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 "Cointraffic" added #5695

Merged
merged 3 commits into from
Sep 9, 2020
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
81 changes: 81 additions & 0 deletions modules/cointrafficBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import * as utils from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js'

const BIDDER_CODE = 'cointraffic';
const ENDPOINT_URL = 'https://appspb.cointraffic.io/pb/tmp';

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],

/**
* 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.
*
* @param validBidRequests
* @param bidderRequest
* @return Array Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
return validBidRequests.map(bidRequest => {
const sizes = utils.parseSizesInput(bidRequest.params.size || bidRequest.sizes);

const payload = {
placementId: bidRequest.params.placementId,
sizes: sizes,
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;

if (utils.isEmpty(response)) {
return bidResponses;
}

const bidResponse = {
requestId: response.requestId,
cpm: response.cpm,
currency: response.currency,
netRevenue: response.netRevenue,
width: response.width,
height: response.height,
creativeId: response.creativeId,
ttl: response.ttl,
ad: response.ad
};

bidResponses.push(bidResponse);

return bidResponses;
}
};

registerBidder(spec);
28 changes: 28 additions & 0 deletions modules/cointrafficBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Overview

```
Module Name: Cointraffic Bidder Adapter
Module Type: Cointraffic Adapter
Maintainer: tech@cointraffic.io
```

# Description
The Cointraffic client module makes it easy to implement Cointraffic directly into your website. To get started, simply replace the ``placementId`` with your assigned tracker key. This is dependent on the size required by your account dashboard. For additional information on this module, please contact us at ``support@cointraffic.io``.

# Test Parameters
```
var adUnits = [{
code: 'test-ad-div',
mediaTypes: {
banner: {
sizes: [[300, 250]],
}
},
bids: [{
bidder: 'cointraffic',
params: {
placementId: 'testPlacementId'
}
}]
}];
```
145 changes: 145 additions & 0 deletions test/spec/modules/cointrafficBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import { expect } from 'chai';
import { spec } from 'modules/cointrafficBidAdapter.js';

const ENDPOINT_URL = 'https://appspb.cointraffic.io/pb/tmp';

describe('cointrafficBidAdapter', function () {
describe('isBidRequestValid', function () {
let bid = {
bidder: 'cointraffic',
params: {
placementId: 'testPlacementId'
},
adUnitCode: 'adunit-code',
sizes: [
[300, 250]
],
bidId: 'bidId12345',
bidderRequestId: 'bidderRequestId12345',
auctionId: 'auctionId12345'
};

it('should return true where required params found', function () {
expect(spec.isBidRequestValid(bid)).to.equal(true);
});
});

describe('buildRequests', function () {
let bidRequests = [
{
bidder: 'cointraffic',
params: {
placementId: 'testPlacementId'
},
adUnitCode: 'adunit-code',
sizes: [
[300, 250]
],
bidId: 'bidId12345',
bidderRequestId: 'bidderRequestId12345',
auctionId: 'auctionId12345',
},
{
bidder: 'cointraffic',
params: {
placementId: 'testPlacementId'
},
adUnitCode: 'adunit-code2',
sizes: [
[300, 250]
],
bidId: 'bidId67890"',
bidderRequestId: 'bidderRequestId67890',
auctionId: 'auctionId12345',
}
];

let bidderRequests = {
refererInfo: {
numIframes: 0,
reachedTop: true,
referer: 'https://example.com',
stack: [
'https://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',
device: 'desktop',
sizes: ['300x250'],
bidId: 'bidId12345',
referer: 'www.example.com'
}
}
];

it('should get the correct bid response', function () {
let serverResponse = {
body: {
requestId: 'bidId12345',
cpm: 3.9,
currency: 'EUR',
netRevenue: true,
width: 300,
height: 250,
creativeId: 'creativeId12345',
ttl: 90,
ad: '<html><h3>I am an ad</h3></html> ',
}
};

let expectedResponse = [{
requestId: 'bidId12345',
cpm: 3.9,
currency: 'EUR',
netRevenue: true,
width: 300,
height: 250,
creativeId: 'creativeId12345',
ttl: 90,
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));
});

it('should get empty bid response if server response body is empty', function () {
let serverResponse = {
body: {}
};

let expectedResponse = [];

let result = spec.interpretResponse(serverResponse, bidRequest[0]);
expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse));
});

it('should get empty bid response if no server response', function () {
let serverResponse = {};

let expectedResponse = [];

let result = spec.interpretResponse(serverResponse, bidRequest[0]);
expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse));
});
});
});