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

New adapter Coinzilla #3385

Merged
merged 3 commits into from
Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions modules/coinzillaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import * as utils from 'src/utils';
import {config} from 'src/config';
import {registerBidder} from 'src/adapters/bidderFactory';

const BIDDER_CODE = 'coinzilla';
const ENDPOINT_URL = 'https://request.czilladx.com/serve/request.php';

export const spec = {
code: BIDDER_CODE,
aliases: ['czlla'], // short code

/**
* Determines whether or not the given bid request is valid.
*
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
return !!(bid.params.placementId);
},

/**
* Make a server request from the list of BidRequests.
*
* @return Array Info describing the request to the server.
* @param validBidRequests
* @param bidderRequest
*/
buildRequests: function (validBidRequests, bidderRequest) {
if (validBidRequests.length === 0) {
return [];
}
return validBidRequests.map(bidRequest => {
const sizes = utils.parseSizesInput(bidRequest.sizes)[0];
const width = sizes.split('x')[0];
const height = sizes.split('x')[1];
const payload = {
placementId: bidRequest.params.placementId,
width: width,
height: height,
bidId: bidRequest.bidId,
referer: bidderRequest.refererInfo.referer,
};
return {
method: 'POST',
url: ENDPOINT_URL,
data: payload
};
});
},

/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @param bidRequest
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = [];
const response = serverResponse.body;
const creativeId = response.creativeId || 0;
const width = response.width || 0;
const height = response.height || 0;
const cpm = response.cpm || 0;
if (width !== 0 && height !== 0 && cpm !== 0 && creativeId !== 0) {
const dealId = response.dealid || '';
const currency = response.currency || 'EUR';
const netRevenue = (response.netRevenue === undefined) ? true : response.netRevenue;
const referrer = bidRequest.data.referer;
const bidResponse = {
requestId: response.requestId,
cpm: cpm,
width: response.width,
height: response.height,
creativeId: creativeId,
dealId: dealId,
currency: currency,
netRevenue: netRevenue,
ttl: config.getConfig('_bidderTimeout'),
referrer: referrer,
ad: response.ad
};
bidResponses.push(bidResponse);
}
return bidResponses;
},
};
registerBidder(spec);
24 changes: 24 additions & 0 deletions modules/coinzillaBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Overview

```
Module Name: Coinzilla Bidder Adapter
Module Type: Coinzilla Adapter
Maintainer: technical@sevio.com
```

# Description

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 ``publishers@coinzilla.com``.
# Test Parameters
```
var adUnits = [{
code: 'test-ad-div',
sizes: [[300, 250]],
bids: [{
bidder: 'coinzilla',
params: {
placementId: 'testPlacementId'
}
}]
}];
```
120 changes: 120 additions & 0 deletions test/spec/modules/coinzillaBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import {assert, expect} from 'chai';
import {spec} from 'modules/coinzillaBidAdapter';
import {newBidder} from 'src/adapters/bidderFactory';

const ENDPOINT_URL = 'https://request.czilladx.com/serve/request.php';

describe('coinzillaBidAdapter', function () {
const adapter = newBidder(spec);
describe('isBidRequestValid', function () {
let bid = {
'bidder': 'coinzilla',
'params': {
placementId: 'testPlacementId'
},
'adUnitCode': 'adunit-code',
'sizes': [
[300, 250]
],
'bidId': '1234asdf1234',
'bidderRequestId': '1234asdf1234asdf',
'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf120'
};
it('should return true where required params found', function () {
expect(spec.isBidRequestValid(bid)).to.equal(true);
});
});
describe('buildRequests', function () {
let bidRequests = [
{
'bidder': 'coinzilla',
'params': {
placementId: 'testPlacementId'
},
'sizes': [
[300, 250]
],
'bidId': '23beaa6af6cdde',
'bidderRequestId': '19c0c1efdf37e7',
'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1',
},
{
'bidder': 'coinzilla',
'params': {
placementId: 'testPlacementId'
},
'adUnitCode': 'adunit-code2',
'sizes': [
[300, 250]
],
'bidId': '382091349b149f"',
'bidderRequestId': '1f9c98192de251',
'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1',
}
];

let bidderRequests = {
'refererInfo': {
'numIframes': 0,
'reachedTop': true,
'referer': 'http://example.com',
'stack': ['http://example.com']
}
};

const request = spec.buildRequests(bidRequests, bidderRequests);
it('sends bid request to our endpoint via POST', function () {
expect(request[0].method).to.equal('POST');
expect(request[1].method).to.equal('POST');
});
it('attaches source and version to endpoint URL as query params', function () {
expect(request[0].url).to.equal(ENDPOINT_URL);
expect(request[1].url).to.equal(ENDPOINT_URL);
});
});

describe('interpretResponse', function () {
let bidRequest = [
{
'method': 'POST',
'url': ENDPOINT_URL,
'data': {
'placementId': 'testPlacementId',
'width': '300',
'height': '200',
'bidId': 'bidId123',
'referer': 'www.example.com'
}

}
];
let serverResponse = {
body: {
'ad': '<html><h3>I am an ad</h3></html> ',
'cpm': 4.2,
'creativeId': '12345asdfg',
'currency': 'EUR',
'statusMessage': 'Bid available',
'requestId': 'bidId123',
'width': 300,
'height': 250,
'netRevenue': true
}
};
it('should get the correct bid response', function () {
let expectedResponse = [{
'requestId': 'bidId123',
'cpm': 4.2,
'width': 300,
'height': 250,
'creativeId': '12345asdfg',
'currency': 'EUR',
'netRevenue': true,
'ttl': 3000,
'ad': '<html><h3>I am an ad</h3></html>'
}];
let result = spec.interpretResponse(serverResponse, bidRequest[0]);
expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse));
});
});
});