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

Adlive bid adapter #3109

Merged
merged 11 commits into from
Oct 19, 2018
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
68 changes: 68 additions & 0 deletions modules/adliveBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import { BANNER } from 'src/mediaTypes';

const BIDDER_CODE = 'adlive';
const ENDPOINT_URL = 'https://api.publishers.adlive.io/get?pbjs=1';
const CURRENCY = 'USD';
const TIME_TO_LIVE = 360;

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

isBidRequestValid: function(bid) {
return !!(bid.params.hashes && utils.isArray(bid.params.hashes));
},

buildRequests: function(validBidRequests) {
let requests = [];

utils._each(validBidRequests, function(bid) {
requests.push({
method: 'POST',
url: ENDPOINT_URL,
options: {
contentType: 'application/json',
withCredentials: true
},
data: JSON.stringify({
transaction_id: bid.bidId,
hashes: utils.getBidIdParameter('hashes', bid.params)
}),
bidId: bid.bidId
});
});

return requests;
},

interpretResponse: function(serverResponse, bidRequest) {
try {
const response = serverResponse.body;
const bidResponses = [];

utils._each(response, function(bidResponse) {
if (!bidResponse.is_passback) {
bidResponses.push({
requestId: bidRequest.bidId,
cpm: bidResponse.price,
width: bidResponse.size[0],
height: bidResponse.size[1],
creativeId: bidResponse.hash,
currency: CURRENCY,
netRevenue: false,
ttl: TIME_TO_LIVE,
ad: bidResponse.content
});
}
});

return bidResponses;
} catch (err) {
utils.logError(err);
return [];
}
}
};
registerBidder(spec);
28 changes: 28 additions & 0 deletions modules/adliveBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Overview
```
Module Name: Adlive Bid Adapter
Module Type: Bidder Adapter
Maintainer: traffic@adlive.io
```

# Description
Module that connects to Adlive's server for bids.
Currently module supports only banner mediaType.

# Test Parameters
```
var adUnits = [{
code: '/test/div',
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
bids: [{
bidder: 'adlive',
params: {
hashes: ['1e100887dd614b0909bf6c49ba7f69fdd1360437']
}
}]
}];
```
78 changes: 78 additions & 0 deletions test/spec/modules/adliveBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { expect } from 'chai';
import { spec } from 'modules/adliveBidAdapter';

describe('adliveBidAdapterTests', function() {
let bidRequestData = {
bids: [
{
bidId: 'transaction_1234',
bidder: 'adlive',
params: {
hashes: ['1e100887dd614b0909bf6c49ba7f69fdd1360437']
},
sizes: [[300, 250]]
}
]
};
let request = [];

it('validate_pub_params', function() {
expect(
spec.isBidRequestValid({
bidder: 'adlive',
params: {
hashes: ['1e100887dd614b0909bf6c49ba7f69fdd1360437']
}
})
).to.equal(true);
});

it('validate_generated_params', function() {
request = spec.buildRequests(bidRequestData.bids);
let req_data = JSON.parse(request[0].data);

expect(req_data.transaction_id).to.equal('transaction_1234');
});

it('validate_response_params', function() {
let serverResponse = {
body: [
{
hash: '1e100887dd614b0909bf6c49ba7f69fdd1360437',
content: 'Ad html',
price: 1.12,
size: [300, 250],
is_passback: 0
}
]
};

let bids = spec.interpretResponse(serverResponse, bidRequestData.bids[0]);
expect(bids).to.have.lengthOf(1);

let bid = bids[0];

expect(bid.creativeId).to.equal('1e100887dd614b0909bf6c49ba7f69fdd1360437');
expect(bid.ad).to.equal('Ad html');
expect(bid.cpm).to.equal(1.12);
expect(bid.width).to.equal(300);
expect(bid.height).to.equal(250);
expect(bid.currency).to.equal('USD');
});

it('validate_response_params_with passback', function() {
let serverResponse = {
body: [
{
hash: '1e100887dd614b0909bf6c49ba7f69fdd1360437',
content: 'Ad html passback',
size: [300, 250],
is_passback: 1
}
]
};
let bids = spec.interpretResponse(serverResponse);

expect(bids).to.have.lengthOf(0);
});
});