forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Arteebee bidder adapter (prebid#1849)
* add arteebee adapter * set log * basic structure * basic structure * send caller as placeholder for ip and user agent * send caller as placeholder for ip and user agent * send caller as placeholder for ip and user agent * first version of adapter * add unit testing for arteebee bid adapter * fix indent * fix lint complain
- Loading branch information
1 parent
d41287a
commit 18fe42d
Showing
3 changed files
with
338 additions
and
0 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,178 @@ | ||
import * as utils from 'src/utils'; | ||
import {BANNER} from 'src/mediaTypes'; | ||
import {registerBidder} from 'src/adapters/bidderFactory'; | ||
import {config} from 'src/config'; | ||
|
||
const BIDDER_CODE = 'arteebee'; | ||
|
||
const DEFAULT_HOST = 'bidder.mamrtb.com'; | ||
|
||
const DEFAULT_SSP = 'arteebee'; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: [BANNER], | ||
isBidRequestValid: function (bidRequest) { | ||
return 'params' in bidRequest && bidRequest.params.pub !== undefined && | ||
bidRequest.params.source !== undefined; | ||
}, | ||
buildRequests: function (validBidRequests) { | ||
var requests = []; | ||
|
||
for (let i = 0; i < validBidRequests.length; i++) { | ||
let prebidReq = makePrebidRequest(validBidRequests[i]); | ||
if (prebidReq) { | ||
requests.push(prebidReq); | ||
} | ||
} | ||
|
||
return requests; | ||
}, | ||
interpretResponse: function (serverResponse, bidRequest) { | ||
var rtbResp = serverResponse.body; | ||
|
||
if ((!rtbResp) || (!rtbResp.seatbid)) { | ||
return []; | ||
} | ||
|
||
let bidResponses = []; | ||
|
||
for (let i = 0; i < rtbResp.seatbid.length; i++) { | ||
let seatbid = rtbResp.seatbid[i]; | ||
for (let j = 0; j < seatbid.bid.length; j++) { | ||
let bid = seatbid.bid[j]; | ||
let bidResponse = { | ||
requestId: bid.impid, | ||
cpm: bid.price, | ||
width: bid.w, | ||
height: bid.h, | ||
mediaType: BANNER, | ||
creativeId: bid.crid, | ||
currency: 'USD', | ||
netRevenue: true, | ||
ttl: bid.exp, | ||
ad: bid.adm | ||
}; | ||
bidResponses.push(bidResponse); | ||
} | ||
} | ||
return bidResponses; | ||
}, | ||
getUserSyncs: function (syncOptions, serverResponses) { | ||
return []; | ||
} | ||
} | ||
|
||
registerBidder(spec); | ||
|
||
function makePrebidRequest(req) { | ||
var host = req.params.host || DEFAULT_HOST; | ||
var ssp = req.params.ssp || DEFAULT_SSP; | ||
|
||
var url = window.location.protocol + '//' + host + '/rtb/bid/' + ssp + '?type=json®ister=0'; | ||
|
||
const payload = makeRtbRequest(req); | ||
const payloadString = JSON.stringify(payload); | ||
|
||
return { | ||
method: 'POST', | ||
url: url, | ||
data: payloadString | ||
}; | ||
} | ||
|
||
function makeRtbRequest(req) { | ||
var auctionId = req.requestId; | ||
|
||
var imp = []; | ||
imp.push(makeImp(req)); | ||
|
||
var rtbReq = { | ||
'id': auctionId, | ||
'imp': imp, | ||
'site': makeSite(req), | ||
'device': makeDevice(), | ||
'at': 1, | ||
'tmax': config.getConfig('bidderTimeout') | ||
}; | ||
|
||
if (req.params.coppa) { | ||
rtbReq.regs = {coppa: 1}; | ||
} | ||
|
||
if (req.params.test) { | ||
rtbReq.test = 1; | ||
} | ||
|
||
return rtbReq; | ||
} | ||
|
||
function makeImp(req) { | ||
var imp = { | ||
'id': req.bidId, | ||
'tagid': req.placementCode | ||
}; | ||
|
||
if (window.location.protocol === 'https:') { | ||
imp.secure = 1; | ||
} | ||
|
||
imp.banner = makeBanner(req); | ||
|
||
return imp; | ||
} | ||
|
||
function makeBanner(req) { | ||
var format = []; | ||
|
||
for (let i = 0; i < req.sizes.length; i++) { | ||
format.push({ | ||
w: req.sizes[i][0], | ||
h: req.sizes[i][1] | ||
}); | ||
} | ||
return { | ||
'format': format | ||
}; | ||
} | ||
|
||
function makeSite(req) { | ||
var params = req.params; | ||
|
||
var site = { | ||
'id': params.source, | ||
'page': utils.getTopWindowUrl(), | ||
'ref': utils.getTopWindowReferrer(), | ||
'publisher': makePublisher(req) | ||
}; | ||
|
||
return site; | ||
} | ||
|
||
function makePublisher(req) { | ||
var params = req.params; | ||
|
||
var publisher = { | ||
'id': params.pub, | ||
'domain': getDomain(config.getConfig('publisherDomain')) | ||
}; | ||
|
||
return publisher; | ||
} | ||
|
||
function getDomain(url) { | ||
var a = document.createElement('a'); | ||
a.href = url; | ||
|
||
return a.host; | ||
} | ||
|
||
function makeDevice() { | ||
var device = { | ||
'ua': 'caller', | ||
'ip': 'caller', | ||
'js': 1 | ||
}; | ||
|
||
return device; | ||
} |
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,32 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: Arteebee Bidder Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: jeffyecn@gmail.com | ||
``` | ||
|
||
# Description | ||
|
||
Module that connects to Arteebee's demand source | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
{ | ||
code: 'banner-ad-div', | ||
sizes: [[300, 250]], | ||
bids: [ | ||
{ | ||
bidder: 'arteebee', | ||
params: { | ||
ssp: 'mock', | ||
pub: 'prebidtest', | ||
source: 'prebidtest', | ||
test: true | ||
} | ||
} | ||
] | ||
} | ||
]; | ||
``` |
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,128 @@ | ||
import {expect} from 'chai'; | ||
import {spec} from 'modules/arteebeeBidAdapter'; | ||
|
||
describe('Arteebee adapater', () => { | ||
describe('Test validate req', () => { | ||
it('should accept minimum valid bid', () => { | ||
let bid = { | ||
bidder: 'arteebee', | ||
params: { | ||
pub: 'prebidtest', | ||
source: 'prebidtest' | ||
} | ||
}; | ||
const isValid = spec.isBidRequestValid(bid); | ||
|
||
expect(isValid).to.equal(true); | ||
}); | ||
|
||
it('should reject missing pub', () => { | ||
let bid = { | ||
bidder: 'arteebee', | ||
params: { | ||
source: 'prebidtest' | ||
} | ||
}; | ||
const isValid = spec.isBidRequestValid(bid); | ||
|
||
expect(isValid).to.equal(false); | ||
}); | ||
|
||
it('should reject missing source', () => { | ||
let bid = { | ||
bidder: 'arteebee', | ||
params: { | ||
pub: 'prebidtest' | ||
} | ||
}; | ||
const isValid = spec.isBidRequestValid(bid); | ||
|
||
expect(isValid).to.equal(false); | ||
}); | ||
}); | ||
|
||
describe('Test build request', () => { | ||
it('minimum request', () => { | ||
let bid = { | ||
bidder: 'arteebee', | ||
params: { | ||
pub: 'prebidtest', | ||
source: 'prebidtest' | ||
}, | ||
sizes: [[300, 250]] | ||
}; | ||
|
||
const req = JSON.parse(spec.buildRequests([bid])[0].data); | ||
|
||
expect(req).to.not.have.property('reg'); | ||
expect(req).to.not.have.property('test'); | ||
expect(req.imp[0]).to.not.have.property('secure'); | ||
}); | ||
|
||
it('make test request', () => { | ||
let bid = { | ||
bidder: 'arteebee', | ||
params: { | ||
pub: 'prebidtest', | ||
source: 'prebidtest', | ||
test: true | ||
}, | ||
sizes: [[300, 250]] | ||
}; | ||
|
||
const req = JSON.parse(spec.buildRequests([bid])[0].data); | ||
|
||
expect(req).to.not.have.property('reg'); | ||
expect(req).to.have.property('test', 1); | ||
expect(req.imp[0]).to.not.have.property('secure'); | ||
}); | ||
|
||
it('test coppa', () => { | ||
let bid = { | ||
bidder: 'arteebee', | ||
params: { | ||
pub: 'prebidtest', | ||
source: 'prebidtest', | ||
coppa: true | ||
}, | ||
sizes: [[300, 250]] | ||
}; | ||
|
||
const req = JSON.parse(spec.buildRequests([bid])[0].data); | ||
|
||
expect(req.regs).to.have.property('coppa', 1); | ||
expect(req).to.not.have.property('test'); | ||
expect(req.imp[0]).to.not.have.property('secure'); | ||
}); | ||
}); | ||
|
||
describe('Test interpret response', () => { | ||
it('General banner response', () => { | ||
let resp = spec.interpretResponse({ | ||
body: { | ||
id: 'abcd', | ||
seatbid: [{ | ||
bid: [{ | ||
id: 'abcd', | ||
impid: 'banner-bid', | ||
price: 0.3, | ||
adm: 'hello', | ||
crid: 'efgh', | ||
w: 300, | ||
h: 250, | ||
exp: 5 | ||
}] | ||
}] | ||
} | ||
}, null)[0]; | ||
|
||
expect(resp).to.have.property('requestId', 'banner-bid'); | ||
expect(resp).to.have.property('cpm', 0.3); | ||
expect(resp).to.have.property('width', 300); | ||
expect(resp).to.have.property('height', 250); | ||
expect(resp).to.have.property('creativeId', 'efgh'); | ||
expect(resp).to.have.property('ttl', 5); | ||
expect(resp).to.have.property('ad', 'hello'); | ||
}); | ||
}); | ||
}); |