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

Add NasmediaAdmixer adapter for Perbid.js 1.0 #1937

Merged
merged 6 commits into from
Jan 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
81 changes: 81 additions & 0 deletions modules/nasmediaAdmixerBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import * as utils from 'src/utils';
import {registerBidder} from 'src/adapters/bidderFactory';

const ADMIXER_ENDPOINT = 'https://adn.admixer.co.kr:10443/prebid';
const DEFAULT_BID_TTL = 360;
const DEFAULT_CURRENCY = 'USD';
const DEFAULT_REVENUE = false;

export const spec = {
code: 'nasmediaAdmixer',

isBidRequestValid: function (bid) {
return !!(bid && bid.params && bid.params.ax_key);
},

buildRequests: function (validBidRequests) {
return validBidRequests.map(bid => {
let adSize = getSize(bid.sizes);

return {
method: 'GET',
url: ADMIXER_ENDPOINT,
data: {
ax_key: utils.getBidIdParameter('ax_key', bid.params),
req_id: bid.bidId,
width: adSize.width,
height: adSize.height,
referrer: utils.getTopWindowUrl(),
os: getOsType()
}
}
})
},

interpretResponse: function (serverResponse, bidRequest) {
const serverBody = serverResponse.body;
const bidResponses = [];

if (serverBody && serverBody.error_code === 0 && serverBody.body && serverBody.body.length > 0) {
let bidData = serverBody.body[0];

const bidResponse = {
ad: bidData.ad,
requestId: serverBody.req_id,
creativeId: bidData.ad_id,
cpm: bidData.cpm,
width: bidData.width,
height: bidData.height,
currency: bidData.currency ? bidData.currency : DEFAULT_CURRENCY,
netRevenue: DEFAULT_REVENUE,
ttl: DEFAULT_BID_TTL
};

bidResponses.push(bidResponse);
}
return bidResponses;
}
}

function getOsType() {
let ua = navigator.userAgent.toLowerCase();
let os = ['android', 'ios', 'mac', 'linux', 'window', 'etc'];
let regexp_os = [/android/i, /iphone|ipad/i, /mac/i, /linux/i, /window/i, ''];

return regexp_os.some((tos, idx) => {
if (ua.match(tos)) {
return os[idx];
}
});
}

function getSize(sizes) {
let parsedSizes = utils.parseSizesInput(sizes);
let [width, height] = parsedSizes.length ? parsedSizes[0].split('x') : [];

return {
width: parseInt(width, 10),
height: parseInt(height, 10)
};
}
registerBidder(spec);
32 changes: 32 additions & 0 deletions modules/nasmediaAdmixerBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Overview

```
Module Name: NasmeidaAdmixer Bidder Adapter
Module Type: Bidder Adapter
Maintainer: [email protected]
```

# Description

Module that connects to NasmediaAdmixer demand sources.
Banner formats are supported.
The NasmediaAdmixer adapter doesn't support multiple sizes per ad-unit and will use the first one if multiple sizes are defined.


# Test Parameters
```
var adUnits = [
{
code: 'banner-ad-div',
sizes: [[320, 480]], // banner size
bids: [
{
bidder: 'nasmediaAdmixer',
params: {
ax_key: 'ajj7jba3', //required parameter
}
}
]
}
];
```
138 changes: 138 additions & 0 deletions test/spec/modules/nasmediaAdmixerBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import {expect} from 'chai';
import {spec} from 'modules/nasmediaAdmixerBidAdapter';
import {newBidder} from 'src/adapters/bidderFactory';

describe('nasmediaAdmixerBidAdapter', () => {
const adapter = newBidder(spec);

describe('inherited functions', () => {
it('exists and is a function', () => {
expect(adapter.callBids).to.exist.and.to.be.a('function');
});
});

describe('isBidRequestValid', () => {
const bid = {
'bidder': 'nasmediaAdmixer',
'params': {
'ax_key': 'ax_key'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250]],
'bidId': '3361d01e67dbd6',
'bidderRequestId': '2b60dcd392628a',
'auctionId': '124cb070528662',
};

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

it('should return false when required params are not passed', () => {
const bid = Object.assign({}, bid);
delete bid.params;
bid.params = {
'ax_key': 0
};
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
});

describe('buildRequests', () => {
const bidRequests = [
{
'bidder': 'nasmediaAdmixer',
'params': {
'ax_key': 'ajj7jba3'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250]],
'bidId': '3361d01e67dbd6',
'bidderRequestId': '2b60dcd392628a',
'auctionId': '124cb070528662',
}
];

it('sends bid request to url via GET', () => {
const request = spec.buildRequests(bidRequests)[0];
expect(request.method).to.equal('GET');
expect(request.url).to.match(new RegExp(`https://adn.admixer.co.kr`));
});
});

describe('interpretResponse', () => {
const response = {
'body': {
'bidder': 'nasmedia_admixer',
'req_id': '861a8e7952c82c',
'error_code': 0,
'error_msg': 'OK',
'body': [{
'ad_id': '20049',
'width': 300,
'height': 250,
'currency': 'USD',
'cpm': 1.769221,
'ad': '<!-- Creative -->'
}]
},
'headers': {
'get': function () {
}
}
};

const bidRequest = {
'bidder': 'nasmediaAdmixer',
'params': {
'ax_key': 'ajj7jba3',
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [320, 480]],
'bidId': '31300c8b9697cd',
'bidderRequestId': '2bf570adcf83fa',
'auctionId': '169827a33f03cc',
};

it('should get correct bid response', () => {
const expectedResponse = [
{
'requestId': '861a8e7952c82c',
'cpm': 1.769221,
'currency': 'USD',
'width': 300,
'height': 250,
'ad': '<!-- Creative -->',
'creativeId': '20049',
'ttl': 360,
'netRevenue': false
}
];

const result = spec.interpretResponse(response, bidRequest);
expect(result).to.have.lengthOf(1);
let resultKeys = Object.keys(result[0]);
expect(resultKeys.sort()).to.deep.equal(Object.keys(expectedResponse[0]).sort());
resultKeys.forEach(function (k) {
if (k === 'ad') {
expect(result[0][k]).to.match(/<!-- Creative -->$/);
} else {
expect(result[0][k]).to.equal(expectedResponse[0][k]);
}
});
});

it('handles nobid responses', () => {
response.body = {
'bidder': 'nasmedia_admixer',
'req_id': '861a8e7952c82c',
'error_code': 0,
'error_msg': 'OK',
'body': []
};

const result = spec.interpretResponse(response, bidRequest);
expect(result).to.have.lengthOf(0);
});
});
});