Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nextmillennium: add extra_info support #3351

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it desired to send an empty object if the list is empty? If you add an omitempty flag to the json attribute you could skip creating an empty object (unless you need it on your side). ie:

NextMillennium nmExtNMM    `json:"nextMillennium"`

to

NextMillennium nmExtNMM    `json:"nextMillennium,omitempty"`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test case for extra_info,
When I add omitempty it doesn't actually change anything... I always believed omitempty only works on keys (meaning not objects) (or if it's a pointer...),
Either way, it doesn't bother us, so if it's ok with you, I would just leave it...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JacobKlein26

omitempty was added on NmmFlags. But recommendation was to add omitempty on nextMillennium

type nmExtNMM struct {
- 	NmmFlags []string `json:"nmmFlags,omitempty"`
+ 	NmmFlags []string `json:"nmmFlags"`
}
type nextMillJsonExt struct {
	Prebid nmExtPrebid `json:"prebid"`
	Prebid         nmExtPrebid `json:"prebid"`
-	NextMillennium nmExtNMM    `json:"nextMillennium"`
+ 	NextMillennium nmExtNMM    `json:"nextMillennium,omitempty"`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @onkarvhanumante.
Thanks for clarifying.
I pushed another commit to add it. However, as far as I'm aware, adding omitempty on a type of struct makes no difference (the object itself will be empty but the nextMillennium key will still exist as an empty object).
The only way (from a quick google search) to remove it is to convert it to a pointer.
It is not important for us to remove it, but if for whatever reason you think I should do it, let me know and I'll do it.

Thank you!

"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
Loading