Skip to content

Commit

Permalink
ccpa support; formatting
Browse files Browse the repository at this point in the history
sylvialiu404 committed Jun 13, 2023
1 parent 1f69756 commit 1c9c17c
Showing 3 changed files with 33 additions and 21 deletions.
13 changes: 13 additions & 0 deletions ccpa_parsed_consent.go
Original file line number Diff line number Diff line change
@@ -42,3 +42,16 @@ func IsValidCCPAString(ccpaString string) (bool, error) {

return true, nil
}

func ParseCCPA(s string) (*CcpaParsedConsent, error) {
if valid, err := IsValidCCPAString(s); !valid {
return nil, err
}

return &CcpaParsedConsent{
int(s[0] - '0'),
s[1],
s[2],
s[3],
}, nil
}
8 changes: 8 additions & 0 deletions gpp_parsed_consent_test.go
Original file line number Diff line number Diff line change
@@ -61,6 +61,14 @@ func (s *GppParseSuite) TestParseGppHeader(c *check.C) {
Version: 1,
Sections: []int{6, 7}},
},
{
description: "US CA",
header: "DBABBg",
expected: &iabconsent.GppHeader{
Type: 3,
Version: 1,
Sections: []int{8}},
},
}

for _, tc := range tcs {
33 changes: 12 additions & 21 deletions mspa_sections.go
Original file line number Diff line number Diff line change
@@ -48,10 +48,6 @@ type NotSupported struct {
GppSection
}

func (u NotSupported) ParseConsent() (GppParsedConsent, error) {
return nil, errors.New(fmt.Sprintf("Section ID %d is not supported", u.sectionId))
}

func NewTCFEU(section string) *TCFEU {
return &TCFEU{GppSection{sectionId: SectionIDEUTCFv2, sectionValue: section}}
}
@@ -92,25 +88,20 @@ func NewNotSupported(section string, sectionID int) *NotSupported {
return &NotSupported{GppSection{sectionId: sectionID, sectionValue: section}}
}

func (t TCFEU) ParseConsent() (GppParsedConsent, error) {
return ParseV2(t.sectionValue)
func (n *NotSupported) ParseConsent() (GppParsedConsent, error) {
return nil, errors.New(fmt.Sprintf("Section ID %d is not supported", n.sectionId))
}

func (t TCFCA) ParseConsent() (GppParsedConsent, error) {
func (t *TCFEU) ParseConsent() (GppParsedConsent, error) {
return ParseV2(t.sectionValue)
}

func (u USPV) ParseConsent() (GppParsedConsent, error) {
if valid, err := IsValidCCPAString(u.sectionValue); !valid {
return nil, err
}
func (t *TCFCA) ParseConsent() (GppParsedConsent, error) {
return ParseV2(t.sectionValue)
}

return &CcpaParsedConsent{
int(u.sectionValue[0] - '0'),
u.sectionValue[1],
u.sectionValue[2],
u.sectionValue[3],
}, nil
func (u *USPV) ParseConsent() (GppParsedConsent, error) {
return ParseCCPA(u.sectionValue)

}

@@ -205,7 +196,7 @@ func (m *MspaUsVA) ParseConsent() (GppParsedConsent, error) {
return p, r.Err
}

func (m MspaUsCO) ParseConsent() (GppParsedConsent, error) {
func (m *MspaUsCO) ParseConsent() (GppParsedConsent, error) {
var segments = strings.Split(m.sectionValue, ".")

var b, err = base64.RawURLEncoding.DecodeString(segments[0])
@@ -245,7 +236,7 @@ func (m MspaUsCO) ParseConsent() (GppParsedConsent, error) {
return p, r.Err
}

func (m MspaUsUT) ParseConsent() (GppParsedConsent, error) {
func (m *MspaUsUT) ParseConsent() (GppParsedConsent, error) {
var segments = strings.Split(m.sectionValue, ".")

var b, err = base64.RawURLEncoding.DecodeString(segments[0])
@@ -285,7 +276,7 @@ func (m MspaUsUT) ParseConsent() (GppParsedConsent, error) {
return p, r.Err
}

func (m MspaUsCT) ParseConsent() (GppParsedConsent, error) {
func (m *MspaUsCT) ParseConsent() (GppParsedConsent, error) {
var segments = strings.Split(m.sectionValue, ".")

var b, err = base64.RawURLEncoding.DecodeString(segments[0])
@@ -326,7 +317,7 @@ func (m MspaUsCT) ParseConsent() (GppParsedConsent, error) {

}

func (m MspaUsCA) ParseConsent() (GppParsedConsent, error) {
func (m *MspaUsCA) ParseConsent() (GppParsedConsent, error) {
var segments = strings.Split(m.sectionValue, ".")

var b, err = base64.RawURLEncoding.DecodeString(segments[0])

0 comments on commit 1c9c17c

Please sign in to comment.