Skip to content

Commit

Permalink
Add Colombia adapter (prebid#2975)
Browse files Browse the repository at this point in the history
* Add colombia adapter

* Add https in the url

* update files

* add test cases and update md file

* remove native from package.json and update colombia test cases
  • Loading branch information
ColombiaOnline authored and ptomasroos committed Sep 25, 2018
1 parent 7e4ef67 commit a5498e1
Show file tree
Hide file tree
Showing 3 changed files with 251 additions and 0 deletions.
72 changes: 72 additions & 0 deletions modules/colombiaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import * as utils from 'src/utils';
import {config} from 'src/config';
import {registerBidder} from 'src/adapters/bidderFactory';
const BIDDER_CODE = 'colombia';
const ENDPOINT_URL = 'https://ade.clmbtech.com/cde/prebid.htm';
const HOST_NAME = document.location.protocol + '//' + window.location.host;

export const spec = {
code: BIDDER_CODE,
aliases: ['clmb'],
isBidRequestValid: function(bid) {
return !!(bid.params.placementId);
},
buildRequests: function(validBidRequests) {
return validBidRequests.map(bidRequest => {
const params = bidRequest.params;
const sizes = utils.parseSizesInput(bidRequest.sizes)[0];
const width = sizes.split('x')[0];
const height = sizes.split('x')[1];
const placementId = params.placementId;
const cb = Math.floor(Math.random() * 99999999999);
const referrer = encodeURIComponent(utils.getTopWindowUrl());
const bidId = bidRequest.bidId;
const payload = {
v: 'hb1',
p: placementId,
w: width,
h: height,
cb: cb,
r: referrer,
uid: bidId,
t: 'i',
d: HOST_NAME,
};
return {
method: 'POST',
url: ENDPOINT_URL,
data: payload,
}
});
},
interpretResponse: function(serverResponse, bidRequest) {
const bidResponses = [];
const response = serverResponse.body;
const crid = response.creativeId || 0;
const width = response.width || 0;
const height = response.height || 0;
const cpm = response.cpm || 0;
if (width !== 0 && height !== 0 && cpm !== 0 && crid !== 0) {
const dealId = response.dealid || '';
const currency = response.currency || 'USD';
const netRevenue = (response.netRevenue === undefined) ? true : response.netRevenue;
const referrer = utils.getTopWindowUrl();
const bidResponse = {
requestId: bidRequest.data.uid,
cpm: cpm,
width: response.width,
height: response.height,
creativeId: crid,
dealId: dealId,
currency: currency,
netRevenue: netRevenue,
ttl: config.getConfig('_bidderTimeout'),
referrer: referrer,
ad: response.ad
};
bidResponses.push(bidResponse);
}
return bidResponses;
}
}
registerBidder(spec);
27 changes: 27 additions & 0 deletions modules/colombiaBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Overview

```
Module Name: COLOMBIA Bidder Adapter
Module Type: Bidder Adapter
Maintainer: colombiaonline@timesinteret.in
```

# Description

Connect to COLOMBIA for bids.

THE COLOMBIA adapter requires setup and approval from the COLOMBIA team. Please reach out to your account team or colombiaonline@timesinteret.in for more information.

# Test Parameters
```
var adUnits = [{
code: 'test-ad-div',
sizes: [[300, 250]],
bids: [{
bidder: 'colombia',
params: {
placementId: '307466'
}
}]
}];
```
152 changes: 152 additions & 0 deletions test/spec/modules/colombiaBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import { expect } from 'chai';
import { spec } from 'modules/colombiaBidAdapter';
import { newBidder } from 'src/adapters/bidderFactory';

const HOST_NAME = document.location.protocol + '//' + window.location.host;
const ENDPOINT = 'https://ade.clmbtech.com/cde/prebid.htm';

describe('colombiaBidAdapter', function() {
const adapter = newBidder(spec);

describe('isBidRequestValid', function () {
let bid = {
'bidder': 'colombia',
'params': {
placementId: '307466'
},
'adUnitCode': 'adunit-code',
'sizes': [
[300, 250]
],
'bidId': '23beaa6af6cdde',
'bidderRequestId': '19c0c1efdf37e7',
'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1',
};

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

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

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

describe('buildRequests', function () {
let bidRequests = [
{
'bidder': 'colombia',
'params': {
placementId: '307466'
},
'adUnitCode': 'adunit-code1',
'sizes': [
[300, 250]
],
'bidId': '23beaa6af6cdde',
'bidderRequestId': '19c0c1efdf37e7',
'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1',
},
{
'bidder': 'colombia',
'params': {
placementId: '307466'
},
'adUnitCode': 'adunit-code2',
'sizes': [
[300, 250]
],
'bidId': '382091349b149f"',
'bidderRequestId': '"1f9c98192de251"',
'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1',
}
];

const request = spec.buildRequests(bidRequests);

it('sends bid request to our endpoint via POST', function () {
expect(request[0].method).to.equal('POST');
expect(request[1].method).to.equal('POST');
});

it('attaches source and version to endpoint URL as query params', function () {
expect(request[0].url).to.equal(ENDPOINT);
expect(request[1].url).to.equal(ENDPOINT);
});
});

describe('interpretResponse', function () {
let bidRequest = [
{
'method': 'POST',
'url': ENDPOINT,
'data': {
'v': 'hb1',
'p': '307466',
'w': '300',
'h': '250',
'cb': 12892917383,
'r': 'http%3A%2F%2Flocalhost%3A9876%2F%3Fid%3D74552836',
'uid': '23beaa6af6cdde',
't': 'i',
'd': HOST_NAME
}
}
];

let serverResponse = {
body: {
'ad': '<div>This is test case</div> ',
'cpm': 3.14,
'creativeId': '6b958110-612c-4b03-b6a9-7436c9f746dc-1sk24',
'currency': 'USD',
'statusMessage': 'Bid available',
'uid': '23beaa6af6cdde',
'width': 300,
'height': 250,
'netRevenue': true,
'ttl': 600
}
};

it('should get the correct bid response', function () {
let expectedResponse = [{
'requestId': '23beaa6af6cdde',
'cpm': 3.14,
'width': 300,
'height': 250,
'creativeId': '6b958110-612c-4b03-b6a9-7436c9f746dc-1sk24',
'dealId': '',
'currency': 'USD',
'netRevenue': true,
'ttl': 3000,
'referrer': '',
'ad': '<div>This is test case</div>'
}];
let result = spec.interpretResponse(serverResponse, bidRequest[0]);
expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse));
});

it('handles empty bid response', function () {
let response = {
body: {
'uid': '2c0b634db95a01',
'height': 0,
'crid': '',
'statusMessage': 'Bid returned empty or error response',
'width': 0,
'cpm': 0
}
};
let result = spec.interpretResponse(response, bidRequest[0]);
expect(result.length).to.equal(0);
});
});
});

0 comments on commit a5498e1

Please sign in to comment.