From c773b0f1a0c282d12ba46a0b6be2a98be107cd3e Mon Sep 17 00:00:00 2001 From: JacobKlein26 <42449375+JacobKlein26@users.noreply.github.com> Date: Thu, 21 Dec 2023 08:58:24 -0500 Subject: [PATCH] Nextmillennium: add extra_info support (#3351) --- adapters/nextmillennium/nextmillennium.go | 20 ++++++++++++++++--- .../nextmillennium/nextmillennium_test.go | 13 ++++++++++++ .../exemplary/banner-empty-group-id.json | 2 ++ .../exemplary/banner-with-group-id.json | 2 ++ .../exemplary/banner-with-group-id_app.json | 2 ++ .../exemplary/banner-with-only-width.json | 2 ++ .../exemplary/banner-with-wh.json | 2 ++ .../exemplary/banner-wo-domain.json | 2 ++ .../exemplary/banner-wo-size.json | 2 ++ .../nextmillenniumtest/exemplary/banner.json | 2 ++ .../exemplary/empty-banner-obj.json | 2 ++ .../supplemental/empty-seatbid.json | 2 ++ .../supplemental/error-response.json | 2 ++ .../supplemental/no-content.json | 2 ++ 14 files changed, 54 insertions(+), 3 deletions(-) diff --git a/adapters/nextmillennium/nextmillennium.go b/adapters/nextmillennium/nextmillennium.go index 5d10cac2d9e..966f96de47a 100644 --- a/adapters/nextmillennium/nextmillennium.go +++ b/adapters/nextmillennium/nextmillennium.go @@ -14,6 +14,7 @@ import ( type adapter struct { endpoint string + nmmFlags []string } type nmExtPrebidStoredRequest struct { @@ -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 @@ -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 { @@ -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 != "" { @@ -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 @@ -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 } diff --git a/adapters/nextmillennium/nextmillennium_test.go b/adapters/nextmillennium/nextmillennium_test.go index ec813ba2412..6e51edc5e17 100644 --- a/adapters/nextmillennium/nextmillennium_test.go +++ b/adapters/nextmillennium/nextmillennium_test.go @@ -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) { @@ -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"}) +} diff --git a/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-empty-group-id.json b/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-empty-group-id.json index 7a628d0fd91..19212134463 100644 --- a/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-empty-group-id.json +++ b/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-empty-group-id.json @@ -33,6 +33,7 @@ "body":{ "id": "testid", "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "7819" @@ -54,6 +55,7 @@ ] }, "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "7819" diff --git a/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-with-group-id.json b/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-with-group-id.json index 3538113014d..129c025e1da 100644 --- a/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-with-group-id.json +++ b/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-with-group-id.json @@ -44,6 +44,7 @@ "body":{ "id": "testid", "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "g7819;320x250;www.example.com" @@ -67,6 +68,7 @@ "w": 320 }, "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "g7819;320x250;www.example.com" diff --git a/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-with-group-id_app.json b/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-with-group-id_app.json index 25c1f36deff..2ddf9bee948 100644 --- a/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-with-group-id_app.json +++ b/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-with-group-id_app.json @@ -40,6 +40,7 @@ "domain": "www.example.com" }, "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "g7819;320x250;www.example.com" @@ -63,6 +64,7 @@ "w": 320 }, "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "g7819;320x250;www.example.com" diff --git a/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-with-only-width.json b/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-with-only-width.json index 79c9894f424..4db65ec46cd 100644 --- a/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-with-only-width.json +++ b/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-with-only-width.json @@ -29,6 +29,7 @@ "domain": "www.example.com" }, "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "g7819;;www.example.com" @@ -41,6 +42,7 @@ "w": 320 }, "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "g7819;;www.example.com" diff --git a/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-with-wh.json b/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-with-wh.json index 6af7816eb21..f7da0784728 100644 --- a/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-with-wh.json +++ b/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-with-wh.json @@ -30,6 +30,7 @@ "domain": "www.example.com" }, "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "g7819;320x250;www.example.com" @@ -43,6 +44,7 @@ "w": 320 }, "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "g7819;320x250;www.example.com" diff --git a/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-wo-domain.json b/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-wo-domain.json index 181dab3548b..d27dffafaf1 100644 --- a/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-wo-domain.json +++ b/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-wo-domain.json @@ -34,6 +34,7 @@ "body":{ "id": "testid", "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "g7819;320x250;" @@ -57,6 +58,7 @@ "w": 320 }, "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "g7819;320x250;" diff --git a/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-wo-size.json b/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-wo-size.json index f2422033b81..c5b9276700d 100644 --- a/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-wo-size.json +++ b/adapters/nextmillennium/nextmillenniumtest/exemplary/banner-wo-size.json @@ -32,6 +32,7 @@ "body":{ "id": "testid", "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "g7819;320x250;" @@ -53,6 +54,7 @@ ] }, "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "g7819;320x250;" diff --git a/adapters/nextmillennium/nextmillenniumtest/exemplary/banner.json b/adapters/nextmillennium/nextmillenniumtest/exemplary/banner.json index fa8834fa998..df736d79757 100644 --- a/adapters/nextmillennium/nextmillenniumtest/exemplary/banner.json +++ b/adapters/nextmillennium/nextmillenniumtest/exemplary/banner.json @@ -34,6 +34,7 @@ "body":{ "id": "testid", "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "7819" @@ -57,6 +58,7 @@ "w": 320 }, "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "7819" diff --git a/adapters/nextmillennium/nextmillenniumtest/exemplary/empty-banner-obj.json b/adapters/nextmillennium/nextmillenniumtest/exemplary/empty-banner-obj.json index cc9f9eb980b..2d357ffb99c 100644 --- a/adapters/nextmillennium/nextmillenniumtest/exemplary/empty-banner-obj.json +++ b/adapters/nextmillennium/nextmillenniumtest/exemplary/empty-banner-obj.json @@ -21,6 +21,7 @@ "body":{ "id": "testid", "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "g7819;;" @@ -31,6 +32,7 @@ { "banner": {}, "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "g7819;;" diff --git a/adapters/nextmillennium/nextmillenniumtest/supplemental/empty-seatbid.json b/adapters/nextmillennium/nextmillenniumtest/supplemental/empty-seatbid.json index dd070d62427..8f3588de144 100644 --- a/adapters/nextmillennium/nextmillenniumtest/supplemental/empty-seatbid.json +++ b/adapters/nextmillennium/nextmillenniumtest/supplemental/empty-seatbid.json @@ -33,6 +33,7 @@ "body": { "id": "testid", "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "7819" @@ -56,6 +57,7 @@ "w": 320 }, "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "7819" diff --git a/adapters/nextmillennium/nextmillenniumtest/supplemental/error-response.json b/adapters/nextmillennium/nextmillenniumtest/supplemental/error-response.json index 3e8047fae54..f7b23ac9bcf 100644 --- a/adapters/nextmillennium/nextmillenniumtest/supplemental/error-response.json +++ b/adapters/nextmillennium/nextmillenniumtest/supplemental/error-response.json @@ -29,6 +29,7 @@ "body": { "id": "testid", "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "7819" @@ -48,6 +49,7 @@ "w": 320 }, "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "7819" diff --git a/adapters/nextmillennium/nextmillenniumtest/supplemental/no-content.json b/adapters/nextmillennium/nextmillenniumtest/supplemental/no-content.json index c4710a376d0..699be4e9aad 100644 --- a/adapters/nextmillennium/nextmillenniumtest/supplemental/no-content.json +++ b/adapters/nextmillennium/nextmillenniumtest/supplemental/no-content.json @@ -29,6 +29,7 @@ "body": { "id": "testid", "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "7819" @@ -48,6 +49,7 @@ "w": 320 }, "ext": { + "nextMillennium": {}, "prebid": { "storedrequest": { "id": "7819"