diff --git a/modules/undertoneBidAdapter.js b/modules/undertoneBidAdapter.js new file mode 100644 index 00000000000..1fe139d6fbe --- /dev/null +++ b/modules/undertoneBidAdapter.js @@ -0,0 +1,73 @@ +/** + * Adapter to send bids to Undertone + */ + +import * as utils from 'src/utils'; +import { registerBidder } from 'src/adapters/bidderFactory'; + +const BIDDER_CODE = 'undertone'; +const URL = '//hb.undertone.com/hb'; + +export const spec = { + code: BIDDER_CODE, + isBidRequestValid: function(bid) { + if (bid && bid.params && bid.params.publisherId && bid.params.placementId) { + bid.params.publisherId = parseInt(bid.params.publisherId); + return true; + } + }, + buildRequests: function(validBidRequests) { + const payload = { + 'x-ut-hb-params': [] + }; + const host = utils.getTopWindowLocation().host; + const domain = /[-\w]+\.(?:[-\w]+\.xn--[-\w]+|[-\w]{3,}|[-\w]+\.[-\w]{2})$/i.exec(host); + + const pubid = validBidRequests[0].params.publisherId; + const REQ_URL = `${URL}?pid=${pubid}&domain=${domain}`; + + validBidRequests.map(bidReq => { + const bid = { + bidRequestId: bidReq.bidId, + hbadaptor: 'prebid', + domain: domain, + placementId: bidReq.params.placementId, + publisherId: bidReq.params.publisherId, + sizes: bidReq.sizes, + params: bidReq.params + }; + payload['x-ut-hb-params'].push(bid); + }); + return { + method: 'POST', + url: REQ_URL, + withCredentials: true, + data: JSON.stringify(payload) + }; + }, + interpretResponse: function(serverResponse, request) { + const bids = []; + const body = serverResponse.body; + + if (body && Array.isArray(body) && body.length > 0) { + body.forEach((bidRes) => { + if (bidRes.ad && bidRes.cpm > 0) { + const bid = { + requestId: bidRes.bidRequestId, + cpm: bidRes.cpm, + width: bidRes.width, + height: bidRes.height, + creativeId: bidRes.adId, + currency: bidRes.currency, + netRevenue: bidRes.netRevenue, + ttl: bidRes.ttl, + ad: bidRes.ad + }; + bids.push(bid); + } + }); + } + return bids; + } +}; +registerBidder(spec); diff --git a/modules/undertoneBidAdapter.md b/modules/undertoneBidAdapter.md new file mode 100644 index 00000000000..8ac84b77bd8 --- /dev/null +++ b/modules/undertoneBidAdapter.md @@ -0,0 +1,29 @@ +# Overview + +``` +Module Name: Example Bidder Adapter +Module Type: Bidder Adapter +Maintainer: RampProgrammatic@perion.com +``` +# Description + +Module that connects to Undertone's demand sources + +# Test Parameters +``` + var adUnits = [ + { + code: 'test-div', + sizes: [[300, 250]], + bids: [ + { + bidder: "undertone", + params: { + placementId: '10433394', + publisherId: 12345 + } + } + ] + } + ]; +``` diff --git a/test/spec/modules/undertoneBidAdapter_spec.js b/test/spec/modules/undertoneBidAdapter_spec.js new file mode 100644 index 00000000000..dab9cea98bf --- /dev/null +++ b/test/spec/modules/undertoneBidAdapter_spec.js @@ -0,0 +1,140 @@ +import { expect } from 'chai'; +import { spec } from 'modules/undertoneBidAdapter'; + +const URL = '//hb.undertone.com/hb'; +const BIDDER_CODE = 'undertone'; +const validBidReq = { + bidder: BIDDER_CODE, + params: { + placementId: '10433394', + publisherId: 12345 + }, + sizes: [[300, 250], [300, 600]], + bidId: '263be71e91dd9d', + requestId: '9ad1fa8d-2297-4660-a018-b39945054746', + auctionId: '1d1a030790a475' +}; + +const invalidBidReq = { + bidder: BIDDER_CODE, + params: { + placementId: '123456789' + }, + sizes: [[300, 250], [300, 600]], + bidId: '263be71e91dd9d', + requestId: '9ad1fa8d-2297-4660-a018-b39945054746' +}; + +const bidReq = [{ + bidder: BIDDER_CODE, + params: { + placementId: '10433394', + publisherId: 12345 + }, + sizes: [[300, 250], [300, 600]], + bidId: '263be71e91dd9d', + requestId: '9ad1fa8d-2297-4660-a018-b39945054746', + auctionId: '1d1a030790a475' +}]; + +const validBidRes = { + ad: '