Skip to content

Commit

Permalink
Gjirafa Bidder Adapter (prebid#1944)
Browse files Browse the repository at this point in the history
* Added Gjirafa adapter

* Add gjirafa adapter unit test

* adapter update

* New line

* Requested changes

* change hello_world.html to one bid

* change hello_world.html to one bid

* Dropping changes in gitignore and hello_world example

* hello_world changes

* Drop hello_world and gitignore
  • Loading branch information
agon-qurdina authored and Justas Pupelis committed Jan 10, 2018
1 parent 15e5f5c commit cf3bf61
Show file tree
Hide file tree
Showing 3 changed files with 283 additions and 0 deletions.
91 changes: 91 additions & 0 deletions modules/gjirafaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import * as utils from 'src/utils';
import {registerBidder} from 'src/adapters/bidderFactory';

const BIDDER_CODE = 'gjirafa';
const ENDPOINT_URL = 'https://gjc.gjirafa.com/Home/GetBid';
const DIMENSION_SEPARATOR = 'x';
const SIZE_SEPARATOR = ';';

export const spec = {
code: BIDDER_CODE,
/**
* 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 && (!!bid.params.placementId || (!!bid.params.minCPM && !!bid.params.minCPC));
},
/**
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests[]} - an array of bids
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function(validBidRequests, bidderRequest) {
return validBidRequests.map(bidRequest => {
let gjid = Math.floor(Math.random() * 99999999);
let sizes = generateSizeParam(bidRequest.sizes);
let configId = bidRequest.params.placementId || '';
let minCPM = bidRequest.params.minCPM || 0.0;
let minCPC = bidRequest.params.minCPC || 0.0;
let allowExplicit = bidRequest.params.explicit || 0;
const body = {
gjid: gjid,
sizes: sizes,
configId: configId,
minCPM: minCPM,
minCPC: minCPC,
allowExplicit: allowExplicit,
referrer: utils.getTopWindowUrl(),
requestid: bidRequest.bidderRequestId,
bidid: bidRequest.bidId
};
if (document.referrer) {
body.referrer = document.referrer;
}
return {
method: 'GET',
url: ENDPOINT_URL,
data: body
};
});
},
/**
* 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, bidRequest) {
const serverBody = serverResponse.body;
const bidResponses = [];
const bidResponse = {
requestId: bidRequest.data.bidid,
cpm: serverBody.CPM,
width: serverBody.Width,
height: serverBody.Height,
creativeId: serverBody.CreativeId,
currency: serverBody.Currency,
netRevenue: serverBody.NetRevenue,
ttl: serverBody.TTL,
referrer: serverBody.Referrer,
ad: serverBody.Ad
};
bidResponses.push(bidResponse);
return bidResponses;
}
}

/**
* Generate size param for bid request using sizes array
*
* @param {Array} sizes Possible sizes for the ad unit.
* @return {string} Processed sizes param to be used for the bid request.
*/
function generateSizeParam(sizes) {
return sizes.map(size => size.join(DIMENSION_SEPARATOR)).join(SIZE_SEPARATOR);
}

registerBidder(spec);
36 changes: 36 additions & 0 deletions modules/gjirafaBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Overview
Module Name: Gjirafa Bidder Adapter Module
Type: Bidder Adapter
Maintainer: agonq@gjirafa.com

# Description
Gjirafa Bidder Adapter for Prebid.js.

# Test Parameters
var adUnits = [
{
code: 'test-div',
sizes: [[728, 90]], // leaderboard
bids: [
{
bidder: 'gjirafa',
params: {
placementId: '71-3'
}
}
]
},{
code: 'test-div',
sizes: [[300, 250]], // mobile rectangle
bids: [
{
bidder: 'gjirafa',
params: {
minCPM: 0.0001,
minCPC: 0.001,
explicit: true
}
}
]
}
];
156 changes: 156 additions & 0 deletions test/spec/modules/gjirafaBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import { expect } from 'chai';
import { spec } from 'modules/gjirafaBidAdapter';

describe('gjirafaAdapterTest', () => {
describe('bidRequestValidity', () => {
it('bidRequest with placementId, minCPM and minCPC params', () => {
expect(spec.isBidRequestValid({
bidder: 'gjirafa',
params: {
placementId: 'test-div',
minCPM: 0.0001,
minCPC: 0.001
}
})).to.equal(true);
});

it('bidRequest with only placementId param', () => {
expect(spec.isBidRequestValid({
bidder: 'gjirafa',
params: {
placementId: 'test-div'
}
})).to.equal(true);
});

it('bidRequest with minCPM and minCPC params', () => {
expect(spec.isBidRequestValid({
bidder: 'gjirafa',
params: {
minCPM: 0.0001,
minCPC: 0.001
}
})).to.equal(true);
});

it('bidRequest with no placementId, minCPM or minCPC params', () => {
expect(spec.isBidRequestValid({
bidder: 'gjirafa',
params: {
}
})).to.equal(false);
});
});

describe('bidRequest', () => {
const bidRequests = [{
'bidder': 'gjirafa',
'params': {
'placementId': '71-3'
},
'adUnitCode': 'hb-leaderboard',
'transactionId': 'b6b889bb-776c-48fd-bc7b-d11a1cf0425e',
'sizes': [[728, 90], [980, 200], [980, 150], [970, 90], [970, 250]],
'bidId': '10bdc36fe0b48c8',
'bidderRequestId': '70deaff71c281d',
'auctionId': 'f9012acc-b6b7-4748-9098-97252914f9dc'
},
{
'bidder': 'gjirafa',
'params': {
'minCPM': 0.0001,
'minCPC': 0.001,
'explicit': true
},
'adUnitCode': 'hb-inarticle',
'transactionId': '8757194d-ea7e-4c06-abc0-cfe92bfc5295',
'sizes': [[300, 250]],
'bidId': '81a6dcb65e2bd9',
'bidderRequestId': '70deaff71c281d',
'auctionId': 'f9012acc-b6b7-4748-9098-97252914f9dc'
}];

it('bidRequest HTTP method', () => {
const requests = spec.buildRequests(bidRequests);
requests.forEach(function(requestItem) {
expect(requestItem.method).to.equal('GET');
});
});

it('bidRequest url', () => {
const endpointUrl = 'https://gjc.gjirafa.com/Home/GetBid';
const requests = spec.buildRequests(bidRequests);
requests.forEach(function(requestItem) {
expect(requestItem.url).to.match(new RegExp(`${endpointUrl}`));
});
});

it('bidRequest data', () => {
const requests = spec.buildRequests(bidRequests);
requests.forEach(function(requestItem) {
expect(requestItem.data).to.exists;
});
});

it('bidRequest sizes', () => {
const requests = spec.buildRequests(bidRequests);
expect(requests[0].data.sizes).to.equal('728x90;980x200;980x150;970x90;970x250');
expect(requests[1].data.sizes).to.equal('300x250');
});
});

describe('interpretResponse', () => {
const bidRequest = {
'method': 'GET',
'url': 'https://gjc.gjirafa.com/Home/GetBid',
'data': {
'gjid': 2323007,
'sizes': '728x90;980x200;980x150;970x90;970x250',
'configId': '71-3',
'minCPM': 0,
'minCPC': 0,
'allowExplicit': 0,
'referrer': 'http://localhost:9999/integrationExamples/gpt/hello_world.html?pbjs_debug=true',
'requestid': '26ee8fe87940da7',
'bidid': '2962dbedc4768bf'
}
};

const bidResponse = {
body: [{
'CPM': 1,
'Width': 728,
'Height': 90,
'Referrer': 'https://example.com/',
'Ad': 'test ad',
'CreativeId': '123abc',
'NetRevenue': false,
'Currency': 'EUR',
'TTL': 360
}],
headers: {}
};

it('all keys present', () => {
const result = spec.interpretResponse(bidResponse, bidRequest);

let keys = [
'requestId',
'cpm',
'width',
'height',
'creativeId',
'currency',
'netRevenue',
'ttl',
'referrer',
'ad'
];

let resultKeys = Object.keys(result[0]);
resultKeys.forEach(function(key) {
expect(keys.indexOf(key) !== -1).to.equal(true);
});
})
});
});

0 comments on commit cf3bf61

Please sign in to comment.