Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vi bid adapter #2020

Merged
merged 12 commits into from
Jan 22, 2018
69 changes: 69 additions & 0 deletions modules/viBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import { BANNER } from 'src/mediaTypes';

const BIDDER_CODE = 'vi';
const SUPPORTED_MEDIA_TYPES = [BANNER];

function isBidRequestValid(bid) {
return !!(bid.params.pubId);
}

function buildRequests(bidReqs) {
let imps = [];
utils._each(bidReqs, function (bid) {
imps.push({
id: bid.bidId,
sizes: bid.sizes,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ad unit sizes may be defined as a double array ([[320, 480]]) or single array ([320, 480]). In the case of single sizes, your endpoint is erroring out with 400 (Invalid JSON: Cannot deserialize instance of int[] out of VALUE_NUMBER_INT, but utils.parseSizesInput can help. Something like

utils.parseSizesInput(bid.sizes).map(size => size.split('x'))

though feel free handle it however you'd like

bidFloor: parseFloat(bid.params.bidFloor) > 0 ? bid.params.bidFloor : 0
});
});

const bidRequest = {
id: bidReqs[0].requestId,
imps: imps,
publisherId: utils.getBidIdParameter('pubId', bidReqs[0].params),
siteId: utils.getBidIdParameter('siteId', bidReqs[0].params),
cat: utils.getBidIdParameter('cat', bidReqs[0].params),
language: utils.getBidIdParameter('lang', bidReqs[0].params),
domain: utils.getTopWindowLocation().hostname,
page: utils.getTopWindowUrl(),
referrer: utils.getTopWindowReferrer()
};
return {
method: 'POST',
url: `//pb.vi-serve.com/prebid/bid`,
data: JSON.stringify(bidRequest),
options: {contentType: 'application/json', withCredentials: false}
};
}

function interpretResponse(bids) {
let responses = [];
utils._each(bids.body, function(bid) {
responses.push({
requestId: bid.id,
cpm: parseFloat(bid.price),
width: parseInt(bid.width),
height: parseInt(bid.height),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A radix (likely, 10) should be specified as the second argument to the above two parseInts to guarantee predictable behavior

creativeId: bid.creativeId,
dealId: bid.dealId || null,
currency: 'USD',
netRevenue: true,
mediaType: BANNER,
ad: decodeURIComponent(`${bid.ad}`),
ttl: 60000
});
});
return responses;
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: SUPPORTED_MEDIA_TYPES,
isBidRequestValid,
buildRequests,
interpretResponse
}

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

```
Module Name: vi bid adapter
Module Type: Bidder adapter
Maintainer: [email protected]
```

# Description

The video intelligence (vi) adapter integration to the Prebid library.
Connects to vi’s demand sources.
There should be only one ad unit with vi bid adapter on each single page.

# Test Parameters

```
var adUnits = [{
code: 'div-0',
sizes: [[320, 480]],
bids: [{
bidder: 'vi',
params: {
pubId: 'sb_test',
lang: 'en-US',
cat: 'IAB1',
bidFloor: 0.05 //optional
}
}]
}];
```

# Parameters

| Name | Scope | Description | Example |
| :------------ | :------- | :---------------------------------------------- | :--------------------------------- |
| `pubId` | required | Publisher ID, provided by vi | 'sb_test' |
| `lang` | required | Ad language, in ISO 639-1 language code format | 'en-US', 'es-ES', 'de' |
| `cat` | required | Ad IAB category (top-level or subcategory), single one supported | 'IAB1', 'IAB9-1' |
| `bidFloor` | optional | Lowest value of expected bid price | 0.001 |

111 changes: 111 additions & 0 deletions test/spec/modules/viBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { expect } from 'chai';
import { spec } from 'modules/viBidAdapter';
import { newBidder } from 'src/adapters/bidderFactory';
import { REPO_AND_VERSION } from 'src/constants';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import isn't used in the test, line can be dropped


const ENDPOINT = `//pb.vi-serve.com/prebid/bid`;

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

describe('isBidRequestValid', () => {
let bid = {
'bidder': 'vi',
'params': {
'pubId': 'sb_test',
'lang': 'en-US',
'cat': 'IAB1',
'bidFloor': 0.05
},
'adUnitCode': 'adunit-code',
'sizes': [
[320, 480]
],
'bidId': '29b891ad542377',
'bidderRequestId': '1dc9a08206a57b',
'requestId': '24176695-e3f0-44db-815b-ed97cf5ad49b',
'placementCode': 'div-gpt-ad-1460505748561-0',
'transactionId': '474da635-9cf0-4188-a3d9-58961be8f905'
};

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

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

describe('buildRequests', () => {
let bidRequests = [{
'bidder': 'vi',
'params': {
'pubId': 'sb_test',
'lang': 'en-US',
'cat': 'IAB1',
'bidFloor': 0.05
},
'adUnitCode': 'adunit-code',
'sizes': [
[320, 480]
],
'bidId': '29b891ad542377',
'bidderRequestId': '1dc9a08206a57b',
'requestId': '24176695-e3f0-44db-815b-ed97cf5ad49b',
'placementCode': 'div-gpt-ad-1460505748561-0',
'transactionId': '474da635-9cf0-4188-a3d9-58961be8f905'
}];

const request = spec.buildRequests(bidRequests);

it('POST bid request to vi', () => {
expect(request.method).to.equal('POST');
});

it('check endpoint URL', () => {
expect(request.url).to.equal(ENDPOINT)
});
});

describe('interpretResponse', () => {
let response = {
body: [{
'id': '29b891ad542377',
'price': 0.1,
'width': 320,
'height': 480,
'ad': '<!-- Real ad markup -->',
'creativeId': 'dZsPGv'
}]
};

it('should get the correct bid response', () => {
let expectedResponse = [{
'requestId': '29b891ad542377',
'cpm': 0.1,
'width': 320,
'height': 480,
'creativeId': 'dZsPGv',
'dealId': null,
'currency': 'USD',
'netRevenue': true,
'mediaType': 'banner',
'ad': decodeURIComponent(`<!-- Creative -->`),
'ttl': 60000
}];

let result = spec.interpretResponse(response);
expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0]));
});

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