Skip to content

Commit 3aadbd8

Browse files
arkan303AdSpacesDevelopers
authored and
AdSpacesDevelopers
committed
New adapter Coinzilla (prebid#3385)
* New adapter "Coinzilla" added * Solved required modifications related to bidderRequest.referrerInfo.referer
1 parent 4cfcc96 commit 3aadbd8

File tree

3 files changed

+233
-0
lines changed

3 files changed

+233
-0
lines changed

modules/coinzillaBidAdapter.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import * as utils from 'src/utils';
2+
import {config} from 'src/config';
3+
import {registerBidder} from 'src/adapters/bidderFactory';
4+
5+
const BIDDER_CODE = 'coinzilla';
6+
const ENDPOINT_URL = 'https://request.czilladx.com/serve/request.php';
7+
8+
export const spec = {
9+
code: BIDDER_CODE,
10+
aliases: ['czlla'], // short code
11+
12+
/**
13+
* Determines whether or not the given bid request is valid.
14+
*
15+
* @param {BidRequest} bid The bid params to validate.
16+
* @return boolean True if this is a valid bid, and false otherwise.
17+
*/
18+
isBidRequestValid: function (bid) {
19+
return !!(bid.params.placementId);
20+
},
21+
22+
/**
23+
* Make a server request from the list of BidRequests.
24+
*
25+
* @return Array Info describing the request to the server.
26+
* @param validBidRequests
27+
* @param bidderRequest
28+
*/
29+
buildRequests: function (validBidRequests, bidderRequest) {
30+
if (validBidRequests.length === 0) {
31+
return [];
32+
}
33+
return validBidRequests.map(bidRequest => {
34+
const sizes = utils.parseSizesInput(bidRequest.sizes)[0];
35+
const width = sizes.split('x')[0];
36+
const height = sizes.split('x')[1];
37+
const payload = {
38+
placementId: bidRequest.params.placementId,
39+
width: width,
40+
height: height,
41+
bidId: bidRequest.bidId,
42+
referer: bidderRequest.refererInfo.referer,
43+
};
44+
return {
45+
method: 'POST',
46+
url: ENDPOINT_URL,
47+
data: payload
48+
};
49+
});
50+
},
51+
52+
/**
53+
* Unpack the response from the server into a list of bids.
54+
*
55+
* @param {ServerResponse} serverResponse A successful response from the server.
56+
* @param bidRequest
57+
* @return {Bid[]} An array of bids which were nested inside the server.
58+
*/
59+
interpretResponse: function (serverResponse, bidRequest) {
60+
const bidResponses = [];
61+
const response = serverResponse.body;
62+
const creativeId = response.creativeId || 0;
63+
const width = response.width || 0;
64+
const height = response.height || 0;
65+
const cpm = response.cpm || 0;
66+
if (width !== 0 && height !== 0 && cpm !== 0 && creativeId !== 0) {
67+
const dealId = response.dealid || '';
68+
const currency = response.currency || 'EUR';
69+
const netRevenue = (response.netRevenue === undefined) ? true : response.netRevenue;
70+
const referrer = bidRequest.data.referer;
71+
const bidResponse = {
72+
requestId: response.requestId,
73+
cpm: cpm,
74+
width: response.width,
75+
height: response.height,
76+
creativeId: creativeId,
77+
dealId: dealId,
78+
currency: currency,
79+
netRevenue: netRevenue,
80+
ttl: config.getConfig('_bidderTimeout'),
81+
referrer: referrer,
82+
ad: response.ad
83+
};
84+
bidResponses.push(bidResponse);
85+
}
86+
return bidResponses;
87+
},
88+
};
89+
registerBidder(spec);

modules/coinzillaBidAdapter.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Overview
2+
3+
```
4+
Module Name: Coinzilla Bidder Adapter
5+
Module Type: Coinzilla Adapter
6+
Maintainer: [email protected]
7+
```
8+
9+
# Description
10+
11+
Our module helps you have an easier time implementing Coinzilla on your website. All you have to do is replace the ``placementId`` with your zoneID, depending on the required size in your account dashboard. If you need additional information please contact us at ``[email protected]``.
12+
# Test Parameters
13+
```
14+
var adUnits = [{
15+
code: 'test-ad-div',
16+
sizes: [[300, 250]],
17+
bids: [{
18+
bidder: 'coinzilla',
19+
params: {
20+
placementId: 'testPlacementId'
21+
}
22+
}]
23+
}];
24+
```
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import {assert, expect} from 'chai';
2+
import {spec} from 'modules/coinzillaBidAdapter';
3+
import {newBidder} from 'src/adapters/bidderFactory';
4+
5+
const ENDPOINT_URL = 'https://request.czilladx.com/serve/request.php';
6+
7+
describe('coinzillaBidAdapter', function () {
8+
const adapter = newBidder(spec);
9+
describe('isBidRequestValid', function () {
10+
let bid = {
11+
'bidder': 'coinzilla',
12+
'params': {
13+
placementId: 'testPlacementId'
14+
},
15+
'adUnitCode': 'adunit-code',
16+
'sizes': [
17+
[300, 250]
18+
],
19+
'bidId': '1234asdf1234',
20+
'bidderRequestId': '1234asdf1234asdf',
21+
'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf120'
22+
};
23+
it('should return true where required params found', function () {
24+
expect(spec.isBidRequestValid(bid)).to.equal(true);
25+
});
26+
});
27+
describe('buildRequests', function () {
28+
let bidRequests = [
29+
{
30+
'bidder': 'coinzilla',
31+
'params': {
32+
placementId: 'testPlacementId'
33+
},
34+
'sizes': [
35+
[300, 250]
36+
],
37+
'bidId': '23beaa6af6cdde',
38+
'bidderRequestId': '19c0c1efdf37e7',
39+
'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1',
40+
},
41+
{
42+
'bidder': 'coinzilla',
43+
'params': {
44+
placementId: 'testPlacementId'
45+
},
46+
'adUnitCode': 'adunit-code2',
47+
'sizes': [
48+
[300, 250]
49+
],
50+
'bidId': '382091349b149f"',
51+
'bidderRequestId': '1f9c98192de251',
52+
'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1',
53+
}
54+
];
55+
56+
let bidderRequests = {
57+
'refererInfo': {
58+
'numIframes': 0,
59+
'reachedTop': true,
60+
'referer': 'http://example.com',
61+
'stack': ['http://example.com']
62+
}
63+
};
64+
65+
const request = spec.buildRequests(bidRequests, bidderRequests);
66+
it('sends bid request to our endpoint via POST', function () {
67+
expect(request[0].method).to.equal('POST');
68+
expect(request[1].method).to.equal('POST');
69+
});
70+
it('attaches source and version to endpoint URL as query params', function () {
71+
expect(request[0].url).to.equal(ENDPOINT_URL);
72+
expect(request[1].url).to.equal(ENDPOINT_URL);
73+
});
74+
});
75+
76+
describe('interpretResponse', function () {
77+
let bidRequest = [
78+
{
79+
'method': 'POST',
80+
'url': ENDPOINT_URL,
81+
'data': {
82+
'placementId': 'testPlacementId',
83+
'width': '300',
84+
'height': '200',
85+
'bidId': 'bidId123',
86+
'referer': 'www.example.com'
87+
}
88+
89+
}
90+
];
91+
let serverResponse = {
92+
body: {
93+
'ad': '<html><h3>I am an ad</h3></html> ',
94+
'cpm': 4.2,
95+
'creativeId': '12345asdfg',
96+
'currency': 'EUR',
97+
'statusMessage': 'Bid available',
98+
'requestId': 'bidId123',
99+
'width': 300,
100+
'height': 250,
101+
'netRevenue': true
102+
}
103+
};
104+
it('should get the correct bid response', function () {
105+
let expectedResponse = [{
106+
'requestId': 'bidId123',
107+
'cpm': 4.2,
108+
'width': 300,
109+
'height': 250,
110+
'creativeId': '12345asdfg',
111+
'currency': 'EUR',
112+
'netRevenue': true,
113+
'ttl': 3000,
114+
'ad': '<html><h3>I am an ad</h3></html>'
115+
}];
116+
let result = spec.interpretResponse(serverResponse, bidRequest[0]);
117+
expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse));
118+
});
119+
});
120+
});

0 commit comments

Comments
 (0)