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.
* send request to endpoint * tests * improve tests * Add description. Small fix * add maintainer email * restore origin package.json * add getUserSyncs function * remove userSyncs * change endpoint_url params * change test params * change netRevenue to false
- Loading branch information
Mikhail Ivanchenko
authored and
Pedro López Jiménez
committed
Mar 18, 2019
1 parent
36c2623
commit c635e7d
Showing
3 changed files
with
174 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,68 @@ | ||
import * as utils from 'src/utils'; | ||
import { registerBidder } from 'src/adapters/bidderFactory'; | ||
import { BANNER } from 'src/mediaTypes'; | ||
|
||
const BIDDER_CODE = 'adlive'; | ||
const ENDPOINT_URL = 'https://api.publishers.adlive.io/get?pbjs=1'; | ||
const CURRENCY = 'USD'; | ||
const TIME_TO_LIVE = 360; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: [BANNER], | ||
|
||
isBidRequestValid: function(bid) { | ||
return !!(bid.params.hashes && utils.isArray(bid.params.hashes)); | ||
}, | ||
|
||
buildRequests: function(validBidRequests) { | ||
let requests = []; | ||
|
||
utils._each(validBidRequests, function(bid) { | ||
requests.push({ | ||
method: 'POST', | ||
url: ENDPOINT_URL, | ||
options: { | ||
contentType: 'application/json', | ||
withCredentials: true | ||
}, | ||
data: JSON.stringify({ | ||
transaction_id: bid.bidId, | ||
hashes: utils.getBidIdParameter('hashes', bid.params) | ||
}), | ||
bidId: bid.bidId | ||
}); | ||
}); | ||
|
||
return requests; | ||
}, | ||
|
||
interpretResponse: function(serverResponse, bidRequest) { | ||
try { | ||
const response = serverResponse.body; | ||
const bidResponses = []; | ||
|
||
utils._each(response, function(bidResponse) { | ||
if (!bidResponse.is_passback) { | ||
bidResponses.push({ | ||
requestId: bidRequest.bidId, | ||
cpm: bidResponse.price, | ||
width: bidResponse.size[0], | ||
height: bidResponse.size[1], | ||
creativeId: bidResponse.hash, | ||
currency: CURRENCY, | ||
netRevenue: false, | ||
ttl: TIME_TO_LIVE, | ||
ad: bidResponse.content | ||
}); | ||
} | ||
}); | ||
|
||
return bidResponses; | ||
} catch (err) { | ||
utils.logError(err); | ||
return []; | ||
} | ||
} | ||
}; | ||
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,28 @@ | ||
# Overview | ||
``` | ||
Module Name: Adlive Bid Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: traffic@adlive.io | ||
``` | ||
|
||
# Description | ||
Module that connects to Adlive's server for bids. | ||
Currently module supports only banner mediaType. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [{ | ||
code: '/test/div', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[300, 250]] | ||
} | ||
}, | ||
bids: [{ | ||
bidder: 'adlive', | ||
params: { | ||
hashes: ['1e100887dd614b0909bf6c49ba7f69fdd1360437'] | ||
} | ||
}] | ||
}]; | ||
``` |
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,78 @@ | ||
import { expect } from 'chai'; | ||
import { spec } from 'modules/adliveBidAdapter'; | ||
|
||
describe('adliveBidAdapterTests', function() { | ||
let bidRequestData = { | ||
bids: [ | ||
{ | ||
bidId: 'transaction_1234', | ||
bidder: 'adlive', | ||
params: { | ||
hashes: ['1e100887dd614b0909bf6c49ba7f69fdd1360437'] | ||
}, | ||
sizes: [[300, 250]] | ||
} | ||
] | ||
}; | ||
let request = []; | ||
|
||
it('validate_pub_params', function() { | ||
expect( | ||
spec.isBidRequestValid({ | ||
bidder: 'adlive', | ||
params: { | ||
hashes: ['1e100887dd614b0909bf6c49ba7f69fdd1360437'] | ||
} | ||
}) | ||
).to.equal(true); | ||
}); | ||
|
||
it('validate_generated_params', function() { | ||
request = spec.buildRequests(bidRequestData.bids); | ||
let req_data = JSON.parse(request[0].data); | ||
|
||
expect(req_data.transaction_id).to.equal('transaction_1234'); | ||
}); | ||
|
||
it('validate_response_params', function() { | ||
let serverResponse = { | ||
body: [ | ||
{ | ||
hash: '1e100887dd614b0909bf6c49ba7f69fdd1360437', | ||
content: 'Ad html', | ||
price: 1.12, | ||
size: [300, 250], | ||
is_passback: 0 | ||
} | ||
] | ||
}; | ||
|
||
let bids = spec.interpretResponse(serverResponse, bidRequestData.bids[0]); | ||
expect(bids).to.have.lengthOf(1); | ||
|
||
let bid = bids[0]; | ||
|
||
expect(bid.creativeId).to.equal('1e100887dd614b0909bf6c49ba7f69fdd1360437'); | ||
expect(bid.ad).to.equal('Ad html'); | ||
expect(bid.cpm).to.equal(1.12); | ||
expect(bid.width).to.equal(300); | ||
expect(bid.height).to.equal(250); | ||
expect(bid.currency).to.equal('USD'); | ||
}); | ||
|
||
it('validate_response_params_with passback', function() { | ||
let serverResponse = { | ||
body: [ | ||
{ | ||
hash: '1e100887dd614b0909bf6c49ba7f69fdd1360437', | ||
content: 'Ad html passback', | ||
size: [300, 250], | ||
is_passback: 1 | ||
} | ||
] | ||
}; | ||
let bids = spec.interpretResponse(serverResponse); | ||
|
||
expect(bids).to.have.lengthOf(0); | ||
}); | ||
}); |