Skip to content

Commit 99d2a71

Browse files
IOTiagoFariashunj-nb
authored andcommitted
New Adapter: Interactive Offers (prebid#1835)
1 parent ae6b46a commit 99d2a71

File tree

17 files changed

+874
-237
lines changed

17 files changed

+874
-237
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package interactiveoffers
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"net/http"
7+
8+
"github.com/mxmCherry/openrtb/v15/openrtb2"
9+
"github.com/prebid/prebid-server/adapters"
10+
"github.com/prebid/prebid-server/config"
11+
"github.com/prebid/prebid-server/errortypes"
12+
"github.com/prebid/prebid-server/openrtb_ext"
13+
)
14+
15+
type adapter struct {
16+
endpoint string
17+
}
18+
19+
func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
20+
requestJSON, err := json.Marshal(request)
21+
if err != nil {
22+
return nil, []error{err}
23+
}
24+
25+
requestData := &adapters.RequestData{
26+
Method: "POST",
27+
Uri: a.endpoint,
28+
Body: requestJSON,
29+
}
30+
31+
return []*adapters.RequestData{requestData}, nil
32+
}
33+
34+
func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) {
35+
if responseData.StatusCode == http.StatusNoContent {
36+
return nil, nil
37+
}
38+
39+
if responseData.StatusCode == http.StatusBadRequest {
40+
err := &errortypes.BadInput{
41+
Message: "Unexpected status code: 400. Bad request from publisher. Run with request.debug = 1 for more info.",
42+
}
43+
return nil, []error{err}
44+
}
45+
46+
if responseData.StatusCode != http.StatusOK {
47+
err := &errortypes.BadServerResponse{
48+
Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info.", responseData.StatusCode),
49+
}
50+
return nil, []error{err}
51+
}
52+
53+
var response openrtb2.BidResponse
54+
if err := json.Unmarshal(responseData.Body, &response); err != nil {
55+
return nil, []error{err}
56+
}
57+
58+
bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp))
59+
bidResponse.Currency = response.Cur
60+
for _, seatBid := range response.SeatBid {
61+
for _, bid := range seatBid.Bid {
62+
bid := bid // pin https://github.com/kyoh86/scopelint#whats-this
63+
b := &adapters.TypedBid{
64+
Bid: &bid,
65+
BidType: openrtb_ext.BidTypeBanner,
66+
}
67+
bidResponse.Bids = append(bidResponse.Bids, b)
68+
}
69+
}
70+
return bidResponse, nil
71+
}
72+
73+
// Builder builds a new instance of the Interactiveoffers adapter for the given bidder with the given config.
74+
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) {
75+
bidder := &adapter{
76+
endpoint: config.Endpoint,
77+
}
78+
return bidder, nil
79+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package interactiveoffers
2+
3+
import (
4+
"testing"
5+
6+
"github.com/prebid/prebid-server/adapters/adapterstest"
7+
"github.com/prebid/prebid-server/config"
8+
"github.com/prebid/prebid-server/openrtb_ext"
9+
)
10+
11+
func TestJsonSamples(t *testing.T) {
12+
bidder, buildErr := Builder(openrtb_ext.BidderInteractiveoffers, config.Adapter{
13+
Endpoint: "https://rtb.ioadx.com/bidRequest/?partnerId=d9e56d418c4825d466ee96c7a31bf1da6b62fa04"})
14+
15+
if buildErr != nil {
16+
t.Fatalf("Builder returned unexpected error %v", buildErr)
17+
}
18+
19+
adapterstest.RunJSONBidderTest(t, "interactiveofferstest", bidder)
20+
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
{
2+
"mockBidRequest": {
3+
"id": "test-request-id",
4+
"site": {
5+
"page": "https://good.site/url"
6+
},
7+
"imp": [{
8+
"id": "test-imp-id",
9+
"banner": {
10+
"format": [{
11+
"w": 300,
12+
"h": 250
13+
}]
14+
},
15+
"ext": {
16+
"bidder": {
17+
"pubid": 35
18+
}
19+
}
20+
},{
21+
"id": "test-imp-id-2",
22+
"banner": {
23+
"format": [{
24+
"w": 300,
25+
"h": 250
26+
}]
27+
},
28+
"ext": {
29+
"bidder": {
30+
"pubid": 35
31+
}
32+
}
33+
}]
34+
},
35+
36+
"httpCalls": [{
37+
"expectedRequest": {
38+
"uri": "https://rtb.ioadx.com/bidRequest/?partnerId=d9e56d418c4825d466ee96c7a31bf1da6b62fa04",
39+
"body": {
40+
"id": "test-request-id",
41+
"site": {
42+
"page": "https://good.site/url"
43+
},
44+
"imp": [{
45+
"id": "test-imp-id",
46+
"banner": {
47+
"format": [{
48+
"w": 300,
49+
"h": 250
50+
}]
51+
},
52+
"ext": {
53+
"bidder": {
54+
"pubid": 35
55+
}
56+
}
57+
},{
58+
"id": "test-imp-id-2",
59+
"banner": {
60+
"format": [{
61+
"w": 300,
62+
"h": 250
63+
}]
64+
},
65+
"ext": {
66+
"bidder": {
67+
"pubid": 35
68+
}
69+
}
70+
}]
71+
}
72+
},
73+
"mockResponse": {
74+
"status": 200,
75+
"body": {
76+
"id": "test-request-id",
77+
"seatbid": [{
78+
"seat": "interactiveoffers",
79+
"bid": [{
80+
"id": "randomid",
81+
"impid": "test-imp-id",
82+
"price": 0.500000,
83+
"adid": "12345678",
84+
"adm": "some-test-ad",
85+
"cid": "987",
86+
"crid": "12345678",
87+
"h": 250,
88+
"w": 300
89+
},{
90+
"id": "randomid2",
91+
"impid": "test-imp-id-2",
92+
"price": 0.500000,
93+
"adid": "12345678",
94+
"adm": "some-test-ad",
95+
"cid": "987",
96+
"crid": "12345678",
97+
"h": 250,
98+
"w": 300
99+
}]
100+
}],
101+
"cur": "USD"
102+
}
103+
}
104+
}],
105+
106+
"expectedBidResponses": [{
107+
"currency": "USD",
108+
"bids": [{
109+
"bid": {
110+
"id": "randomid",
111+
"impid": "test-imp-id",
112+
"price": 0.5,
113+
"adm": "some-test-ad",
114+
"adid": "12345678",
115+
"cid": "987",
116+
"crid": "12345678",
117+
"w": 300,
118+
"h": 250
119+
},
120+
"type": "banner"
121+
},{
122+
"bid": {
123+
"id": "randomid2",
124+
"impid": "test-imp-id-2",
125+
"price": 0.5,
126+
"adm": "some-test-ad",
127+
"adid": "12345678",
128+
"cid": "987",
129+
"crid": "12345678",
130+
"w": 300,
131+
"h": 250
132+
},
133+
"type": "banner"
134+
}]
135+
}]
136+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"mockBidRequest": {
3+
"id": "test-request-id",
4+
"site": {
5+
"page": "https://good.site/url"
6+
},
7+
"imp": [{
8+
"id": "test-imp-id",
9+
"banner": {
10+
"format": [{
11+
"w": 300,
12+
"h": 250
13+
}]
14+
},
15+
"ext": {
16+
"bidder": {
17+
"pubid": 35
18+
}
19+
}
20+
}]
21+
},
22+
23+
"httpCalls": [{
24+
"expectedRequest": {
25+
"uri": "https://rtb.ioadx.com/bidRequest/?partnerId=d9e56d418c4825d466ee96c7a31bf1da6b62fa04",
26+
"body": {
27+
"id": "test-request-id",
28+
"site": {
29+
"page": "https://good.site/url"
30+
},
31+
"imp": [{
32+
"id": "test-imp-id",
33+
"banner": {
34+
"format": [{
35+
"w": 300,
36+
"h": 250
37+
}]
38+
},
39+
"ext": {
40+
"bidder": {
41+
"pubid": 35
42+
}
43+
}
44+
}]
45+
}
46+
},
47+
"mockResponse": {
48+
"status": 200,
49+
"body": {
50+
"id": "test-request-id",
51+
"seatbid": [{
52+
"seat": "interactiveoffers",
53+
"bid": [{
54+
"id": "randomid",
55+
"impid": "test-imp-id",
56+
"price": 0.500000,
57+
"adid": "12345678",
58+
"adm": "some-test-ad",
59+
"cid": "987",
60+
"crid": "12345678",
61+
"h": 250,
62+
"w": 300
63+
}]
64+
}],
65+
"cur": "USD"
66+
}
67+
}
68+
}],
69+
70+
"expectedBidResponses": [{
71+
"currency": "USD",
72+
"bids": [{
73+
"bid": {
74+
"id": "randomid",
75+
"impid": "test-imp-id",
76+
"price": 0.5,
77+
"adm": "some-test-ad",
78+
"adid": "12345678",
79+
"cid": "987",
80+
"crid": "12345678",
81+
"w": 300,
82+
"h": 250
83+
},
84+
"type": "banner"
85+
}]
86+
}]
87+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"pubid": 35
3+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"mockBidRequest": {
3+
"id": "test-request-id",
4+
"site": {
5+
"page": "https://good.site/url"
6+
},
7+
"imp": [{
8+
"id": "test-imp-id",
9+
"banner": {
10+
"format": [{
11+
"w": 300,
12+
"h": 250
13+
}]
14+
},
15+
"ext": {
16+
"bidder": {
17+
"pubid": 35
18+
}
19+
}
20+
}]
21+
},
22+
23+
"httpCalls": [{
24+
"expectedRequest": {
25+
"uri": "https://rtb.ioadx.com/bidRequest/?partnerId=d9e56d418c4825d466ee96c7a31bf1da6b62fa04",
26+
"body": {
27+
"id": "test-request-id",
28+
"site": {
29+
"page": "https://good.site/url"
30+
},
31+
"imp": [{
32+
"id": "test-imp-id",
33+
"banner": {
34+
"format": [{
35+
"w": 300,
36+
"h": 250
37+
}]
38+
},
39+
"ext": {
40+
"bidder": {
41+
"pubid": 35
42+
}
43+
}
44+
}]
45+
}
46+
},
47+
"mockResponse": {
48+
"status": 204,
49+
"body": {}
50+
}
51+
}],
52+
53+
"expectedBidResponses": [],
54+
"expectedMakeBidsErrors": []
55+
}

0 commit comments

Comments
 (0)