Skip to content

Commit

Permalink
Beachfront: Add schain support (prebid#1844)
Browse files Browse the repository at this point in the history
Co-authored-by: jim naumann <jim@beachfront.com>
  • Loading branch information
2 people authored and sachin-pubmatic committed Aug 2, 2021
1 parent fcff331 commit b4616ee
Show file tree
Hide file tree
Showing 15 changed files with 387 additions and 30 deletions.
53 changes: 33 additions & 20 deletions adapters/beachfront/beachfront.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,24 @@ type beachfrontVideoRequest struct {
// Banner
// ---------------------------------------------------
type beachfrontBannerRequest struct {
Slots []beachfrontSlot `json:"slots"`
Domain string `json:"domain"`
Page string `json:"page"`
Referrer string `json:"referrer"`
Search string `json:"search"`
Secure int8 `json:"secure"`
DeviceOs string `json:"deviceOs"`
DeviceModel string `json:"deviceModel"`
IsMobile int8 `json:"isMobile"`
UA string `json:"ua"`
Dnt int8 `json:"dnt"`
User openrtb2.User `json:"user"`
AdapterName string `json:"adapterName"`
AdapterVersion string `json:"adapterVersion"`
IP string `json:"ip"`
RequestID string `json:"requestId"`
Real204 bool `json:"real204"`
Slots []beachfrontSlot `json:"slots"`
Domain string `json:"domain"`
Page string `json:"page"`
Referrer string `json:"referrer"`
Search string `json:"search"`
Secure int8 `json:"secure"`
DeviceOs string `json:"deviceOs"`
DeviceModel string `json:"deviceModel"`
IsMobile int8 `json:"isMobile"`
UA string `json:"ua"`
Dnt int8 `json:"dnt"`
User openrtb2.User `json:"user"`
AdapterName string `json:"adapterName"`
AdapterVersion string `json:"adapterVersion"`
IP string `json:"ip"`
RequestID string `json:"requestId"`
Real204 bool `json:"real204"`
SChain openrtb_ext.ExtRequestPrebidSChainSChain `json:"schain,omitempty"`
}

type beachfrontSlot struct {
Expand Down Expand Up @@ -263,6 +264,11 @@ func getAppId(ext openrtb_ext.ExtImpBeachfront, media openrtb_ext.BidType) (stri
return appid, error
}

func getSchain(request *openrtb2.BidRequest) (openrtb_ext.ExtRequestPrebidSChain, error) {
var schain openrtb_ext.ExtRequestPrebidSChain
return schain, json.Unmarshal(request.Source.Ext, &schain)
}

/*
getBannerRequest, singular. A "Slot" is an "imp," and each Slot can have an AppId, so just one
request to the beachfront banner endpoint gets all banner Imps.
Expand Down Expand Up @@ -370,6 +376,13 @@ func getBannerRequest(request *openrtb2.BidRequest) (beachfrontBannerRequest, []
}
bfr.Real204 = true

if request.Source != nil && request.Source.Ext != nil {
schain, err := getSchain(request)
if err == nil {
bfr.SChain = schain.SChain
}
}

return bfr, errs
}

Expand Down Expand Up @@ -517,10 +530,10 @@ func (a *BeachfrontAdapter) MakeBids(internalRequest *openrtb2.BidRequest, exter
// only get the User struct and everything else will be nil
if err := json.Unmarshal(externalRequest.Body, &xtrnal); err != nil {
errs = append(errs, err)
} else {
bids, errs = postprocess(response, xtrnal, externalRequest.Uri, internalRequest.ID)
}

bids, errs = postprocess(response, xtrnal, externalRequest.Uri, internalRequest.ID)

if len(errs) != 0 {
return nil, errs
}
Expand Down Expand Up @@ -569,7 +582,7 @@ func postprocess(response *adapters.ResponseData, xtrnal openrtb2.BidRequest, ur

if err := json.Unmarshal(response.Body, &beachfrontResp); err != nil {
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprint("server response failed to unmarshal as valid rtb. Run with request.debug = 1 for more info"),
Message: "server response failed to unmarshal as valid rtb. Run with request.debug = 1 for more info",
}}
} else {
return postprocessBanner(beachfrontResp, id)
Expand Down
7 changes: 6 additions & 1 deletion adapters/beachfront/beachfronttest/exemplary/banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@
"ua": "",
"adapterName": "BF_PREBID_S2S",
"adapterVersion": "0.9.2",
"user": {}
"user": {},
"schain": {
"complete": 0,
"nodes": null,
"ver": ""
}
}
},
"mockResponse": {
Expand Down
158 changes: 158 additions & 0 deletions adapters/beachfront/beachfronttest/supplemental/adm-video-schain.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"mockBidRequest": {
"id": "adm-video",
"imp": [
{
"id": "video1",
"ext": {
"bidder": {
"bidfloor": 3.01,
"appId": "videoAppId1"
}
},
"video": {
"mimes": [
"video/mp4"
],
"context": "instream",
"w": 300,
"h": 250
}
}
],
"site": {
"page": "https://some.domain.us/some/page.html"
},
"device":{
"ip":"192.168.168.168"
},
"source": {
"fd": 1,
"ext": {
"schain": {
"complete": 1,
"ver": "1.0",
"nodes": [
{
"asi": "somenode.com",
"sid": "some-sid",
"rid": "some-rid",
"hp": 1
}
]
}
}
}
},

"httpCalls": [
{
"expectedRequest": {
"uri": "https://qa.beachrtb.com/bid.json?exchange_id=videoAppId1",
"body": {
"id": "adm-video",
"imp": [
{
"video": {
"w": 300,
"h": 250,
"mimes": [
"video/mp4"
]
},
"bidfloor": 3.01,
"id": "video1",
"secure": 1
}
],
"site": {
"page": "https://some.domain.us/some/page.html",
"domain": "some.domain.us"
},
"cur": [
"USD"
],
"device":{
"devicetype": 2,
"ip":"192.168.168.168"
},
"source": {
"fd": 1,
"ext": {
"schain": {
"complete": 1,
"ver": "1.0",
"nodes": [
{
"asi": "somenode.com",
"sid": "some-sid",
"rid": "some-rid",
"hp": 1
}
]
}
}
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "adm-video",
"seatBid": [
{
"bid": [
{
"id": "5fd7c8a6ff2f1f0d42ee6427",
"impid": "video1",
"price": 20,
"adm": "<VAST version=\"2.0\"><Ad><Wrapper>http://example.com/vast.xml</Wrapper></Ad></VAST>",
"adid": "1088",
"adomain": [
"beachfront.io"
],
"cid": "277",
"crid": "532",
"w": 300,
"h": 250,
"ext": {
"duration": 30
}
}
],
"seat": "bfio-s-1"
}
]
}
}
}
],

"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "video1AdmVideo",
"impid": "video1",
"price": 20,
"adm": "<VAST version=\"2.0\"><Ad><Wrapper>http://example.com/vast.xml</Wrapper></Ad></VAST>",
"adid": "1088",
"adomain": [
"beachfront.io"
],
"cid": "277",
"crid": "532",
"w": 300,
"h": 250,
"ext": {
"duration": 30
}
},
"type": "video"
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
"adapterName": "BF_PREBID_S2S",
"adapterVersion": "0.9.2",
"user": {
},
"schain": {
"complete": 0,
"nodes": null,
"ver": ""
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
"adapterName": "BF_PREBID_S2S",
"adapterVersion": "0.9.2",
"user": {
},
"schain": {
"complete": 0,
"nodes": null,
"ver": ""
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@
"user": {},
"adapterName": "BF_PREBID_S2S",
"adapterVersion": "0.9.2",
"requestId": "banner-and-video"
"requestId": "banner-and-video",
"schain": {
"complete": 0,
"nodes": null,
"ver": ""
}
}
},
"mockResponse": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@
"user": {},
"adapterName": "BF_PREBID_S2S",
"adapterVersion": "0.9.2",
"requestId": "banner-and-video"
"requestId": "banner-and-video",
"schain": {
"complete": 0,
"nodes": null,
"ver": ""
}
}
},
"mockResponse": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@
"user": {},
"adapterName": "BF_PREBID_S2S",
"adapterVersion": "0.9.2",
"requestId": "banner-and-video"
"requestId": "banner-and-video",
"schain": {
"complete": 0,
"nodes": null,
"ver": ""
}
}
},
"mockResponse": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@
"user": {},
"adapterName": "BF_PREBID_S2S",
"adapterVersion": "0.9.2",
"requestId": "banner-and-video"
"requestId": "banner-and-video",
"schain": {
"complete": 0,
"nodes": null,
"ver": ""
}
}
},
"mockResponse": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@
"ua": "",
"adapterName": "BF_PREBID_S2S",
"adapterVersion": "0.9.2",
"user": {}
"user": {},
"schain": {
"complete": 0,
"nodes": null,
"ver": ""
}
}
},
"mockResponse": {
Expand Down
Loading

0 comments on commit b4616ee

Please sign in to comment.