Skip to content

Commit

Permalink
Add adapter for GAMMA SSP (#2092)
Browse files Browse the repository at this point in the history
* commit gamma adapter

* Fixed The Travis CI build failed

* fix interpretResponse return empty when server response empty

* removed mediaType

removed mediaType in bid 
and return vastXml property if video request

* fixed Travis CI build

* Travis CI build

* add gamma spec

* fixed Travis CI build

* fix spec

* fix spec

* Add files via upload

* Add files via upload

* fix spec

* fix Travis CI build

* move to module

* remove gaxDomain param and move to adapter

* remove check isBidRequestValid for gaxDomain

* remove gaxDomain param

* remove gaxDomain param

* remove gaxDomain param

* Delete gammaBidAdapter_spec.js
  • Loading branch information
gammassp authored and jsnellbaker committed Feb 12, 2018
1 parent c31cc52 commit a2741f0
Show file tree
Hide file tree
Showing 3 changed files with 276 additions and 0 deletions.
90 changes: 90 additions & 0 deletions modules/gammaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
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';

export const spec = {
code: BIDDER_CODE,
aliases: ['gamma'],

/**
* Determines whether or not the given bid request is valid.
*
* @param {object} bid The bid to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function(bid) {
return !!(bid.params.siteId || bid.params.zoneId);
},

/**
* Make a server request from the list of BidRequests.
*
* @param {BidRequest[]} bidRequests A non-empty list of bid requests which should be sent to the Server.
* @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=' + utils.getTopWindowUrl()
};
},

/**
* Unpack the response from the server into a list of bids.
*
* @param {*} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function(serverResponse) {
serverResponse = serverResponse.body;

const bids = [];

if (serverResponse.id) {
const bid = newBid(serverResponse);
bids.push(bid);
}

return bids;
}
}

/**
* Unpack the Server's Bid into a Prebid-compatible one.
* @param serverBid
* @return Bid
*/
function newBid(serverBid) {
const bid = {
ad: serverBid.seatbid[0].bid[0].adm,
cpm: serverBid.seatbid[0].bid[0].price,
creativeId: serverBid.seatbid[0].bid[0].adid,
currency: serverBid.cur,
dealId: serverBid.seatbid[0].bid[0].dealid,
width: serverBid.seatbid[0].bid[0].w,
height: serverBid.seatbid[0].bid[0].h,
mediaType: serverBid.type,
netRevenue: true,
requestId: serverBid.id,
ttl: serverBid.seatbid[0].bid[0].ttl || 300
};

if (serverBid.type == 'video') {
Object.assign(bid, {
vastXml: serverBid.seatbid[0].bid[0].vastXml,
ttl: 3600
});
}

return bid;
}

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

registerBidder(spec);
67 changes: 67 additions & 0 deletions modules/gammaBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Overview

```
Module Name: Gamma Bid Adapter
Module Type: Bidder Adapter
Maintainer: [email protected]
```

# Description

Connects to Gamma exchange for bids.

Gamma bid adapter supports Banner, Video.

# Test Parameters
```
var adUnits = [{
code: 'gamma-hb-ad-123456-0',
sizes: [[300, 250]],
// Replace this object to test a new Adapter!
bids: [{
bidder: 'gamma',
params: {
siteId: '1465446377',
zoneId: '1515999290'
}
}]
}];
```
# Ad Unit and Setup: For Testing
In order to receive bids please map localhost to (any) test domain.

```
<--! Prebid Config section >
<script>
var PREBID_TIMEOUT = 3000;
var adUnits = [{
code: 'gamma-hb-ad-123456-0',
sizes: [[300, 250]],
bids: [{
bidder: 'gamma',
params: {
siteId: '1465446377',
zoneId: '1515999290'
}
}]
}];
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
// Adjust bid CPM to ensure it wins the auction (USED ONLY FOR TESTING). Need to do this since test bids have too low a CPM
pbjs.bidderSettings = {
'gamma': {
bidCpmAdjustment : function(bidCpm, bid){
// adjust the bid in real time before the auction takes place, only do so for valid bids ignore no bids
if (bid.w !== 0 && bid.h !== 0 && bidCpm !== 0) {
return bidCpm + 0.50;
}
}
}
};
</script>
<!-- End Prebid Config section>
```
119 changes: 119 additions & 0 deletions test/spec/modules/gammaBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import * as utils from 'src/utils';
import { expect } from 'chai';
import { spec } from 'modules/gammaBidAdapter';
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',
};

it('should return true when required params found', () => {
expect(spec.isBidRequestValid(bid)).to.equal(true);
});

it('should return false when require params are not passed', () => {
let bid = Object.assign({}, bid);
bid.params = {};
expect(spec.isBidRequestValid(bid)).to.equal(false);
});

it('should return false when params not passed correctly', () => {
bid.params.siteId = '';
bid.params.zoneId = '';
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
});

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`));
});
});

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
}]
}]
}
};

it('should get the correct bid response', () => {
let expectedResponse = [{
'requestId': '23beaa6af6cdde',
'cpm': 0.45,
'width': 300,
'height': 250,
'creativeId': '1515999070',
'dealId': 'gax-paj2qarjf2g',
'currency': 'USD',
'netRevenue': true,
'ttl': 300,
'ad': '<!-- adtag -->'
}];
let result = spec.interpretResponse(serverResponse);
expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse));
});

it('handles empty bid response', () => {
let response = {
body: {}
};
let result = spec.interpretResponse(response);
expect(result.length).to.equal(0);
});
});
});

0 comments on commit a2741f0

Please sign in to comment.