Skip to content

Commit

Permalink
ImproveDigital: Remove placementKey & addtlconsent parsing (#3728)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishihanvcs authored Oct 29, 2024
1 parent 03a4abd commit a23380f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 285 deletions.
83 changes: 3 additions & 80 deletions adapters/improvedigital/improvedigital.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ import (
)

const (
isRewardedInventory = "is_rewarded_inventory"
stateRewardedInventoryEnable = "1"
consentProvidersSettingsInputKey = "ConsentedProvidersSettings"
consentProvidersSettingsOutKey = "consented_providers_settings"
consentedProvidersKey = "consented_providers"
publisherEndpointParam = "{PublisherId}"
isRewardedInventory = "is_rewarded_inventory"
stateRewardedInventoryEnable = "1"
publisherEndpointParam = "{PublisherId}"
)

type ImprovedigitalAdapter struct {
Expand Down Expand Up @@ -75,17 +72,6 @@ func (a *ImprovedigitalAdapter) makeRequest(request openrtb2.BidRequest, imp ope

request.Imp = []openrtb2.Imp{imp}

userExtAddtlConsent, err := a.getAdditionalConsentProvidersUserExt(request)
if err != nil {
return nil, err
}

if len(userExtAddtlConsent) > 0 {
userCopy := *request.User
userCopy.Ext = userExtAddtlConsent
request.User = &userCopy
}

reqJSON, err := json.Marshal(request)
if err != nil {
return nil, err
Expand Down Expand Up @@ -255,69 +241,6 @@ func isMultiFormatImp(imp openrtb2.Imp) bool {
return formatCount > 1
}

// This method responsible to clone request and convert additional consent providers string to array when additional consent provider found
func (a *ImprovedigitalAdapter) getAdditionalConsentProvidersUserExt(request openrtb2.BidRequest) ([]byte, error) {
var cpStr string

// If user/user.ext not defined, no need to parse additional consent
if request.User == nil || request.User.Ext == nil {
return nil, nil
}

// Start validating additional consent
// Check key exist user.ext.ConsentedProvidersSettings
var userExtMap = make(map[string]json.RawMessage)
if err := json.Unmarshal(request.User.Ext, &userExtMap); err != nil {
return nil, err
}

cpsMapValue, cpsJSONFound := userExtMap[consentProvidersSettingsInputKey]
if !cpsJSONFound {
return nil, nil
}

// Check key exist user.ext.ConsentedProvidersSettings.consented_providers
var cpMap = make(map[string]json.RawMessage)
if err := json.Unmarshal(cpsMapValue, &cpMap); err != nil {
return nil, err
}

cpMapValue, cpJSONFound := cpMap[consentedProvidersKey]
if !cpJSONFound {
return nil, nil
}
// End validating additional consent

// Trim enclosing quotes after casting json.RawMessage to string
consentStr := strings.Trim((string)(cpMapValue), "\"")
// Split by ~ and take only the second string (if exists) as the consented providers spec
var consentStrParts = strings.Split(consentStr, "~")
if len(consentStrParts) < 2 {
return nil, nil
}
cpStr = strings.TrimSpace(consentStrParts[1])
if len(cpStr) == 0 {
return nil, nil
}

// Prepare consent providers string
cpStr = fmt.Sprintf("[%s]", strings.Replace(cpStr, ".", ",", -1))
cpMap[consentedProvidersKey] = json.RawMessage(cpStr)

cpJSON, err := json.Marshal(cpMap)
if err != nil {
return nil, err
}
userExtMap[consentProvidersSettingsOutKey] = cpJSON

extJson, err := json.Marshal(userExtMap)
if err != nil {
return nil, err
}

return extJson, nil
}

func getImpExtWithRewardedInventory(imp openrtb2.Imp) ([]byte, error) {
var ext = make(map[string]json.RawMessage)
if err := json.Unmarshal(imp.Ext, &ext); err != nil {
Expand Down

This file was deleted.

This file was deleted.

3 changes: 1 addition & 2 deletions adapters/improvedigital/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func TestInvalidParams(t *testing.T) {
var validParams = []string{
`{"placementId":13245}`,
`{"placementId":13245, "size": {"w":16, "h":9}}`,
`{"publisherId":13245, "placementKey": "slotA"}`,
`{"placementId":13245, "keyValues":{"target1":["foo"],"target2":["bar", "baz"]}}`,
}

Expand All @@ -56,5 +55,5 @@ var invalidParams = []string{
`{"placementId": "1"}`,
`{"size": true}`,
`{"placementId": true, "size":"1234567"}`,
`{"placementId":13245, "publisherId":13245, "placementKey": "slotA"}`,
`{"publisherId":13245, "placementKey": "slotA"}`,
}
21 changes: 8 additions & 13 deletions static/bidder-params/improvedigital.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@
"placementId": {
"type": "integer",
"minimum": 1,
"description": "An ID which identifies this placement of the impression"
"description": "The placement ID from Improve Digital"
},
"publisherId": {
"type": "integer",
"minimum": 1,
"description": "An ID which identifies publisher. Required when using a placementKey"
},
"placementKey": {
"type": "string",
"description": "An uniq name which identifies this placement of the impression. Must be used with publisherId"
"description": "The publisher ID from Improve Digital"
},
"keyValues": {
"type": "object",
Expand All @@ -32,13 +28,12 @@
"type": "integer"
}
},
"required": ["w", "h"],
"required": [
"w",
"h"
],
"description": "Placement size"
}
},
"oneOf": [{
"required": ["placementId"]
}, {
"required": ["publisherId", "placementKey"]
}]
}
"required": ["placementId"]
}

0 comments on commit a23380f

Please sign in to comment.