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

Vrtcal Markets Inc. Bid Adapter Addition #4259

Merged
merged 3 commits into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions modules/vrtcalBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import {registerBidder} from '../src/adapters/bidderFactory';
import { BANNER } from '../src/mediaTypes';
import {ajax} from '../src/ajax';

export const spec = {
code: 'vrtcal',
supportedMediaTypes: [BANNER],
isBidRequestValid: function (bid) {
return true;// No extras params required
},
buildRequests: function (bidRequests) {
const requests = bidRequests.map(function (bid) {
const params = {

prebidJS: 1,
prebidAdUnitCode: bid.adUnitCode,
id: bid.bidId,
imp: [{
id: '1',
banner: {
w: bid.sizes[0][0],
h: bid.sizes[0][1],
Copy link
Collaborator

Choose a reason for hiding this comment

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

May want to look at the mediaTypes.banner.sizes field instead of the bid.sizes field, as that generic field may be deprecated in the future.

},
bidfloor: 0.75
}],
site: {
id: 'VRTCAL_FILLED',
name: 'VRTCAL_FILLED',
cat: ['VRTCAL_FILLED'],
domain: decodeURIComponent(window.location.href).replace('https://', '').replace('http://', '').split('/')[0]

},
device: {
ua: 'VRTCAL_FILLED',
ip: 'VRTCAL_FILLED'
}
};

return {method: 'POST', url: 'https://rtb.vrtcal.com/bidder_prebid.vap?ssp=1804', data: JSON.stringify(params), options: {withCredentials: false, crossOrigin: true}}
});

return requests;
},
interpretResponse: function (serverResponse, bidRequest) {
if (!serverResponse || !serverResponse.body) {
return [];
}

const bidResponses = [];

var response = serverResponse.body;

if (response) {
const bidResponse = {
requestId: response.id,
cpm: response.seatbid[0].bid[0].price,
width: response.seatbid[0].bid[0].w,
height: response.seatbid[0].bid[0].h,
creativeId: response.seatbid[0].bid[0].crid,
currency: 'USD',
netRevenue: true,
ttl: 900,
ad: response.seatbid[0].bid[0].adm,
nurl: response.seatbid[0].bid[0].nurl
};

bidResponses.push(bidResponse);
}
return bidResponses;
},
getUserSyncs: function(syncOptions, serverResponses) {
return [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can remove this function if you're not going to be doing any usersyncing.

},
onBidWon: function(bid) {
if (!bid.nurl) { return; }
const winUrl = bid.nurl.replace(
/\$\{AUCTION_PRICE\}/,
bid.cpm
);
ajax(winUrl, null);
}
};

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

Module Name: Vrtcal Bidder Adapter
Module Type: Bidder Adapter
Maintainer: [email protected]

# Description

You can use this adapter to get a bid from vrtcal.com.


# Test Parameters
```
var adUnits = [
{
code: "vrtcal-test-adunit",
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
bids: [
{
bidder: "vrtcal"
}
]
}
];
```
#Vrtcal requires no extra params passed, thus no params struct included
81 changes: 81 additions & 0 deletions test/spec/modules/vrtcalBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { expect } from 'chai'
import { spec } from 'modules/vrtcalBidAdapter'
import { newBidder } from 'src/adapters/bidderFactory'

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

let bidRequest = {
bidId: 'bidID0001',
transactionId: 'transID0001',
sizes: [[ 300, 250 ]]
}

describe('isBidRequestValid', function () {
it('should return true 100% of time as no special additional params are required, thus no additional validation needed', function () {
expect(spec.isBidRequestValid(bidRequest)).to.be.true
})
})

describe('buildRequests', function () {
let bidRequests = [
{
'bidder': 'vrtcal',
'adUnitCode': 'adunit0001',
'sizes': [[300, 250]],
'bidId': 'bidID0001',
'bidderRequestId': 'br0001',
'auctionId': 'auction0001',
}
];

const request = spec.buildRequests(bidRequests);

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

it('adUnitCode should be sent as prebidAdUnitCode parameters on any requests', function () {
expect(request[0].data).to.match(/"prebidAdUnitCode":"adunit0001"/);
});
});

describe('interpretResponse', function () {
it('should form compliant bid object response', function () {
let res = {
body: {
id: 'bidID0001',
seatbid: [{
bid: [{
id: 'VRTB_240d3c8a3c12b68_1',
impid: '1',
price: 0.7554,
adm: 'TEST AD',
nurl: 'https://exchange.vrtcal.com/wintracker',
w: 300,
h: 250,
crid: 'v2_1064_vrt_vrtcaltestdisplay2_300_250',
adomain: ['vrtcal.com']
}],
seat: '16'
}],
cur: 'USD'
}
}

let ir = spec.interpretResponse(res, bidRequest)

expect(ir.length).to.equal(1)

let en = ir[0]

expect(en.requestId != null &&
en.cpm != null && typeof en.cpm === 'number' &&
en.width != null && typeof en.width === 'number' &&
en.height != null && typeof en.height === 'number' &&
en.ad != null &&
en.creativeId != null
).to.be.true
})
})
})