Skip to content

Commit

Permalink
Adform adapter lacked gross/net parameter support (prebid#2084)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn-lw authored Nov 29, 2021
1 parent 7818efd commit cc4a376
Show file tree
Hide file tree
Showing 10 changed files with 682 additions and 0 deletions.
30 changes: 30 additions & 0 deletions adapters/adf/adf.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ type adapter struct {
endpoint string
}

type adfRequestExt struct {
openrtb_ext.ExtRequest
PriceType string `json:"pt"`
}

// Builder builds a new instance of the Adf adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) {
bidder := &adapter{
Expand All @@ -27,6 +32,7 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters
func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var errors []error
var validImps = make([]openrtb2.Imp, 0, len(request.Imp))
priceType := ""

for _, imp := range request.Imp {
var bidderExt adapters.ExtImpBidder
Expand All @@ -47,6 +53,30 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte

imp.TagID = adfImpExt.MasterTagID.String()
validImps = append(validImps, imp)

// If imps specify priceType they should all be the same. If they differ, only the first one will be used
if adfImpExt.PriceType != "" && priceType == "" {
priceType = adfImpExt.PriceType
}
}

if priceType != "" {
requestExt := adfRequestExt{}
var err error

if len(request.Ext) > 0 {
if err = json.Unmarshal(request.Ext, &requestExt); err != nil {
errors = append(errors, err)
}
}

if err == nil {
requestExt.PriceType = priceType

if request.Ext, err = json.Marshal(&requestExt); err != nil {
errors = append(errors, err)
}
}
}

request.Imp = validImps
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"mockBidRequest": {
"id": "test-request-id",
"ext":{
"prebid":{
"aliases":{
"adfalias": "adf"
}
}
},
"imp": [{
"id": "test-imp-id",
"ext": {
"bidder": {
"mid": "828782",
"priceType": "gross"
}
},
"banner": {
"format": [{
"w": 300,
"h": 250
}]
}
}],
"site": {
"publisher": {
"id": "1"
},
"page": "some-page-url"
},
"device": {
"w": 1920,
"h": 800
}
},
"httpCalls": [{
"expectedRequest": {
"uri": "https://adx.adform.net/adx/openrtb",
"body": {
"id": "test-request-id",
"ext": {
"prebid":{
"aliases":{
"adfalias": "adf"
}
},
"pt": "gross"
},
"imp": [{
"id": "test-imp-id",
"ext": {
"bidder": {
"mid": "828782",
"priceType": "gross"
}
},
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"tagid": "828782"
}],
"site": {
"publisher": {
"id": "1"
},
"page": "some-page-url"
},
"device": {
"w": 1920,
"h": 800
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [{
"bid": [{
"id": "test-bid-id",
"impid": "test-imp-id",
"price": 10,
"adm": "{banner html}",
"adomain": [ "test.com" ],
"crid": "test-creative-id",
"ext": {
"prebid": {
"type": "banner"
}
}
}]
}],
"cur": "USD"
}
}
}],
"expectedBidResponses": [{
"currency": "USD",
"bids": [
{
"bid": {
"id": "test-bid-id",
"impid": "test-imp-id",
"price": 10,
"adm": "{banner html}",
"crid": "test-creative-id",
"adomain": [ "test.com" ],
"ext": {
"prebid": {
"type": "banner"
}
}
},
"type": "banner"
}
]
}]
}
112 changes: 112 additions & 0 deletions adapters/adf/adftest/exemplary/single-banner-pricetype-gross.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [{
"id": "test-imp-id",
"ext": {
"bidder": {
"mid": "828782",
"priceType": "gross"
}
},
"banner": {
"format": [{
"w": 300,
"h": 250
}]
}
}],
"site": {
"publisher": {
"id": "1"
},
"page": "some-page-url"
},
"device": {
"w": 1920,
"h": 800
}
},
"httpCalls": [{
"expectedRequest": {
"uri": "https://adx.adform.net/adx/openrtb",
"body": {
"id": "test-request-id",
"ext": {
"prebid": {
},
"pt": "gross"
},
"imp": [{
"id": "test-imp-id",
"ext": {
"bidder": {
"mid": "828782",
"priceType": "gross"
}
},
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"tagid": "828782"
}],
"site": {
"publisher": {
"id": "1"
},
"page": "some-page-url"
},
"device": {
"w": 1920,
"h": 800
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [{
"bid": [{
"id": "test-bid-id",
"impid": "test-imp-id",
"price": 10,
"adm": "{banner html}",
"adomain": [ "test.com" ],
"crid": "test-creative-id",
"ext": {
"prebid": {
"type": "banner"
}
}
}]
}],
"cur": "USD"
}
}
}],
"expectedBidResponses": [{
"currency": "USD",
"bids": [
{
"bid": {
"id": "test-bid-id",
"impid": "test-imp-id",
"price": 10,
"adm": "{banner html}",
"crid": "test-creative-id",
"adomain": [ "test.com" ],
"ext": {
"prebid": {
"type": "banner"
}
}
},
"type": "banner"
}
]
}]
}
112 changes: 112 additions & 0 deletions adapters/adf/adftest/exemplary/single-banner-pricetype-net.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [{
"id": "test-imp-id",
"ext": {
"bidder": {
"mid": "828782",
"priceType": "net"
}
},
"banner": {
"format": [{
"w": 300,
"h": 250
}]
}
}],
"site": {
"publisher": {
"id": "1"
},
"page": "some-page-url"
},
"device": {
"w": 1920,
"h": 800
}
},
"httpCalls": [{
"expectedRequest": {
"uri": "https://adx.adform.net/adx/openrtb",
"body": {
"id": "test-request-id",
"ext": {
"prebid": {
},
"pt": "net"
},
"imp": [{
"id": "test-imp-id",
"ext": {
"bidder": {
"mid": "828782",
"priceType": "net"
}
},
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"tagid": "828782"
}],
"site": {
"publisher": {
"id": "1"
},
"page": "some-page-url"
},
"device": {
"w": 1920,
"h": 800
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [{
"bid": [{
"id": "test-bid-id",
"impid": "test-imp-id",
"price": 10,
"adm": "{banner html}",
"adomain": [ "test.com" ],
"crid": "test-creative-id",
"ext": {
"prebid": {
"type": "banner"
}
}
}]
}],
"cur": "USD"
}
}
}],
"expectedBidResponses": [{
"currency": "USD",
"bids": [
{
"bid": {
"id": "test-bid-id",
"impid": "test-imp-id",
"price": 10,
"adm": "{banner html}",
"crid": "test-creative-id",
"adomain": [ "test.com" ],
"ext": {
"prebid": {
"type": "banner"
}
}
},
"type": "banner"
}
]
}]
}
Loading

0 comments on commit cc4a376

Please sign in to comment.