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 1 commit
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
68 changes: 67 additions & 1 deletion adapters/33across/33across.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ 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 Down Expand Up @@ -99,6 +106,19 @@ func preprocess(request *openrtb.BidRequest) error {
}
}

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

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

imp.Video = videoCopy
}

imp.Ext = impExtJSON
siteCopy := *request.Site
siteCopy.ID = ttxExt.SiteId
Expand Down Expand Up @@ -135,16 +155,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
103 changes: 103 additions & 0 deletions adapters/33across/33across/exemplary/multi-format.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [{"w": 728, "h": 90}]
},
"video": {
"w": 728,
"h": 90,
"protocols": [2],
"playbackmethod": [2],
"mimes": ["foo", "bar"]
},
"ext": {
"bidder": {
"siteId": "fake-site-id",
"productId": "inview"
}
}
}
],
"site": {}
},

"httpCalls": [
{
"expectedRequest": {
"uri": "http://ssc.33across.com",
"body": {
"id": "test-request-id",
"imp": [
{
"id":"test-imp-id",
"banner": {
"format": [{"w": 728, "h": 90}]
},
"video": {
"w": 728,
"h": 90,
"protocols": [2],
"placement": 2,
"playbackmethod": [2],
"mimes": ["foo", "bar"]
},
"ext": {
"ttx": {
"prod": "inview"
}
}
}
],
"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-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-ad",
"crid": "crid_10",
"w": 728,
"h": 90
},
"type": "banner"
}
]
}
]
}
110 changes: 110 additions & 0 deletions adapters/33across/33across/exemplary/simple-video.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"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,
"ext": {
"ttx": {
"mediaType": "video"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we only expect the 33Across server to respond with an "ext" field to video requests? Because in the banner example found in adapters/33across/33across/exemplary/simple-banner.json the "mockResponse" doesn't have that. If they do, should we expect a "banner" value?

45       "mockResponse": {
46         "status": 200,
47         "body": {
48           "id": "test-request-id",
49           "seatbid": [
50             {
51               "seat": "ttx",
52               "bid": [{
53                 "id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
54                 "impid": "test-imp-id",
55                 "price": 0.500000,
56                 "adm": "some-test-ad",
57                 "crid": "crid_10",
58                 "h": 90,
59                 "w": 728
   +               "ext": {
   +                 "ttx": {
   +                   "mediaType": "video"
   +                 }
   +               }
60               }]
61             }
62           ],
63           "cur": "USD"
64         }
65       }
66     }
67   ],
adapters/33across/33across/exemplary/simple-banner.json

Copy link
Contributor Author

@curlyblueeagle curlyblueeagle Nov 4, 2020

Choose a reason for hiding this comment

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

Correct, the ext field if present will specify the mediaType. If not present assume banner, which is what the adapter will do in such a case.

}
}]
}
],
"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"
}
]
}
]
}
6 changes: 6 additions & 0 deletions adapters/33across/33across/params/race/video.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"productId": "siab",
"siteId": "33across",
"zoneId": "33AcrossZone"
}

2 changes: 2 additions & 0 deletions static/bidder-info/33across.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ capabilities:
app:
mediaTypes:
- banner
- video
site:
mediaTypes:
- banner
- video