Skip to content

Commit

Permalink
RTBHouse: detecting media type may return an error
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrj-rtbh committed Oct 20, 2023
1 parent 4478925 commit 3012d46
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 34 deletions.
43 changes: 23 additions & 20 deletions adapters/rtbhouse/rtbhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,42 +160,45 @@ func (adapter *RTBHouseAdapter) MakeBids(
var typedBid *adapters.TypedBid
for _, seatBid := range openRTBBidderResponse.SeatBid {
for _, bid := range seatBid.Bid {
var err error
bid := bid // pin! -> https://github.com/kyoh86/scopelint#whats-this
bidType := getMediaTypeForBid(bid)

typedBid = &adapters.TypedBid{
Bid: &bid,
BidType: bidType,
}
bidType, err := getMediaTypeForBid(bid)
if err != nil {
errs = append(errs, err)
continue
} else {
typedBid = &adapters.TypedBid{
Bid: &bid,
BidType: bidType,
}

// for native bid responses fix Adm field
if typedBid.BidType == openrtb_ext.BidTypeNative {
bid.AdM, err = getNativeAdm(bid.AdM)
if err != nil {
errs = append(errs, err)
return nil, errs
// for native bid responses fix Adm field
if typedBid.BidType == openrtb_ext.BidTypeNative {
bid.AdM, err = getNativeAdm(bid.AdM)
if err != nil {
errs = append(errs, err)
continue
}
}
}

bidderResponse.Bids = append(bidderResponse.Bids, typedBid)
bidderResponse.Bids = append(bidderResponse.Bids, typedBid)
}
}
}

bidderResponse.Currency = BidderCurrency

return bidderResponse, nil
return bidderResponse, errs

}

func getMediaTypeForBid(bid openrtb2.Bid) openrtb_ext.BidType {
func getMediaTypeForBid(bid openrtb2.Bid) (openrtb_ext.BidType, error) {
switch bid.MType {
case openrtb2.MarkupBanner:
return openrtb_ext.BidTypeBanner
return openrtb_ext.BidTypeBanner, nil
case openrtb2.MarkupNative:
return openrtb_ext.BidTypeNative
return openrtb_ext.BidTypeNative, nil
default:
return openrtb_ext.BidTypeBanner
return "", fmt.Errorf("unrecognized bid type in response from rtbhouse for bid %s", bid.ImpID)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"mockBidRequest": {
"imp": [
{
"ext": {
"bidder": {}
},
"id": "test-native-imp",
"native": {
"request": "{\"eventtrackers\":[{\"event\":1,\"methods\":[1,2]}],\"ver\":\"1.2\",\"assets\":[{\"id\":0,\"required\":1,\"title\":{\"len\":140}},{\"id\":1,\"required\":1,\"data\":{\"type\":2}},{\"id\":2,\"required\":1,\"img\":{\"type\":3}}]}",
"ver": "1.2"
}
},
{
"id": "test-banner-imp",
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"ext": {
"bidder": {}
}
}
],
"site": {
"page": "https://good.site/url"
},
"id": "test-multi-slot-request",
"ext": {},
"debug": 1
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://localhost/prebid_server",
"body": {
"id": "test-multi-slot-request",
"cur": [
"USD"
],
"imp": [
{
"id": "test-native-imp",
"native": {
"request": "{\"eventtrackers\":[{\"event\":1,\"methods\":[1,2]}],\"ver\":\"1.2\",\"assets\":[{\"id\":0,\"required\":1,\"title\":{\"len\":140}},{\"id\":1,\"required\":1,\"data\":{\"type\":2}},{\"id\":2,\"required\":1,\"img\":{\"type\":3}}]}",
"ver": "1.2"
},
"ext": {
"bidder": {}
}
},
{
"id": "test-banner-imp",
"banner": {
"format": [{
"w": 300,
"h": 250
}]
},
"ext": {
"bidder": {}
}
}
],
"site": {
"page": "https://good.site/url"
},
"ext": {}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-multi-slot-request",
"bidid": "test-bidid",
"cur": "USD",
"seatbid": [
{
"seat": "rtbhouse",
"bid": [
{
"id": "randomid-native",
"impid": "test-native-imp",
"price": 0.5,
"adid": "test-adid",
"adm": "{\"native\":{\"ver\":\"1.2\",\"assets\":[{\"id\":0,\"title\":{\"text\":\"title text\"}},{\"id\":1,\"data\":{\"value\":\"data value\"}},{\"id\":2,\"img\":{\"url\":\"image.url\",\"w\":1200,\"h\":628}}],\"link\":{\"url\":\"link.url\"},\"imptrackers\":[\"imp.tracker.url\"],\"eventtrackers\":[{\"event\":1,\"method\":1,\"url\":\"event.tracker.url\"}]}}",
"adomain": [ "adomain.com" ],
"cid": "test-cid",
"crid": "test-crid",
"dealid": "test-dealid",
"mtype": 99
},
{
"id": "randomid-banner",
"impid": "test-banner-imp",
"price": 0.500000,
"adid": "12345678",
"adm": "some-test-ad",
"cid": "987",
"crid": "12345678",
"h": 250,
"w": 300,
"mtype": 1
}
]
}
]
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [{
"bid": {
"id": "randomid-banner",
"impid": "test-banner-imp",
"price": 0.500000,
"adid": "12345678",
"adm": "some-test-ad",
"cid": "987",
"crid": "12345678",
"h": 250,
"w": 300,
"mtype": 1
},
"type": "banner"
}
]
}
],
"expectedMakeBidsErrors": [
{
"value": "unrecognized bid type in response from rtbhouse for bid test-native-imp",
"comparison": "literal"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": []
}
],
"expectedMakeBidsErrors": [
{
"value": "unable to get native adm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": []
}
],
"expectedMakeBidsErrors": [
{
"value": "unable to unmarshal native adm",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"mockBidRequest": {
"id": "test-request-id",
"site": {
"page": "https://good.site/url"
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://localhost/prebid_server",
"body": {
"id": "test-request-id",
"cur": [
"USD"
],
"site": {
"page": "https://good.site/url"
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {}
}
}
]
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "rtbhouse",
"bid": [
{
"id": "randomid",
"impid": "test-imp-id",
"price": 0.500000,
"adid": "12345678",
"adm": "some-test-ad",
"cid": "987",
"crid": "12345678",
"h": 250,
"w": 300,
"mtype": 99
}
]
}
],
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": []
}
],
"expectedMakeBidsErrors": [
{
"value": "unrecognized bid type in response from rtbhouse for bid test-imp-id",
"comparison": "literal"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,13 @@
"expectedBidResponses": [
{
"currency": "USD",
"bids": [{
"bid": {
"id": "randomid",
"impid": "test-imp-id",
"price": 0.5,
"adm": "some-test-ad",
"adid": "12345678",
"cid": "987",
"crid": "12345678",
"w": 300,
"h": 250
},
"type": "banner"
}]
"bids": []
}
],
"expectedMakeBidsErrors": [
{
"value": "unrecognized bid type in response from rtbhouse for bid test-imp-id",
"comparison": "literal"
}
]
}

0 comments on commit 3012d46

Please sign in to comment.