Skip to content

Commit

Permalink
Innity Bid Adapter: Support for Prebid.js v3 (#4633)
Browse files Browse the repository at this point in the history
* Innity Adapter for Prebid.js 1.0

* Fix Innity Adapter Test Spec Error (#2180)

* Fix utils.timestamp and remove userSyncs (#2180)

* Added Prebid.js 3.0 Support
  • Loading branch information
engtat authored and GLStephen committed Jan 9, 2020
1 parent 84d44df commit f34728b
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 2 deletions.
58 changes: 58 additions & 0 deletions modules/innityBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as utils from '../src/utils';
import { registerBidder } from '../src/adapters/bidderFactory';

const BIDDER_CODE = 'innity';
const ENDPOINT = 'https://as.innity.com/synd/';

export const spec = {
code: BIDDER_CODE,
isBidRequestValid: function(bid) {
return !!(bid.params && bid.params.pub && bid.params.zone);
},
buildRequests: function(validBidRequests, bidderRequest) {
let refererInfo = '';
if (bidderRequest && bidderRequest.refererInfo) {
refererInfo = bidderRequest.refererInfo.referer || '';
}
return validBidRequests.map(bidRequest => {
let parseSized = utils.parseSizesInput(bidRequest.sizes);
let arrSize = parseSized[0].split('x');
return {
method: 'GET',
url: ENDPOINT,
data: {
cb: utils.timestamp(),
ver: 2,
hb: 1,
output: 'js',
pub: bidRequest.params.pub,
zone: bidRequest.params.zone,
url: encodeURIComponent(refererInfo),
width: arrSize[0],
height: arrSize[1],
vpw: window.screen.width,
vph: window.screen.height,
callback: 'json',
callback_uid: bidRequest.bidId,
auction: bidRequest.auctionId,
},
};
});
},
interpretResponse: function(serverResponse, request) {
const res = serverResponse.body;
const bidResponse = {
requestId: res.callback_uid,
cpm: parseFloat(res.cpm) / 100,
width: res.width,
height: res.height,
creativeId: res.creative_id,
currency: 'USD',
netRevenue: true,
ttl: 60,
ad: '<script src="https://cdn.innity.net/frame_util.js"></script>' + res.tag,
};
return [bidResponse];
}
}
registerBidder(spec);
8 changes: 6 additions & 2 deletions modules/innityBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ Innity Bidder Adapter for Prebid.js.
# Test Parameters
```
var adUnits = [{
code: 'div-gpt-ad-1460505748561-0',
sizes: [[300, 250]],
code: '/19968336/header-bid-tag-0',
mediaTypes: {
banner: {
sizes: [[300, 250]],
}
},
bids: [{
bidder: 'innity',
params: {
Expand Down
106 changes: 106 additions & 0 deletions test/spec/modules/innityBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { expect } from 'chai';
import { spec } from 'modules/innityBidAdapter';

describe('innityAdapterTest', () => {
describe('bidRequestValidity', () => {
it('bidRequest with pub ID and zone ID param', () => {
expect(spec.isBidRequestValid({
bidder: 'innity',
params: {
'pub': 267,
'zone': 62546
},
})).to.equal(true);
});

it('bidRequest with no required params', () => {
expect(spec.isBidRequestValid({
bidder: 'innity',
params: {
},
})).to.equal(false);
});
});

describe('bidRequest', () => {
const bidRequests = [{
'bidder': 'innity',
'params': {
'pub': 267,
'zone': 62546
},
'adUnitCode': '/19968336/header-bid-tag-0',
'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec',
'sizes': [300, 250],
'bidId': '51ef8751f9aead',
'bidderRequestId': '418b37f85e772c',
'auctionId': '18fd8b8b0bd757'
}];

const bidderRequest = {
refererInfo: {
referer: 'https://example.com'
}
};

it('bidRequest HTTP method', () => {
const requests = spec.buildRequests(bidRequests, bidderRequest);
requests.forEach(function(requestItem) {
expect(requestItem.method).to.equal('GET');
});
});

it('bidRequest data', () => {
const requests = spec.buildRequests(bidRequests, bidderRequest);
expect(requests[0].data.pub).to.equal(267);
expect(requests[0].data.zone).to.equal(62546);
expect(requests[0].data.width).to.equal('300');
expect(requests[0].data.height).to.equal('250');
expect(requests[0].data.callback_uid).to.equal('51ef8751f9aead');
});
});

describe('interpretResponse', () => {
const bidRequest = {
'method': 'GET',
'url': 'https://as.innity.com/synd/?',
'data': {
'ver': 2,
'hb': 1,
'output': 'js',
'pub': 267,
'zone': 62546,
'width': '300',
'height': '250',
'callback': 'json',
'callback_uid': '51ef8751f9aead',
'url': 'https://example.com',
'cb': '',
}
};

const bidResponse = {
body: {
'cpm': 100,
'width': '300',
'height': '250',
'creative_id': '148186',
'callback_uid': '51ef8751f9aead',
'tag': '<script>innity=true;</script>',
},
headers: {}
};

it('result is correct', () => {
const result = spec.interpretResponse(bidResponse, bidRequest);
expect(result[0].requestId).to.equal('51ef8751f9aead');
expect(result[0].cpm).to.equal(1);
expect(result[0].width).to.equal('300');
expect(result[0].height).to.equal('250');
expect(result[0].creativeId).to.equal('148186');
expect(result[0].currency).to.equal('USD');
expect(result[0].ttl).to.equal(60);
expect(result[0].ad).to.equal('<script src="https://cdn.innity.net/frame_util.js"></script><script>innity=true;</script>');
});
});
});

0 comments on commit f34728b

Please sign in to comment.