Skip to content

Commit

Permalink
add NotSupported type
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvialiu404 committed Jun 12, 2023
1 parent bf2a6be commit 1f69756
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion gpp_parsed_consent.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,19 @@ type GppSection struct {
type GppSectionParser interface {
ParseConsent() (GppParsedConsent, error)
GetSectionId() int
GetSectionValue() string
}

// GetSectionId returns the Section ID for a given GppSection.
func (g *GppSection) GetSectionId() int {
return g.sectionId
}

// GetSectionValue returns the Section Value for a given GppSection.
func (g *GppSection) GetSectionValue() string {
return g.sectionValue
}

type GppSubSection struct {
// Global Privacy Control (GPC) is signaled and set.
Gpc bool
Expand Down Expand Up @@ -135,9 +141,10 @@ func MapGppSectionToParser(s string) ([]GppSectionParser, error) {
gppSection = NewMspaUT(segments[i])
case SectionIDUSCT:
gppSection = NewMspaCT(segments[i])
default:
gppSection = NewNotSupported(segments[i], sid)
}

// when the section id is not supported, append nullptr to indicate that this section is invalid
gppSections = append(gppSections, gppSection)
}
return gppSections, nil
Expand Down
13 changes: 13 additions & 0 deletions mspa_sections.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package iabconsent

import (
"encoding/base64"
"fmt"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -43,6 +44,14 @@ type USPV struct {
GppSection
}

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}}
}
Expand Down Expand Up @@ -79,6 +88,10 @@ func NewMspaCT(section string) *MspaUsCT {
return &MspaUsCT{GppSection{sectionId: SectionIDUSCT, sectionValue: section}}
}

func NewNotSupported(section string, sectionID int) *NotSupported {
return &NotSupported{GppSection{sectionId: sectionID, sectionValue: section}}
}

func (t TCFEU) ParseConsent() (GppParsedConsent, error) {
return ParseV2(t.sectionValue)
}
Expand Down

0 comments on commit 1f69756

Please sign in to comment.