Skip to content

Commit

Permalink
New bid adapter: Wipes (prebid#5051)
Browse files Browse the repository at this point in the history
* add wipes

* done update notes

* URL変更

* update test parameter

* fix mediaType to make it work

* fix spec error

* fix comment

* fix param names

* update fix

* erase unused code

Co-authored-by: 嘉数貴明 <yaki180sx@gmail.com>
Co-authored-by: yaki(kkz) <yaki_180sx@hotmail.com>
  • Loading branch information
3 people authored and iggyfisk committed Jun 22, 2020
1 parent e9e27a6 commit de2a928
Show file tree
Hide file tree
Showing 3 changed files with 250 additions and 0 deletions.
69 changes: 69 additions & 0 deletions modules/wipesBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as utils from '../src/utils.js';
import {config} from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';

const BIDDER_CODE = 'wipes';
const ALIAS_BIDDER_CODE = ['wi'];
const SUPPORTED_MEDIA_TYPES = [BANNER]
const ENDPOINT_URL = 'https://adn-srv.reckoner-api.com/v1/prebid';

function isBidRequestValid(bid) {
switch (true) {
case !!(bid.params.asid):
break;
default:
utils.logWarn(`isBidRequestValid Error. ${bid.params}, please check your implementation.`);
return false;
}
return true;
}

function buildRequests(validBidRequests, bidderRequest) {
return validBidRequests.map(bidRequest => {
const params = bidRequest.params;
const asid = params.asid;
return {
method: 'GET',
url: ENDPOINT_URL,
data: {
asid: asid,
}
}
});
}

function interpretResponse(serverResponse, bidRequest) {
const bidResponses = [];
const response = serverResponse.body;
const cpm = response.cpm * 1000 || 0;
if (cpm !== 0) {
const netRevenue = (response.netRevenue === undefined) ? true : response.netRevenue;
const bidResponse = {
requestId: response.uuid,
cpm: cpm,
width: response.width,
height: response.height,
creativeId: response.video_creative_id || 0,
dealId: response.deal_id,
currency: 'JPY',
netRevenue: netRevenue,
ttl: config.getConfig('_bidderTimeout'),
referrer: bidRequest.data.r || '',
mediaType: BANNER,
ad: response.ad_tag,
};
bidResponses.push(bidResponse);
}
return bidResponses;
}

export const spec = {
code: BIDDER_CODE,
aliases: ALIAS_BIDDER_CODE,
isBidRequestValid,
buildRequests,
interpretResponse,
supportedMediaTypes: SUPPORTED_MEDIA_TYPES
}
registerBidder(spec);
33 changes: 33 additions & 0 deletions modules/wipesBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Overview

```
Module Name: WIPES Bidder Adapter
Module Type: Bidder Adapter
Maintainer: contact@3-shake.com
```

# Description

Connect to WIPES for bids.
Publishers needs to be set up and approved by WIPES team to enable this adapter.
Please contact support@wipestream.com for further information.

# Test Parameters
```javascript
var adUnits = [
// adUnit
{
code: 'video-div',
mediaTypes: {
banner: {
sizes: [[160, 300]],
}
},
bids: [{
bidder: 'wipes',
params: {
asid: 'dWyPondh2EGB_bNlrVjzIXRZO9F0k1dpo0I8ZvQ'
}
}]
}]
```
148 changes: 148 additions & 0 deletions test/spec/modules/wipesBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import {expect} from 'chai';
import {spec} from 'modules/wipesBidAdapter.js';
import {newBidder} from 'src/adapters/bidderFactory.js';

const ENDPOINT_URL = 'https://adn-srv.reckoner-api.com/v1/prebid';

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

describe('isBidRequestValid', function () {
let bid = {
'bidder': 'wipes',
'params': {
asid: 'dWyPondh2EGB_bNlrVjzIXRZO9F0k1dpo0I8ZvQ'
},
'adUnitCode': 'adunit-code',
'bidId': '51ef8751f9aead',
'bidderRequestId': '15246a574e859f',
'auctionId': 'b06c5141-fe8f-4cdf-9d7d-54415490a917',
};

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

it('should return false when asid not passed correctly', function () {
bid.params.asid = '';
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': 'wipes',
'params': {
asid: 'dWyPondh2EGB_bNlrVjzIXRZO9F0k1dpo0I8ZvQ'
},
'adUnitCode': 'adunit-code',
'bidId': '51ef8751f9aead',
'bidderRequestId': '15246a574e859f',
'auctionId': 'b06c5141-fe8f-4cdf-9d7d-54415490a917',
},
{
'bidder': 'wipes',
'params': {
asid: 'dWyPondh2EGB_bNlrVjzIXRZO9F0k1dpo0I8ZvQ'
},
'adUnitCode': 'adunit-code2',
'bidId': '51ef8751f9aead',
'bidderRequestId': '15246a574e859f',
'auctionId': 'b06c5141-fe8f-4cdf-9d7d-54415490a917',
}
];

let bidderRequest = {
refererInfo: {
numIframes: 0,
reachedTop: true,
referer: 'http://example.com',
stack: ['http://example.com']
}
};

const request = spec.buildRequests(bidRequests, bidderRequest);

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

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

it('adUnitCode should be sent as uc parameters on any requests', function () {
expect(request[0].data.asid).to.equal('dWyPondh2EGB_bNlrVjzIXRZO9F0k1dpo0I8ZvQ');
expect(request[1].data.asid).to.equal('dWyPondh2EGB_bNlrVjzIXRZO9F0k1dpo0I8ZvQ');
});
});

describe('interpretResponse', function () {
let bidRequestVideo = [
{
'method': 'GET',
'url': ENDPOINT_URL,
'data': {
'asid': 'dWyPondh2EGB_bNlrVjzIXRZO9F0k1dpo0I8ZvQ',
}
}
];

let serverResponseVideo = {
body: {
'uuid': 'a42947f8-f8fd-4cf7-bb72-31a87ab1f6ff',
'ad_tag': '<!-- adtag -->',
'height': 160,
'width': 300,
'cpm': 850,
'status_message': '',
'currency': 'JPY',
'video_creative_id': 600004
}
};

it('should get the correct bid response for video', function () {
let expectedResponse = [{
'requestId': '23beaa6af6cdde',
'cpm': 850,
'width': 300,
'height': 160,
'creativeId': '600004',
'dealId': undefined,
'currency': 'JPY',
'netRevenue': true,
'ttl': 3000,
'referrer': '',
'mediaType': 'banner',
'ad': '<!-- adtag -->'
}];
let result = spec.interpretResponse(serverResponseVideo, bidRequestVideo[0]);
expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0]));
expect(result[0].mediaType).to.equal(expectedResponse[0].mediaType);
});

it('handles empty bid response', function () {
let response = {
body: {
'uid': 'a42947f8-f8fd-4cf7-bb72-31a87ab1f6ff',
'height': 0,
'crid': '',
'statusMessage': '',
'width': 0,
'cpm': 0
}
};
let result = spec.interpretResponse(response, bidRequestVideo[0]);
expect(result.length).to.equal(0);
});
});
});

0 comments on commit de2a928

Please sign in to comment.