Skip to content

Commit 0c64b69

Browse files
seergiioo6pycnvr
authored andcommitted
Adpone Bid Adapter + test (prebid#3663)
1 parent 56112d4 commit 0c64b69

File tree

3 files changed

+200
-0
lines changed

3 files changed

+200
-0
lines changed

modules/adponeBidAdapter.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import {BANNER} from '../src/mediaTypes';
2+
import {registerBidder} from '../src/adapters/bidderFactory';
3+
4+
const ADPONE_CODE = 'adpone';
5+
const ADPONE_ENDPOINT = 'https://rtb.adpone.com/bid-request';
6+
const ADPONE_REQUEST_METHOD = 'POST';
7+
const ADPONE_CURRENCY = 'EUR';
8+
9+
export const spec = {
10+
code: ADPONE_CODE,
11+
supportedMediaTypes: [BANNER],
12+
13+
isBidRequestValid: bid => {
14+
return !!bid.params.placementId && !!bid.bidId;
15+
},
16+
17+
buildRequests: bidRequests => {
18+
return bidRequests.map(bid => {
19+
const url = ADPONE_ENDPOINT + '?pid=' + bid.params.placementId;
20+
const data = {
21+
at: 1,
22+
id: bid.bidId,
23+
imp: bid.sizes.map((size, index) => (
24+
{
25+
id: bid.bidId + '_' + index,
26+
banner: {
27+
w: size[0],
28+
h: size[1]
29+
}
30+
}))
31+
};
32+
33+
return { method: ADPONE_REQUEST_METHOD, url, data }
34+
});
35+
},
36+
37+
interpretResponse: (serverResponse, bidRequest) => {
38+
if (!serverResponse || !serverResponse.body) {
39+
return [];
40+
}
41+
42+
let answer = [];
43+
44+
serverResponse.body.seatbid.forEach(seatbid => {
45+
if (seatbid.bid.length) {
46+
answer = [...answer, ...seatbid.bid.filter(bid => bid.price > 0).map(bid => ({
47+
id: bid.id,
48+
requestId: bidRequest.data.id,
49+
cpm: bid.price,
50+
ad: bid.adm,
51+
width: bid.w || 0,
52+
height: bid.h || 0,
53+
currency: serverResponse.body.cur || ADPONE_CURRENCY,
54+
netRevenue: true,
55+
ttl: 300,
56+
creativeId: bid.crid || 0
57+
}))];
58+
}
59+
});
60+
61+
return answer;
62+
}
63+
64+
};
65+
66+
registerBidder(spec);

modules/adponeBidAdapter.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Overview
2+
3+
Module Name: Adpone Bidder Adapter
4+
5+
Module Type: Bidder Adapter
6+
7+
Maintainer: [email protected]
8+
9+
# Description
10+
11+
You can use this adapter to get a bid from adpone.com.
12+
13+
About us : https://www.adpone.com
14+
15+
16+
# Test Parameters
17+
```javascript
18+
var adUnits = [
19+
{
20+
code: 'div-adpone-example',
21+
sizes: [[300, 250]],
22+
bids: [
23+
{
24+
bidder: "adpone",
25+
params: {
26+
placementId: "1234"
27+
}
28+
}
29+
]
30+
}
31+
];
32+
```
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { expect } from 'chai';
2+
import { spec } from 'modules/adponeBidAdapter';
3+
4+
describe('adponeBidAdapter', function () {
5+
let bid = {
6+
bidder: 'adpone',
7+
adUnitCode: 'adunit-code',
8+
sizes: [[300, 250]],
9+
bidId: '30b31c1838de1e',
10+
bidderRequestId: '22edbae2733bf6',
11+
auctionId: '1d1a030790a475',
12+
params: {
13+
placementId: '1',
14+
}
15+
};
16+
17+
describe('isBidRequestValid', function () {
18+
it('should return true when necessary information is found', function () {
19+
expect(spec.isBidRequestValid(bid)).to.be.true;
20+
});
21+
22+
it('should return false when necessary information is not found', function () {
23+
// empty bid
24+
expect(spec.isBidRequestValid({bidId: '', params: {}})).to.be.false;
25+
26+
// empty bidId
27+
bid.bidId = '';
28+
expect(spec.isBidRequestValid(bid)).to.be.false;
29+
30+
// empty placementId
31+
bid.bidId = '30b31c1838de1e';
32+
bid.params.placementId = '';
33+
expect(spec.isBidRequestValid(bid)).to.be.false;
34+
35+
bid.adUnitCode = 'adunit-code';
36+
});
37+
});
38+
});
39+
40+
describe('interpretResponse', function () {
41+
let serverResponse;
42+
let bidRequest = { data: {id: '1234'} };
43+
44+
beforeEach(function () {
45+
serverResponse = {
46+
body: {
47+
id: '2579e20c0bb89',
48+
seatbid: [
49+
{
50+
bid: [
51+
{
52+
id: '613673EF-A07C-4486-8EE9-3FC71A7DC73D',
53+
impid: '2579e20c0bb89_0',
54+
price: 1,
55+
adm: '<html><a href="http://www.adpone.com" target="_blank"><img src ="https://placehold.it/300x250" /></a></html>',
56+
adomain: [
57+
'www.addomain.com'
58+
],
59+
iurl: 'http://localhost11',
60+
crid: 'creative111',
61+
h: 250,
62+
w: 300,
63+
ext: {
64+
dspid: 6
65+
}
66+
}
67+
],
68+
seat: 'adpone'
69+
}
70+
],
71+
cur: 'USD'
72+
},
73+
};
74+
});
75+
76+
it('should correctly reorder the server response', function () {
77+
const newResponse = spec.interpretResponse(serverResponse, bidRequest);
78+
expect(newResponse.length).to.be.equal(1);
79+
expect(newResponse[0]).to.deep.equal({
80+
id: '613673EF-A07C-4486-8EE9-3FC71A7DC73D',
81+
requestId: '1234',
82+
cpm: 1,
83+
width: 300,
84+
height: 250,
85+
creativeId: 'creative111',
86+
currency: 'USD',
87+
netRevenue: true,
88+
ttl: 300,
89+
ad: '<html><a href="http://www.adpone.com" target="_blank"><img src ="https://placehold.it/300x250" /></a></html>'
90+
});
91+
});
92+
93+
it('should not add responses if the cpm is 0 or null', function () {
94+
serverResponse.body.seatbid[0].bid[0].price = 0;
95+
let response = spec.interpretResponse(serverResponse, bidRequest);
96+
expect(response).to.deep.equal([]);
97+
98+
serverResponse.body.seatbid[0].bid[0].price = null;
99+
response = spec.interpretResponse(serverResponse, bidRequest);
100+
expect(response).to.deep.equal([])
101+
});
102+
});

0 commit comments

Comments
 (0)