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.
OwnAdX Bid Adapter : initial release (prebid#11855)
* remove changes from renderer.js library * changes done
- Loading branch information
1 parent
e2f5002
commit b0d6726
Showing
2 changed files
with
202 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,99 @@ | ||
import { parseSizesInput, isEmpty } from '../src/utils.js'; | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
import { BANNER } from '../src/mediaTypes.js' | ||
|
||
/** | ||
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest | ||
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid | ||
* @typedef {import('../src/adapters/bidderFactory.js').ServerResponse} ServerResponse | ||
*/ | ||
|
||
const BIDDER_CODE = 'ownadx'; | ||
const CUR = 'USD'; | ||
const CREATIVE_TTL = 300; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
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.tokenId && bid.params.sspId && bid.params.seatId); | ||
}, | ||
|
||
/** | ||
* Make a server request from the list of BidRequests. | ||
* | ||
* @param validBidRequests | ||
* @param bidderRequest | ||
* @return Array Info describing the request to the server. | ||
*/ | ||
buildRequests: function (validBidRequests, bidderRequest) { | ||
return validBidRequests.map(bidRequest => { | ||
const sizes = parseSizesInput(bidRequest.params.size || bidRequest.sizes); | ||
let mtype = 0; | ||
if (bidRequest.mediaTypes[BANNER]) { | ||
mtype = 1; | ||
} else { | ||
mtype = 2; | ||
} | ||
|
||
let tkn = bidRequest.params.tokenId; | ||
let seatid = bidRequest.params.seatId; | ||
let sspid = bidRequest.params.sspId; | ||
|
||
const payload = { | ||
sizes: sizes, | ||
slotBidId: bidRequest.bidId, | ||
PageUrl: bidderRequest.refererInfo.page, | ||
mediaChannel: mtype | ||
}; | ||
return { | ||
method: 'POST', | ||
url: `https://pbs-js.prebid-ownadx.com/publisher/prebid/${seatid}/${sspid}?token=${tkn}`, | ||
data: payload | ||
}; | ||
}); | ||
}, | ||
|
||
/** | ||
* 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) { | ||
const response = serverResponse.body; | ||
const bids = []; | ||
if (isEmpty(response)) { | ||
return bids; | ||
} | ||
const responseBid = { | ||
width: response.width, | ||
height: response.height, | ||
token: response.tokenId, | ||
ttl: CREATIVE_TTL, | ||
requestId: response.slotBidId, | ||
aType: response.adType || '1', | ||
cpm: response.cpm, | ||
creativeId: response.creativeId || 0, | ||
netRevenue: response.netRevenue || false, | ||
currency: response.currency || CUR, | ||
meta: { | ||
mediaType: response.mediaType || BANNER, | ||
advertiserDomains: response.advertiserDomains || [] | ||
}, | ||
ad: response.adm | ||
}; | ||
bids.push(responseBid); | ||
return bids; | ||
} | ||
|
||
}; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { expect } from 'chai'; | ||
import { spec } from 'modules/ownadxBidAdapter.js'; | ||
|
||
describe('ownadx', function () { | ||
const METHOD = 'POST'; | ||
const URL = 'https://pbs-js.prebid-ownadx.com/publisher/prebid/9/1231?token=3f2941af4f7e446f9a19ca6045f8cff4'; | ||
|
||
const bidRequest = { | ||
bidder: 'ownadx', | ||
params: { | ||
tokenId: '3f2941af4f7e446f9a19ca6045f8cff4', | ||
sspId: '1231', | ||
seatId: '9' | ||
}, | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[300, 250], [300, 600]] | ||
} | ||
}, | ||
sizes: [ | ||
[300, 250], | ||
[300, 600] | ||
], | ||
bidId: 'bid-id-123456', | ||
adUnitCode: 'ad-unit-code-1', | ||
bidderRequestId: 'bidder-request-id-123456', | ||
auctionId: 'auction-id-123456', | ||
transactionId: 'transaction-id-123456' | ||
}; | ||
|
||
describe('isBidRequestValid', function () { | ||
it('should return true where required params found', function () { | ||
expect(spec.isBidRequestValid(bidRequest)).to.equal(true); | ||
}); | ||
}); | ||
|
||
describe('buildRequests', function () { | ||
let bidderRequest = { | ||
refererInfo: { | ||
page: 'https://www.test.com', | ||
reachedTop: true, | ||
isAmp: false, | ||
numIframes: 0, | ||
stack: [ | ||
'https://www.test.com' | ||
], | ||
canonicalUrl: null | ||
} | ||
}; | ||
|
||
it('should build correct POST request for banner bid', function () { | ||
const request = spec.buildRequests([bidRequest], bidderRequest)[0]; | ||
expect(request).to.be.an('object'); | ||
expect(request.method).to.equal('POST'); | ||
expect(request.url).to.equal('https://pbs-js.prebid-ownadx.com/publisher/prebid/9/1231?token=3f2941af4f7e446f9a19ca6045f8cff4'); | ||
const payload = request.data; | ||
expect(payload).to.be.an('object'); | ||
expect(payload.sizes).to.be.an('array'); | ||
expect(payload.slotBidId).to.be.a('string'); | ||
expect(payload.PageUrl).to.be.a('string'); | ||
expect(payload.mediaChannel).to.be.a('number'); | ||
}); | ||
}); | ||
|
||
describe('interpretResponse', function () { | ||
let serverResponse = { | ||
body: { | ||
tokenId: '3f2941af4f7e446f9a19ca6045f8cff4', | ||
bid: 'BID-XXXX-XXXX', | ||
width: '300', | ||
height: '250', | ||
cpm: '0.7', | ||
adm: '<html><h1>Ad from OwnAdX</h1></html>', | ||
slotBidId: 'bid-id-123456', | ||
adType: '1', | ||
statusText: 'Success' | ||
} | ||
}; | ||
|
||
let expectedResponse = [{ | ||
token: '3f2941af4f7e446f9a19ca6045f8cff4', | ||
requestId: 'bid-id-123456', | ||
cpm: '0.7', | ||
currency: 'USD', | ||
aType: '1', | ||
netRevenue: false, | ||
width: '300', | ||
height: '250', | ||
creativeId: 0, | ||
ttl: 300, | ||
ad: '<html><h1>Ad from OwnAdX</h1></html>', | ||
meta: { | ||
mediaType: 'banner', | ||
advertiserDomains: [] | ||
} | ||
}]; | ||
|
||
it('should correctly interpret valid banner response', function () { | ||
let result = spec.interpretResponse(serverResponse); | ||
expect(result).to.deep.equal(expectedResponse); | ||
}); | ||
}); | ||
}); |