forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Innity Bid Adapter: Support for Prebid.js v3 (prebid#4633)
* Innity Adapter for Prebid.js 1.0 * Fix Innity Adapter Test Spec Error (prebid#2180) * Fix utils.timestamp and remove userSyncs (prebid#2180) * Added Prebid.js 3.0 Support
- Loading branch information
Showing
3 changed files
with
170 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>'); | ||
}); | ||
}); | ||
}); |