Skip to content

Commit

Permalink
Add vuukle adapter (prebid#5773)
Browse files Browse the repository at this point in the history
* add vuukle adapter

* add readme

* doc: add email
  • Loading branch information
Hamper authored and stsepelin committed May 28, 2021
1 parent 8dbbfea commit 465f456
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
63 changes: 63 additions & 0 deletions modules/vuukleBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';

const BIDDER_CODE = 'vuukle';
const URL = 'https://pb.vuukle.com/adapter';
const TIME_TO_LIVE = 360;

export const spec = {
code: BIDDER_CODE,

isBidRequestValid: function(bid) {
return true
},

buildRequests: function(bidRequests) {
const requests = bidRequests.map(function (bid) {
const parseSized = utils.parseSizesInput(bid.sizes);
const arrSize = parseSized[0].split('x');
const params = {
url: encodeURIComponent(window.location.href),
sizes: JSON.stringify(parseSized),
width: arrSize[0],
height: arrSize[1],
params: JSON.stringify(bid.params),
rnd: Math.random(),
bidId: bid.bidId,
source: 'pbjs',
version: '$prebid.version$',
v: 1,
};

return {
method: 'GET',
url: URL,
data: params,
options: {withCredentials: false}
}
});

return requests;
},

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

const res = serverResponse.body;
const bidResponse = {
requestId: bidRequest.data.bidId,
cpm: res.cpm,
width: res.width,
height: res.height,
creativeId: res.creative_id,
currency: res.currency || 'USD',
netRevenue: true,
ttl: TIME_TO_LIVE,
ad: res.ad
};
return [bidResponse];
},
}
registerBidder(spec);
26 changes: 26 additions & 0 deletions modules/vuukleBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Overview
```
Module Name: Vuukle Bid Adapter
Module Type: Bidder Adapter
Maintainer: support@vuukle.com
```

# Description
Module that connects to Vuukle's server for bids.
Currently module supports only banner mediaType.

# Test Parameters
```
var adUnits = [{
code: '/test/div',
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
bids: [{
bidder: 'vuukle',
params: {}
}]
}];
```
59 changes: 59 additions & 0 deletions test/spec/modules/vuukleBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { expect } from 'chai';
import { spec } from 'modules/vuukleBidAdapter.js';

describe('vuukleBidAdapterTests', function() {
let bidRequestData = {
bids: [
{
bidId: 'testbid',
bidder: 'vuukle',
params: {
test: 1
},
sizes: [[300, 250]]
}
]
};
let request = [];

it('validate_pub_params', function() {
expect(
spec.isBidRequestValid({
bidder: 'vuukle',
params: {
test: 1
}
})
).to.equal(true);
});

it('validate_generated_params', function() {
request = spec.buildRequests(bidRequestData.bids);
let req_data = request[0].data;

expect(req_data.bidId).to.equal('testbid');
});

it('validate_response_params', function() {
let serverResponse = {
body: {
'cpm': 0.01,
'width': 300,
'height': 250,
'creative_id': '12345',
'ad': 'test ad'
}
};

request = spec.buildRequests(bidRequestData.bids);
let bids = spec.interpretResponse(serverResponse, request[0]);
expect(bids).to.have.lengthOf(1);

let bid = bids[0];
expect(bid.ad).to.equal('test ad');
expect(bid.cpm).to.equal(0.01);
expect(bid.width).to.equal(300);
expect(bid.height).to.equal(250);
expect(bid.creativeId).to.equal('12345');
});
});

0 comments on commit 465f456

Please sign in to comment.