Skip to content

Commit

Permalink
AppNexus adapter - Accept placementId as int or string (#2617)
Browse files Browse the repository at this point in the history
Authored by @gargcreation1992
  • Loading branch information
gargcreation1992 committed Mar 15, 2023
1 parent 0a9a6f5 commit a1f48b5
Show file tree
Hide file tree
Showing 8 changed files with 372 additions and 19 deletions.
11 changes: 7 additions & 4 deletions adapters/appnexus/appnexus.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,18 @@ func preprocess(imp *openrtb2.Imp, defaultDisplayManagerVer string) (string, boo

// Accept legacy Appnexus parameters if we don't have modern ones
// Don't worry if both is set as validation rules should prevent, and this is temporary anyway.
if appnexusExt.PlacementId == 0 && appnexusExt.LegacyPlacementId != 0 {
appnexusExt.PlacementId = appnexusExt.LegacyPlacementId
if appnexusExt.PlacementId == 0 && appnexusExt.DeprecatedPlacementId != 0 {
appnexusExt.PlacementId = appnexusExt.DeprecatedPlacementId
}
if appnexusExt.InvCode == "" && appnexusExt.LegacyInvCode != "" {
appnexusExt.InvCode = appnexusExt.LegacyInvCode
}
if appnexusExt.TrafficSourceCode == "" && appnexusExt.LegacyTrafficSourceCode != "" {
appnexusExt.TrafficSourceCode = appnexusExt.LegacyTrafficSourceCode
}
if appnexusExt.UsePaymentRule == nil && appnexusExt.DeprecatedUsePaymentRule != nil {
appnexusExt.UsePaymentRule = appnexusExt.DeprecatedUsePaymentRule
}

if appnexusExt.PlacementId == 0 && (appnexusExt.InvCode == "" || appnexusExt.Member == "") {
return "", false, &errortypes.BadInput{
Expand Down Expand Up @@ -248,10 +251,10 @@ func preprocess(imp *openrtb2.Imp, defaultDisplayManagerVer string) (string, boo
}

impExt := appnexusImpExt{Appnexus: appnexusImpExtAppnexus{
PlacementID: appnexusExt.PlacementId,
PlacementID: int(appnexusExt.PlacementId),
TrafficSourceCode: appnexusExt.TrafficSourceCode,
Keywords: makeKeywordStr(appnexusExt.Keywords),
UsePmtRule: appnexusExt.UsePmtRule,
UsePmtRule: appnexusExt.UsePaymentRule,
PrivateSizes: appnexusExt.PrivateSizes,
}}
var err error
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"mockBidRequest": {
"id": "some-req-id",
"imp": [
{
"id": "some-imp-id",
"native": {
"request": "{\"ver\":\"1.1\",\"context\":1,\"contextsubtype\":11,\"plcmttype\":4,\"plcmtcnt\":1,\"assets\":[{\"id\":1,\"required\":1,\"title\":{\"len\":500}},{\"id\":2,\"required\":1,\"img\":{\"type\":3,\"wmin\":1,\"hmin\":1}},{\"id\":3,\"required\":0,\"data\":{\"type\":1,\"len\":200}},{\"id\":4,\"required\":0,\"data\":{\"type\":2,\"len\":15000}},{\"id\":5,\"required\":0,\"data\":{\"type\":6,\"len\":40}},{\"id\":6,\"required\":0,\"data\":{\"type\":500}}]}",
"ver": "1.1"
},
"ext": {
"bidder": {
"placement_id": "9880618"
}
}
}
],
"site": {
"domain": "prebid.org",
"page": "prebid.org"
},
"device": {
"ip": "152.193.6.74"
},
"user": {
"id": "db089de9-a62e-4861-a881-0ff15e052516",
"buyeruid": "8299345306627569435"
},
"tmax": 500
},
"httpcalls": [
{
"expectedRequest": {
"uri": "http://ib.adnxs.com/openrtb2",
"body": {
"id": "some-req-id",
"imp": [
{
"id": "some-imp-id",
"native": {
"request": "{\"ver\":\"1.1\",\"context\":1,\"contextsubtype\":11,\"plcmttype\":4,\"plcmtcnt\":1,\"assets\":[{\"id\":1,\"required\":1,\"title\":{\"len\":500}},{\"id\":2,\"required\":1,\"img\":{\"type\":3,\"wmin\":1,\"hmin\":1}},{\"id\":3,\"required\":0,\"data\":{\"type\":1,\"len\":200}},{\"id\":4,\"required\":0,\"data\":{\"type\":2,\"len\":15000}},{\"id\":5,\"required\":0,\"data\":{\"type\":6,\"len\":40}},{\"id\":6,\"required\":0,\"data\":{\"type\":500}}]}",
"ver": "1.1"
},
"ext": {
"appnexus": {
"placement_id": 9880618
}
}
}
],
"ext": {
"appnexus": {
"hb_source": 5
},
"prebid": {}
},
"site": {
"domain": "prebid.org",
"page": "prebid.org"
},
"device": {
"ip": "152.193.6.74"
},
"user": {
"id": "db089de9-a62e-4861-a881-0ff15e052516",
"buyeruid": "8299345306627569435"
},
"tmax": 500
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "some-req-id",
"seatbid": [
{
"bid": [
{
"id": "928185755156387460",
"impid": "some-imp-id",
"price": 1.000000,
"adid": "69595837",
"adm": "{}",
"adomain": [
"appnexus.com"
],
"iurl": "http://nym1-ib.adnxs.com/cr?id=69595837",
"cid": "958",
"crid": "69595837",
"cat": [
"IAB3-1"
],
"ext": {
"appnexus": {
"brand_id": 350,
"brand_category_id": 350,
"auction_id": 5607483846416358664,
"bidder_id": 2,
"bid_ad_type": 3,
"deal_priority": 5
}
}
}
],
"seat": "958"
}
],
"bidid": "8141327771600527856",
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "928185755156387460",
"impid": "some-imp-id",
"price": 1,
"adm": "{}",
"adid": "69595837",
"adomain": [
"appnexus.com"
],
"iurl": "http://nym1-ib.adnxs.com/cr?id=69595837",
"cid": "958",
"crid": "69595837",
"cat": [
"IAB3-1"
],
"ext": {
"appnexus": {
"brand_id": 350,
"brand_category_id": 350,
"auction_id": 5607483846416358664,
"bidder_id": 2,
"bid_ad_type": 3,
"deal_priority": 5
}
}
},
"type": "native"
}
]
}
]
}

117 changes: 117 additions & 0 deletions adapters/appnexus/appnexustest/supplemental/usePmtRule-test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"member": "103",
"inv_code": "abc",
"reserve": 20,
"position": "below",
"use_payment_rule": true
}
}
},
{
"id": "test-imp-id-2",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"member": "103",
"inv_code": "abc",
"reserve": 20,
"position": "below",
"use_pmt_rule": true,
"use_payment_rule": false
}
}
}
]
},

"httpCalls": [
{
"expectedRequest": {
"uri": "http://ib.adnxs.com/openrtb2?member_id=103",
"body": {
"id": "test-request-id",
"ext": {
"appnexus": {
"hb_source": 5
},
"prebid": {}
},
"imp": [
{
"id":"test-imp-id",
"banner": {
"format": [
{"w":300,"h":250},
{"w":300,"h":600}
],
"w": 300,
"h": 250,
"pos": 3
},
"tagid": "abc",
"bidfloor": 20,
"ext": {
"appnexus": {
"use_pmt_rule": true
}
}
},
{
"id":"test-imp-id-2",
"banner": {
"format": [
{"w":300,"h":250},
{"w":300,"h":600}
],
"w": 300,
"h": 250,
"pos": 3
},
"tagid": "abc",
"bidfloor": 20,
"ext": {
"appnexus": {
"use_pmt_rule": true
}
}
}
]
}
},
"mockResponse": {
"status": 204
}
}
],
"expectedBidResponses": []
}
4 changes: 3 additions & 1 deletion adapters/appnexus/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func TestInvalidParams(t *testing.T) {

var validParams = []string{
`{"placement_id":123}`,
`{"placement_id":"123"}`,
`{"placementId":123}`,
`{"placementId":"123"}`,
`{"placementId":123,"position":"above"}`,
`{"placement_id":123,"position":"below"}`,
`{"member":"123","inv_code":"456"}`,
Expand All @@ -58,7 +61,6 @@ var invalidParams = []string{
`4.2`,
`[]`,
`{}`,
`{"placement_id":"123"}`,
`{"placement_id":123, "placementId":123}`,
`{"member":"123"}`,
`{"member":"123","invCode":45}`,
Expand Down
29 changes: 17 additions & 12 deletions openrtb_ext/imp_appnexus.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package openrtb_ext

import "encoding/json"
import (
"encoding/json"

"github.com/prebid/prebid-server/util/jsonutil"
)

// ExtImpAppnexus defines the contract for bidrequest.imp[i].ext.prebid.bidder.appnexus
type ExtImpAppnexus struct {
LegacyPlacementId int `json:"placementId"`
LegacyInvCode string `json:"invCode"`
LegacyTrafficSourceCode string `json:"trafficSourceCode"`
PlacementId int `json:"placement_id"`
InvCode string `json:"inv_code"`
Member string `json:"member"`
Keywords []*ExtImpAppnexusKeyVal `json:"keywords"`
TrafficSourceCode string `json:"traffic_source_code"`
Reserve float64 `json:"reserve"`
Position string `json:"position"`
UsePmtRule *bool `json:"use_pmt_rule"`
DeprecatedPlacementId jsonutil.StringInt `json:"placementId"`
LegacyInvCode string `json:"invCode"`
LegacyTrafficSourceCode string `json:"trafficSourceCode"`
PlacementId jsonutil.StringInt `json:"placement_id"`
InvCode string `json:"inv_code"`
Member string `json:"member"`
Keywords []*ExtImpAppnexusKeyVal `json:"keywords"`
TrafficSourceCode string `json:"traffic_source_code"`
Reserve float64 `json:"reserve"`
Position string `json:"position"`
UsePaymentRule *bool `json:"use_pmt_rule"`
DeprecatedUsePaymentRule *bool `json:"use_payment_rule"`
// At this time we do no processing on the private sizes, so just leaving it as a JSON blob.
PrivateSizes json.RawMessage `json:"private_sizes"`
AdPodId bool `json:"generate_ad_pod_id"`
Expand Down
8 changes: 6 additions & 2 deletions static/bidder-params/appnexus.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"type": "object",
"properties": {
"placement_id": {
"type": "integer",
"type": ["integer", "string"],
"description": "An ID which identifies this placement of the impression"
},
"placementId": {
"type": "integer",
"type": ["integer", "string"],
"description": "Deprecated, use placement_id instead."
},
"inv_code": {
Expand Down Expand Up @@ -67,6 +67,10 @@
"type": "boolean",
"description": "Boolean to signal AppNexus to apply the relevant payment rule"
},
"use_payment_rule": {
"type": "boolean",
"description": "Deprecated, Boolean to signal AppNexus to apply the relevant payment rule. use_pmt_rule will get precedence over usePaymentRule."
},
"generate_ad_pod_id": {
"type": "boolean",
"description": "Boolean to signal AppNexus to add ad pod id to each request"
Expand Down
Loading

0 comments on commit a1f48b5

Please sign in to comment.