Skip to content

Commit

Permalink
Nextmillennium: add extra_info support (#3351)
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobKlein26 authored Dec 21, 2023
1 parent 0c444d0 commit c773b0f
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 3 deletions.
20 changes: 17 additions & 3 deletions adapters/nextmillennium/nextmillennium.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

type adapter struct {
endpoint string
nmmFlags []string
}

type nmExtPrebidStoredRequest struct {
Expand All @@ -22,8 +23,12 @@ type nmExtPrebidStoredRequest struct {
type nmExtPrebid struct {
StoredRequest nmExtPrebidStoredRequest `json:"storedrequest"`
}
type nmExtNMM struct {
NmmFlags []string `json:"nmmFlags,omitempty"`
}
type nextMillJsonExt struct {
Prebid nmExtPrebid `json:"prebid"`
Prebid nmExtPrebid `json:"prebid"`
NextMillennium nmExtNMM `json:"nextMillennium,omitempty"`
}

// MakeRequests prepares request information for prebid-server core
Expand Down Expand Up @@ -77,7 +82,7 @@ func getImpressionExt(imp *openrtb2.Imp) (*openrtb_ext.ImpExtNextMillennium, err
}

func (adapter *adapter) buildAdapterRequest(prebidBidRequest *openrtb2.BidRequest, params *openrtb_ext.ImpExtNextMillennium) (*adapters.RequestData, error) {
newBidRequest := createBidRequest(prebidBidRequest, params)
newBidRequest := createBidRequest(prebidBidRequest, params, adapter.nmmFlags)

reqJSON, err := json.Marshal(newBidRequest)
if err != nil {
Expand All @@ -96,7 +101,7 @@ func (adapter *adapter) buildAdapterRequest(prebidBidRequest *openrtb2.BidReques
Headers: headers}, nil
}

func createBidRequest(prebidBidRequest *openrtb2.BidRequest, params *openrtb_ext.ImpExtNextMillennium) *openrtb2.BidRequest {
func createBidRequest(prebidBidRequest *openrtb2.BidRequest, params *openrtb_ext.ImpExtNextMillennium, flags []string) *openrtb2.BidRequest {
placementID := params.PlacementID

if params.GroupID != "" {
Expand All @@ -122,6 +127,7 @@ func createBidRequest(prebidBidRequest *openrtb2.BidRequest, params *openrtb_ext
}
ext := nextMillJsonExt{}
ext.Prebid.StoredRequest.ID = placementID
ext.NextMillennium.NmmFlags = flags
jsonExt, err := json.Marshal(ext)
if err != nil {
return prebidBidRequest
Expand Down Expand Up @@ -169,7 +175,15 @@ func (adapter *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalR

// Builder builds a new instance of the NextMillennium adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
var info nmExtNMM
if config.ExtraAdapterInfo != "" {
if err := json.Unmarshal([]byte(config.ExtraAdapterInfo), &info); err != nil {
return nil, fmt.Errorf("invalid extra info: %v", err)
}
}

return &adapter{
endpoint: config.Endpoint,
nmmFlags: info.NmmFlags,
}, nil
}
13 changes: 13 additions & 0 deletions adapters/nextmillennium/nextmillennium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/prebid/prebid-server/v2/adapters/adapterstest"
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/stretchr/testify/assert"
)

func TestJsonSamples(t *testing.T) {
Expand All @@ -18,3 +19,15 @@ func TestJsonSamples(t *testing.T) {

adapterstest.RunJSONBidderTest(t, "nextmillenniumtest", bidder)
}
func TestWithExtraInfo(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderNextMillennium, config.Adapter{
Endpoint: "https://pbs.nextmillmedia.com/openrtb2/auction",
ExtraAdapterInfo: "{\"nmmFlags\":[\"flag1\",\"flag2\"]}",
}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})

if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
}
bidderNextMillennium, _ := bidder.(*adapter)
assert.Equal(t, bidderNextMillennium.nmmFlags, []string{"flag1", "flag2"})
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"body":{
"id": "testid",
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "7819"
Expand All @@ -54,6 +55,7 @@
]
},
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "7819"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"body":{
"id": "testid",
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "g7819;320x250;www.example.com"
Expand All @@ -67,6 +68,7 @@
"w": 320
},
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "g7819;320x250;www.example.com"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"domain": "www.example.com"
},
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "g7819;320x250;www.example.com"
Expand All @@ -63,6 +64,7 @@
"w": 320
},
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "g7819;320x250;www.example.com"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"domain": "www.example.com"
},
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "g7819;;www.example.com"
Expand All @@ -41,6 +42,7 @@
"w": 320
},
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "g7819;;www.example.com"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"domain": "www.example.com"
},
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "g7819;320x250;www.example.com"
Expand All @@ -43,6 +44,7 @@
"w": 320
},
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "g7819;320x250;www.example.com"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"body":{
"id": "testid",
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "g7819;320x250;"
Expand All @@ -57,6 +58,7 @@
"w": 320
},
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "g7819;320x250;"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"body":{
"id": "testid",
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "g7819;320x250;"
Expand All @@ -53,6 +54,7 @@
]
},
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "g7819;320x250;"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"body":{
"id": "testid",
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "7819"
Expand All @@ -57,6 +58,7 @@
"w": 320
},
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "7819"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"body":{
"id": "testid",
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "g7819;;"
Expand All @@ -31,6 +32,7 @@
{
"banner": {},
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "g7819;;"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"body": {
"id": "testid",
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "7819"
Expand All @@ -56,6 +57,7 @@
"w": 320
},
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "7819"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"body": {
"id": "testid",
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "7819"
Expand All @@ -48,6 +49,7 @@
"w": 320
},
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "7819"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"body": {
"id": "testid",
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "7819"
Expand All @@ -48,6 +49,7 @@
"w": 320
},
"ext": {
"nextMillennium": {},
"prebid": {
"storedrequest": {
"id": "7819"
Expand Down

0 comments on commit c773b0f

Please sign in to comment.