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

Sharethrough: Support native ads #2780

27 changes: 22 additions & 5 deletions adapters/sharethrough/sharethrough.go
Expand Up @@ -130,20 +130,37 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R

bidderResponse := adapters.NewBidderResponse()
bidderResponse.Currency = "USD"
var errors []error

for _, seatBid := range bidResp.SeatBid {
for i := range seatBid.Bid {
bidType := openrtb_ext.BidTypeBanner
if bidReq.Imp[0].Video != nil {
bidType = openrtb_ext.BidTypeVideo
bid := &seatBid.Bid[i]
bidType, err := getMediaTypeForBid(*bid)
if err != nil {
errors = append(errors, err)
}

bidderResponse.Bids = append(bidderResponse.Bids, &adapters.TypedBid{
BidType: bidType,
Bid: &seatBid.Bid[i],
Bid: bid,
})
}
}

return bidderResponse, nil
return bidderResponse, errors
}

func getMediaTypeForBid(bid openrtb2.Bid) (openrtb_ext.BidType, error) {

if bid.Ext != nil {
var bidExt openrtb_ext.ExtBid
err := json.Unmarshal(bid.Ext, &bidExt)
if err == nil && bidExt.Prebid != nil {
return openrtb_ext.ParseBidType(string(bidExt.Prebid.Type))
}
}

return "", &errortypes.BadServerResponse{
Message: fmt.Sprintf("Failed to parse bid mediatype for impression \"%s\"", bid.ImpID),
}
}
22 changes: 14 additions & 8 deletions adapters/sharethrough/sharethroughtest/exemplary/app-banner.json
Expand Up @@ -37,12 +37,8 @@
"expectedRequest": {
"uri": "http://whatever.url",
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
],
"Accept": [
"application/json"
]
"Content-Type": ["application/json;charset=utf-8"],
"Accept": ["application/json"]
},
"body": {
"id": "web-banner",
Expand Down Expand Up @@ -100,7 +96,12 @@
"adm": "<div>Ad</div>",
"price": 20,
"w": 300,
"h": 250
"h": 250,
"ext": {
"prebid": {
"type": "banner"
}
}
}
]
}
Expand All @@ -121,7 +122,12 @@
"adm": "<div>Ad</div>",
"price": 20,
"w": 300,
"h": 250
"h": 250,
"ext": {
"prebid": {
"type": "banner"
}
}
},
"type": "banner"
}
Expand Down
105 changes: 105 additions & 0 deletions adapters/sharethrough/sharethroughtest/exemplary/app-native.json
@@ -0,0 +1,105 @@
{
"mockBidRequest": {
"id": "web-native",
"imp": [
{
"id": "native-imp-id",
"ext": {
"bidder": {
"pkey": "pkey"
}
},
"native": {
"ver": "1.2",
"request": "placeholder request"
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://whatever.url",
"headers": {
"Content-Type": ["application/json;charset=utf-8"],
"Accept": ["application/json"]
},
"body": {
"id": "web-native",
"imp": [
{
"id": "native-imp-id",
"tagid": "pkey",
"ext": {
"bidder": {
"pkey": "pkey"
}
},
"native": {
"ver": "1.2",
"request": "placeholder request"
}
}
],
"source": {
"ext": {
"version": "",
"str": "10.0"
}
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "web-native",
"cur": "USD",
"seatbid": [
{
"bid": [
{
"id": "web-native",
"impid": "native-imp-id",
"crid": "some-creative-id",
"adm": "<div>Ad</div>",
"price": 20,
"w": 300,
"h": 250,
"ext": {
"prebid": {
"type": "native"
}
}
}
]
}
]
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "web-native",
"impid": "native-imp-id",
"crid": "some-creative-id",
"adm": "<div>Ad</div>",
"price": 20,
"w": 300,
"h": 250,
"ext": {
"prebid": {
"type": "native"
}
}
},
"type": "native"
}
]
}
]
}
48 changes: 20 additions & 28 deletions adapters/sharethrough/sharethroughtest/exemplary/app-video.json
Expand Up @@ -11,21 +11,14 @@
},
"bidder": {
"pkey": "pkey",
"badv": [
"ford.com"
],
"bcat": [
"IAB-1",
"IAB-2"
]
"badv": ["ford.com"],
"bcat": ["IAB-1", "IAB-2"]
}
},
"video": {
"w": 640,
"h": 480,
"mimes": [
"video/mp4"
],
"mimes": ["video/mp4"],
"placement": 1
}
}
Expand All @@ -47,12 +40,8 @@
"expectedRequest": {
"uri": "http://whatever.url",
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
],
"Accept": [
"application/json"
]
"Content-Type": ["application/json;charset=utf-8"],
"Accept": ["application/json"]
},
"body": {
"id": "web-video",
Expand All @@ -67,21 +56,14 @@
},
"bidder": {
"pkey": "pkey",
"badv": [
"ford.com"
],
"bcat": [
"IAB-1",
"IAB-2"
]
"badv": ["ford.com"],
"bcat": ["IAB-1", "IAB-2"]
}
},
"video": {
"w": 640,
"h": 480,
"mimes": [
"video/mp4"
],
"mimes": ["video/mp4"],
"placement": 1
}
}
Expand Down Expand Up @@ -122,7 +104,12 @@
"adm": "<VAST>TAG</VAST>",
"price": 20,
"w": 640,
"h": 480
"h": 480,
"ext": {
"prebid": {
"type": "video"
}
}
}
]
}
Expand All @@ -143,7 +130,12 @@
"adm": "<VAST>TAG</VAST>",
"price": 20,
"w": 640,
"h": 480
"h": 480,
"ext": {
"prebid": {
"type": "video"
}
}
},
"type": "video"
}
Expand Down
22 changes: 14 additions & 8 deletions adapters/sharethrough/sharethroughtest/exemplary/web-banner.json
Expand Up @@ -38,12 +38,8 @@
"expectedRequest": {
"uri": "http://whatever.url",
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
],
"Accept": [
"application/json"
]
"Content-Type": ["application/json;charset=utf-8"],
"Accept": ["application/json"]
},
"body": {
"id": "web-banner",
Expand Down Expand Up @@ -101,7 +97,12 @@
"adm": "<div>Ad</div>",
"price": 20,
"w": 300,
"h": 250
"h": 250,
"ext": {
"prebid": {
"type": "banner"
}
}
}
]
}
Expand All @@ -122,7 +123,12 @@
"adm": "<div>Ad</div>",
"price": 20,
"w": 300,
"h": 250
"h": 250,
"ext": {
"prebid": {
"type": "banner"
}
}
},
"type": "banner"
}
Expand Down