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

add between adapter #2722

Merged
merged 3 commits into from
Aug 1, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
167 changes: 167 additions & 0 deletions modules/betweenBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import {registerBidder} from 'src/adapters/bidderFactory';

const BIDDER_CODE = 'between';

export const spec = {
code: BIDDER_CODE,
aliases: ['btw'],
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 && bid.params.w && bid.params.h && bid.params.s);
},
/**
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests[]} - an array of bids
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function(validBidRequests) {
let requests = [];
validBidRequests.forEach(i => {
let params = {
jst: 'hb',
ord: Math.random() * 10000000000000000,
tz: get_tz(),
fl: get_fl(),
rr: get_rr(),
w: i.params.w,
h: i.params.h,
s: i.params.s,
bidid: i.bidId,
transactionid: i.transactionId,
auctionid: i.auctionId
};
if (i.params.itu !== undefined) {
params.itu = i.params.itu;
}
if (i.params.cur !== undefined) {
params.cur = i.params.cur;
}
if (i.params.subid !== undefined) {
params.subid = i.params.subid;
}
if (i.params.click3rd !== undefined) {
params.click3rd = i.params.click3rd;
}
if (i.params.pubdata !== undefined) {
for (let key in i.params.pubdata) {
params['pubside_macro[' + key + ']'] = encodeURIComponent(i.params.pubdata[key]);
}
}
requests.push({method: 'GET', url: 'https://ads.betweendigital.com/adjson', data: params})
})
return requests;
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function(serverResponse, bidRequest) {
const bidResponses = [];
for (var i = 0; i < serverResponse.body.length; i++) {
let bidResponse = {
requestId: serverResponse.body[i].bidid,
cpm: serverResponse.body[i].cpm || 123,
width: serverResponse.body[i].w || 200,
height: serverResponse.body[i].h || 400,
ttl: serverResponse.body[i].ttl || 120,
creativeId: serverResponse.body[i].creativeid || 123,
currency: serverResponse.body[i].currency || 'RUB',
netRevenue: serverResponse.body[i].netRevenue || false,
ad: serverResponse.body[i].ad
};
bidResponses.push(bidResponse);
}
return bidResponses;
},

/**
* Register the user sync pixels which should be dropped after the auction.
*
* @param {SyncOptions} syncOptions Which user syncs are allowed?
* @param {ServerResponse[]} serverResponses List of server's responses.
* @return {UserSync[]} The user syncs which should be dropped.
*/
getUserSyncs: function(syncOptions, serverResponses) {
let syncs = []
/* console.log(syncOptions,serverResponses)
if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: '//acdn.adnxs.com/ib/static/usersync/v3/async_usersync.html'
});
}
if (syncOptions.pixelEnabled && serverResponses.length > 0) {
syncs.push({
type: 'image',
url: serverResponses[0].body.userSync.url
});
} */

syncs.push({
type: 'iframe',
url: '//acdn.adnxs.com/ib/static/usersync/v3/async_usersync.html'
})
return syncs;
}
}

function get_rr() {
try {
var td = top.document;
var rr = td.referrer;
} catch (err) { return false }

if (typeof rr != 'undefined' && rr.length > 0) {
return encodeURIComponent(rr);
} else if (typeof rr != 'undefined' && rr == '') {
return 'direct';
}
}

function get_fl() {
if (navigator.plugins !== undefined && navigator.plugins !== null) {
if (navigator.plugins['Shockwave Flash'] !== undefined && navigator.plugins['Shockwave Flash'] !== null && typeof navigator.plugins['Shockwave Flash'] === 'object') {
var description = navigator.plugins['Shockwave Flash'].description;
if (description && !(navigator.mimeTypes !== undefined && navigator.mimeTypes['application/x-shockwave-flash'] && !navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin)) {
description = description.replace(/^.*\s+(\S+\s+\S+$)/, '$1').replace(/^(.*)\..*$/, '$1');

return parseInt(description, 10);
}
}
}

return 0;
}

function get_tz() {
return new Date().getTimezoneOffset();
}

/*
function get_pubdata(adds) {
if (adds !== undefined && adds.pubdata !== undefined) {
let index = 0;
let url = '';
for(var key in adds.pubdata) {
if (index == 0) {
url = url + encodeURIComponent('pubside_macro[' + key + ']') + '=' + encodeURIComponent(adds.pubdata[key]);
index++;
} else {
url = url + '&' + encodeURIComponent('pubside_macro[' + key + ']') + '=' + encodeURIComponent(adds.pubdata[key]);
}
}
return url;
}
}
*/

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

Module Name: Example Bidder Adapter
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please update the template and add actual contact info.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Module Type: Bidder Adapter
Maintainer: prebid@example.com

# Description

Module that connects to Example's demand sources

# Test Parameters
```
var adUnits = [
{
code: 'test-div',
bids: [
{
bidder: "between",
params: {
placementId: '12345',
Copy link
Collaborator

Choose a reason for hiding this comment

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

is 12345 an actual bid parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, its test parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated pull req and i did pull req in prebid.io

w: 200,
h: 400,
s: 111
}
}
]
}
];
```
48 changes: 48 additions & 0 deletions test/spec/modules/betweenBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { expect } from 'chai';
import { spec } from 'modules/betweenBidAdapter';

describe('betweenBidAdapterTests', () => {
it('validate_pub_params', () => {
expect(spec.isBidRequestValid({
bidder: 'between',
params: {
placementId: 'example',
w: 240,
h: 400,
s: 1112
}
})).to.equal(true);
});
it('validate_generated_params', () => {
let bidRequestData = [{
bidId: 'bid1234',
bidder: 'between',
params: {w: 240, h: 400, s: 1112, placementId: 'example'},
sizes: [[240, 400]]
}]
let request = spec.buildRequests(bidRequestData);
let req_data = request[0].data;
expect(req_data.bidid).to.equal('bid1234');
});
it('validate_response_params', () => {
let serverResponse = {
body: [{
bidid: 'bid1234',
cpm: 1.12,
w: 240,
h: 400,
currency: 'USD',
ad: 'Ad html'
}]
};
let bids = spec.interpretResponse(serverResponse);
expect(bids).to.have.lengthOf(1);
let bid = bids[0];
expect(bid.cpm).to.equal(1.12);
expect(bid.currency).to.equal('USD');
expect(bid.width).to.equal(240);
expect(bid.height).to.equal(400);
expect(bid.requestId).to.equal('bid1234');
expect(bid.ad).to.equal('Ad html');
});
});