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

33Across: Add video support in adapter #1557

Merged
merged 6 commits into from
Nov 11, 2020
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
77 changes: 76 additions & 1 deletion adapters/33across/33across.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ type ext struct {
Zoneid string `json:"zoneid,omitempty"`
}

type bidExt struct {
Ttx bidTtxExt `json:"ttx,omitempty"`
}

type bidTtxExt struct {
SyntaxNode marked this conversation as resolved.
Show resolved Hide resolved
MediaType string `json:mediaType,omitempty`
}

// MakeRequests create the object for TTX Reqeust.
func (a *TtxAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var errs []error
Expand All @@ -49,6 +57,14 @@ func (a *TtxAdapter) makeRequest(request *openrtb.BidRequest) (*adapters.Request
errs = append(errs, err)
}

if reqCopy.Imp[0].Banner == nil && reqCopy.Imp[0].Video == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

reqCopy.Imp[0]

It's unexpected for an adapter to only forward the first impression and throw out the rest. I recognize this is existing behavior which predates me by quite a bit. I don't wish for this to hold up this PR.

At the very least, please document this behavior here: https://github.com/prebid/prebid.github.io/blob/master/dev-docs/bidders/33across.md

As a future improvement, you may wish to consider sending multiple requests to your bidding server for each impression provided by the publisher.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion, will incorporate this in follow up PR. I will also file a Docs PR shortly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SyntaxNode a follow up question about your suggestion to send multiple requests-- how would Prebid Server handle responses? Wait for all responses for each request to return or send them upstream as they come one-by-one?

errs = append(errs, &errortypes.BadInput{
Message: "At least one of [banner, video] formats must be defined in Imp. None found",
})

return nil, errs
}

// Last Step
reqJSON, err := json.Marshal(reqCopy)
if err != nil {
Expand Down Expand Up @@ -104,6 +120,19 @@ func preprocess(request *openrtb.BidRequest) error {
siteCopy.ID = ttxExt.SiteId
request.Site = &siteCopy

// Validate Video if it exists
if imp.Video != nil {
videoCopy, err := validateVideoParams(imp.Video, impExt.Ttx.Prod)

imp.Video = videoCopy

if err != nil {
SyntaxNode marked this conversation as resolved.
Show resolved Hide resolved
return &errortypes.BadInput{
Message: err.Error(),
}
}
}

return nil
}

Expand Down Expand Up @@ -135,16 +164,62 @@ func (a *TtxAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalReque

for _, sb := range bidResp.SeatBid {
for i := range sb.Bid {
var bidExt bidExt
var bidType openrtb_ext.BidType

if err := json.Unmarshal(sb.Bid[i].Ext, &bidExt); err != nil {
bidType = openrtb_ext.BidTypeBanner
} else {
bidType = getBidType(bidExt)
}

bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &sb.Bid[i],
BidType: "banner",
BidType: bidType,
})
}
}
return bidResponse, nil

}

func validateVideoParams(video *openrtb.Video, prod string) (*openrtb.Video, error) {
videoCopy := video
if videoCopy.W == 0 ||
videoCopy.H == 0 ||
videoCopy.Protocols == nil ||
videoCopy.MIMEs == nil ||
videoCopy.PlaybackMethod == nil {

return nil, &errortypes.BadInput{
SyntaxNode marked this conversation as resolved.
Show resolved Hide resolved
Message: "One or more invalid or missing video field(s) w, h, protocols, mimes, playbackmethod",
}
}

if videoCopy.Placement == 0 {
videoCopy.Placement = 2
}

if prod == "instream" {
videoCopy.Placement = 1

if videoCopy.StartDelay == nil {
videoCopy.StartDelay = openrtb.StartDelay.Ptr(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add test coverage for this default to 0 branch.

}
}

return videoCopy, nil
}

func getBidType(ext bidExt) openrtb_ext.BidType {
if ext.Ttx.MediaType == "video" {
return openrtb_ext.BidTypeVideo
}

return openrtb_ext.BidTypeBanner
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add test coverage for this assume banner if not a video mediatype branch.

}

// New33AcrossBidder configures bidder endpoint
func New33AcrossBidder(endpoint string) *TtxAdapter {
return &TtxAdapter{
endpoint: endpoint,
Expand Down
2 changes: 1 addition & 1 deletion adapters/33across/33across_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (
)

func TestJsonSamples(t *testing.T) {
adapterstest.RunJSONBidderTest(t, "33across", New33AcrossBidder("http://ssc.33across.com"))
adapterstest.RunJSONBidderTest(t, "33acrosstest", New33AcrossBidder("http://ssc.33across.com"))
}
100 changes: 100 additions & 0 deletions adapters/33across/33acrosstest/exemplary/bidresponse-defaults.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"video": {
"w": 728,
"h": 90,
"protocols": [2],
"placement": 1,
"startdelay": -2,
"playbackmethod": [2],
"mimes": ["foo", "bar"]
},
"ext": {
"bidder": {
"siteId": "fake-site-id",
"productId": "instream"
}
}
}
],
"site": {}
},

"httpCalls": [
{
"expectedRequest": {
"uri": "http://ssc.33across.com",
"body": {
"id": "test-request-id",
"imp": [
{
"id":"test-imp-id",
"video": {
"w": 728,
"h": 90,
"protocols": [2],
"placement": 1,
"startdelay": -2,
"playbackmethod": [2],
"mimes": ["foo", "bar"]
},
"ext": {
"ttx": {
"prod": "instream"
}
}
}
],
"site": {
"id": "fake-site-id"
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "ttx",
"bid": [{
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 0.500000,
"adm": "some-test-vast-ad",
"crid": "crid_10",
"h": 90,
"w": 728
}]
}
],
"cur": "USD"
}
}
}
],

"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 0.5,
"adm": "some-test-vast-ad",
"crid": "crid_10",
"w": 728,
"h": 90
},
"type": "banner"
}
]
}
]
}
108 changes: 108 additions & 0 deletions adapters/33across/33acrosstest/exemplary/instream-video-defaults.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"video": {
"w": 728,
"h": 90,
"protocols": [2],
"playbackmethod": [2],
"mimes": ["foo", "bar"]
},
"ext": {
"bidder": {
"siteId": "fake-site-id",
"productId": "instream"
}
}
}
],
"site": {}
},

"httpCalls": [
{
"expectedRequest": {
"uri": "http://ssc.33across.com",
"body": {
"id": "test-request-id",
"imp": [
{
"id":"test-imp-id",
"video": {
"w": 728,
"h": 90,
"protocols": [2],
"placement": 1,
"startdelay": 0,
"playbackmethod": [2],
"mimes": ["foo", "bar"]
},
"ext": {
"ttx": {
"prod": "instream"
}
}
}
],
"site": {
"id": "fake-site-id"
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "ttx",
"bid": [{
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 0.500000,
"adm": "some-test-vast-ad",
"crid": "crid_10",
"h": 90,
"w": 728,
"ext": {
"ttx": {
"mediaType": "video"
}
}
}]
}
],
"cur": "USD"
}
}
}
],

"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 0.5,
"adm": "some-test-vast-ad",
"crid": "crid_10",
"w": 728,
"h": 90,
"ext": {
"ttx": {
"mediaType": "video"
}
}
},
"type": "video"
}
]
}
]
}
Loading