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 7 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
71 changes: 71 additions & 0 deletions modules/adliveBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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';
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)
}),
bid
});
});

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: true,
ttl: TIME_TO_LIVE,
ad: bidResponse.content
});
}
});

return bidResponses;
} catch (err) {
utils.logError(err);
return [];
}
},

getUserSyncs: function (syncOptions, serverResponses, gdprConsent) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't have any userSync pixels you want to fire, you can just remove the entire getUserSyncs property from your adapter. It's not required to define it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I do not define this function, tests do not pass.

Copy link
Collaborator

@jsnellbaker jsnellbaker Oct 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify what tests do not pass? I disabled that part of your adapter code in the branch copy I checked out and rangulp test. There were no unit test errors from what I saw.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsnellbaker
I mean circleci tests.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mifanich I ran the browserstack tests (which is what circleci runs for us automatically) locally with the getUserSyncs code disabled and I didn't see any test failures.

It's possible there was some other issue that happened in the circleci tests you saw that failed that were unrelated to your adapter's code. Can you try to make the change again and push it in this PR so we can retest it?

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']
}
}]
}];
```
77 changes: 77 additions & 0 deletions test/spec/modules/adliveBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { expect } from 'chai';
import { spec } from 'modules/adliveBidAdapter';

describe('adliveBidAdapterTests', function() {
let bidRequestData = [
{
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);
let req_data = request[0];
req_data.data = JSON.parse(req_data.data);

expect(req_data.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[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);
});
});