Skip to content

Commit

Permalink
Add New Adapter dgadsBidAdapter (#2429)
Browse files Browse the repository at this point in the history
* Add dgads adapter

* Add dgads adapter

* Add spec file for dgads

* Add spec file for dgads

* Add dgads bid adapter

* Add dgads bid adapter

* fix

* fix

* fix email

* remove  semi-colon

* Add mediaType native

* Add import medaTypes
  • Loading branch information
r-sato authored and jsnellbaker committed Apr 24, 2018
1 parent 204daae commit 372899b
Show file tree
Hide file tree
Showing 3 changed files with 444 additions and 0 deletions.
88 changes: 88 additions & 0 deletions modules/dgadsBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import {registerBidder} from 'src/adapters/bidderFactory';
import * as utils from 'src/utils';
import { BANNER, NATIVE } from 'src/mediaTypes';

const BIDDER_CODE = 'dgads';
const ENDPOINT = 'https://ads-tr.bigmining.com/ad/p/bid';

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [ BANNER, NATIVE ],
isBidRequestValid: function(bid) {
const params = bid.params;
if (!/^\d+$/.test(params.location_id)) {
return false;
}
if (!/^\d+$/.test(params.site_id)) {
return false;
}
return true;
},
buildRequests: function(bidRequests) {
if (bidRequests.length === 0) {
return {};
}

return bidRequests.map(bidRequest => {
const params = bidRequest.params;
const data = {};

data['location_id'] = params.location_id;
data['site_id'] = params.site_id;
data['transaction_id'] = bidRequest.transactionId;
data['bid_id'] = bidRequest.bidId;

return {
method: 'POST',
url: ENDPOINT,
data,
};
});
},
interpretResponse: function(serverResponse, bidRequest) {
const bidResponses = [];
const responseObj = serverResponse.body;
const ads = responseObj.bids;
let bidResponse = {};
if (utils.isEmpty(ads)) {
return [];
}
utils._each(ads, function(ad) {
bidResponse.requestId = ad.bidId;
bidResponse.bidderCode = BIDDER_CODE;
bidResponse.cpm = ad.cpm;
bidResponse.creativeId = ad.creativeId;
bidResponse.currency = 'JPY';
bidResponse.netRevenue = true;
bidResponse.ttl = ad.ttl;
bidResponse.referrer = utils.getTopWindowUrl();
if (ad.isNative == 1) {
bidResponse.mediaType = NATIVE;
bidResponse.native = setNativeResponse(ad);
} else {
bidResponse.width = parseInt(ad.w);
bidResponse.height = parseInt(ad.h);
bidResponse.ad = ad.ad;
}
bidResponses.push(bidResponse);
});
return bidResponses;
}
};
function setNativeResponse(ad) {
let nativeResponce = {};
nativeResponce.image = {
url: ad.image,
width: parseInt(ad.w),
height: parseInt(ad.h)
}
nativeResponce.title = ad.title;
nativeResponce.body = ad.desc;
nativeResponce.sponsoredBy = ad.sponsoredBy;
nativeResponce.clickUrl = ad.clickUrl;
nativeResponce.clickTrackers = ad.clickTrackers || [];
nativeResponce.impressionTrackers = ad.impressionTrackers || [];
return nativeResponce;
}

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

```
Module Name: Digital Garage Ads Platform Bidder Adapter
Module Type: Bidder Adapter
Maintainer:dgads-support@garage.co.jp
```

# Description

Connect to Digital Garage Ads Platform for bids.
This adapter supports Banner and Native.

# Test Parameters
```
var adUnits = [
// Banner
{
code: 'banner-div',
sizes: [[300, 250]],
bids: [{
bidder: 'dgads',
mediaTypes: 'banner',
params: {
location_id: '1',
site_id: '1'
}
}]
},
// Native
{
code: 'native-div',
sizes: [[300, 250]],
mediaTypes: {
native: {
title: {
required: true,
len: 25
},
body: {
required: true,
len: 140
},
sponsoredBy: {
required: true,
len: 40
},
image: {
required: true
},
clickUrl: {
required: true
},
}
},
bids: [{
bidder: 'dgads',
params: {
location_id: '10',
site_id: '1'
}
}]
},
];
```
Loading

0 comments on commit 372899b

Please sign in to comment.