Skip to content

Commit

Permalink
Support send multi request (prebid#2684)
Browse files Browse the repository at this point in the history
* support multi request
  • Loading branch information
gammassp authored and StefanWallin committed Sep 28, 2018
1 parent 93cbb67 commit a69f0c9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 70 deletions.
19 changes: 9 additions & 10 deletions modules/gammaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import find from 'core-js/library/fn/array/find';

const ENDPOINT = 'hb.gammaplatform.com';
const BIDDER_CODE = 'gamma';
Expand All @@ -27,11 +26,15 @@ export const spec = {
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function(bidRequests) {
const gaxObjParams = find(bidRequests, hasParamInfo);
return {
method: 'GET',
url: '//' + ENDPOINT + '/adx/request?wid=' + gaxObjParams.params.siteId + '&zid=' + gaxObjParams.params.zoneId + '&hb=pbjs&bidid=' + gaxObjParams.bidId + '&urf=' + encodeURIComponent(utils.getTopWindowUrl())
};
const serverRequests = [];
for (var i = 0, len = bidRequests.length; i < len; i++) {
const gaxObjParams = bidRequests[i];
serverRequests.push({
method: 'GET',
url: '//' + ENDPOINT + '/adx/request?wid=' + gaxObjParams.params.siteId + '&zid=' + gaxObjParams.params.zoneId + '&hb=pbjs&bidid=' + gaxObjParams.bidId + '&urf=' + encodeURIComponent(utils.getTopWindowUrl())
});
}
return serverRequests;
},

/**
Expand Down Expand Up @@ -94,8 +97,4 @@ function newBid(serverBid) {
return bid;
}

function hasParamInfo(bid) {
return !!bid.params;
}

registerBidder(spec);
106 changes: 46 additions & 60 deletions test/spec/modules/gammaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ import { newBidder } from 'src/adapters/bidderFactory';
describe('gammaBidAdapter', function() {
const adapter = newBidder(spec);

describe('isBidRequestValid', () => {
let bid = {
'bidder': 'gamma',
'params': {
siteId: '1465446377',
zoneId: '1515999290'
},
'adUnitCode': 'adunit-code',
'sizes': [
[300, 250]
],
'bidId': '23beaa6af6cdde',
'bidderRequestId': '19c0c1efdf37e7',
'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1',
};
let bid = {
'bidder': 'gamma',
'params': {
siteId: '1465446377',
zoneId: '1515999290'
},
'adUnitCode': 'adunit-code',
'sizes': [
[300, 250]
],
'bidId': '23beaa6af6cdde',
'bidderRequestId': '19c0c1efdf37e7',
'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1',
};
let bidArray = [bid];

describe('isBidRequestValid', () => {
it('should return true when required params found', () => {
expect(spec.isBidRequestValid(bid)).to.equal(true);
});
Expand All @@ -40,56 +41,41 @@ describe('gammaBidAdapter', function() {
});

describe('buildRequests', () => {
let bidRequests = [
{
'bidder': 'gamma',
'params': {
siteId: '1465446377',
zoneId: '1515999290'
},
'adUnitCode': 'adunit-code',
'sizes': [
[300, 250]
],
'bidId': '23beaa6af6cdde',
'bidderRequestId': '19c0c1efdf37e7',
'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1'
}
];

const request = spec.buildRequests(bidRequests);

it('sends bid request to our endpoint via GET', () => {
expect(request.method).to.equal('GET');
});

it('bidRequest url', () => {
expect(request.url).to.match(new RegExp(`hb.gammaplatform.com`));
it('should attempt to send bid requests to the endpoint via GET', () => {
const requests = spec.buildRequests(bidArray);
requests.forEach(function(requestItem) {
expect(requestItem.method).to.equal('GET');
expect(requestItem.url).to.match(new RegExp(`hb.gammaplatform.com`));
});
});
});

describe('interpretResponse', () => {
let serverResponse = {
body: {
'id': '23beaa6af6cdde',
'bid': '5611802021800040585',
'type': 'banner',
'cur': 'USD',
'seatbid': [{
'seat': '5611802021800040585',
'bid': [{
'id': '1515999070',
'impid': '1',
'price': 0.45,
'adm': '<!-- Creative -->',
'adid': '1515999070',
'dealid': 'gax-paj2qarjf2g',
'h': 250,
'w': 300
let serverResponse;

beforeEach(() => {
serverResponse = {
body: {
'id': '23beaa6af6cdde',
'bid': '5611802021800040585',
'type': 'banner',
'cur': 'USD',
'seatbid': [{
'seat': '5611802021800040585',
'bid': [{
'id': '1515999070',
'impid': '1',
'price': 0.45,
'adm': '<!-- Creative -->',
'adid': '1515999070',
'dealid': 'gax-paj2qarjf2g',
'h': 250,
'w': 300
}]
}]
}]
}
};
}
};
})

it('should get the correct bid response', () => {
let expectedResponse = [{
Expand Down

0 comments on commit a69f0c9

Please sign in to comment.