Skip to content

Commit

Permalink
update AdGeneration adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
banakemi committed Oct 25, 2018
1 parent 5e27370 commit ab93aaa
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
40 changes: 38 additions & 2 deletions modules/adgenerationBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as utils from 'src/utils';
// import {config} from 'src/config';
import {registerBidder} from 'src/adapters/bidderFactory';
import {BANNER, NATIVE} from 'src/mediaTypes';
const ADG_BIDDER_CODE = 'adgeneration';
Expand All @@ -15,7 +14,7 @@ export const spec = {
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
return !!(bid.params.id);
return !!(bid.params.id) && (isValidCurrency(bid.params.currency));
},
/**
* Make a server request from the list of BidRequests.
Expand All @@ -24,6 +23,7 @@ export const spec = {
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests) {
const ADGENE_PREBID_VERSION = '1.0.1';
let serverRequests = [];
for (let i = 0, len = validBidRequests.length; i < len; i++) {
const validReq = validBidRequests[i];
Expand All @@ -38,6 +38,12 @@ export const spec = {
data = utils.tryAppendQueryString(data, 'hb', 'true');
data = utils.tryAppendQueryString(data, 't', 'json3');
data = utils.tryAppendQueryString(data, 'transactionid', validReq.transactionId);
data = utils.tryAppendQueryString(data, 'sizes', getSizes(validReq));
data = utils.tryAppendQueryString(data, 'currency', validReq.params.currency.toUpperCase());
data = utils.tryAppendQueryString(data, 'pbver', '$prebid.version$');
data = utils.tryAppendQueryString(data, 'sdkname', 'prebidjs');
data = utils.tryAppendQueryString(data, 'adapterver', ADGENE_PREBID_VERSION);
data = utils.tryAppendQueryString(data, 'tp', utils.getTopWindowUrl());

// native以外にvideo等の対応が入った場合は要修正
if (!validReq.mediaTypes || !validReq.mediaTypes.native) {
Expand Down Expand Up @@ -198,4 +204,34 @@ function removeWrapper(ad) {
return ad.substr(bodyIndex, lastBodyIndex).replace('<body>', '').replace('</body>', '');
}

/**
* request
* @param validReq request
* @returns {?string} 300x250,320x50...
*/
function getSizes(validReq) {
const sizes = validReq.sizes;
if (!sizes || sizes.length < 1) return null;
let sizesStr = null;
for (const i in sizes) {
const size = sizes[i];
if (sizesStr == null) {
sizesStr = size[0] + 'x' + size[1];
} else {
sizesStr += ',' + size[0] + 'x' + size[1];
}
}
return sizesStr;
}

/**
* @param {?string} currency
* @return {!boolean}
*/
function isValidCurrency(currency) {
if (!currency) return false;
const upperCurrency = currency.toUpperCase();
return (upperCurrency === 'JPY' || upperCurrency === 'USD')
}

registerBidder(spec);
1 change: 1 addition & 0 deletions modules/adgenerationBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var adUnits = [
bidder: 'adg',
params: {
id: '58278', // banner
currency: 'JPY',
}
},
]
Expand Down
15 changes: 7 additions & 8 deletions test/spec/modules/adgenerationBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ describe('AdgenerationAdapter', function () {
});

describe('isBidRequestValid', function () {
let bid = {
const bid = {
'bidder': 'adg',
'params': {
id: '58278', // banner
currency: 'JPY',
}
};
it('should return true when required params found', function () {
Expand All @@ -39,11 +40,10 @@ describe('AdgenerationAdapter', function () {
bidder: 'adg',
params: {
id: '58278',
width: '300',
height: '250'
currency: 'JPY',
},
adUnitCode: 'adunit-code',
sizes: [[300, 250]],
sizes: [[300, 250], [320, 100]],
bidId: '2f6ac468a9c15e',
bidderRequestId: '14a9f773e30243',
auctionId: '4aae9f05-18c6-4fcd-80cf-282708cd584a',
Expand All @@ -53,8 +53,7 @@ describe('AdgenerationAdapter', function () {
bidder: 'adg',
params: {
id: '58278',
width: '300',
height: '250'
currency: 'JPY',
},
mediaTypes: {
native: {
Expand Down Expand Up @@ -88,8 +87,8 @@ describe('AdgenerationAdapter', function () {
}
];
const data = {
banner: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&imark=1',
native: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3'
banner: `posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=300x250%2C320x100&currency=JPY&pbver=%24prebid.version%24&sdkname=prebidjs&adapterver=1.0.1&tp=http%3A%2F%2Flocalhost%3A9876%2F&imark=1`,
native: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=1x1&currency=JPY&pbver=%24prebid.version%24&sdkname=prebidjs&adapterver=1.0.1&tp=http%3A%2F%2Flocalhost%3A9876%2F'
};
it('sends bid request to ENDPOINT via GET', function () {
const request = spec.buildRequests(bidRequests)[0];
Expand Down

0 comments on commit ab93aaa

Please sign in to comment.