Skip to content

Commit

Permalink
Update JCM Adapter to 1.0 (#1715)
Browse files Browse the repository at this point in the history
* Add files via upload

* Update package.json

* Add files via upload

Test for jcm adapter

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Delete jcm.js

* Add files via upload

* Add files via upload

* Add files via upload

* Delete jcm_spec.js

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Delete adapters.json

* Update package.json
  • Loading branch information
JCarterGw authored and jaiminpanchal27 committed Oct 24, 2017
1 parent 755f193 commit 923adfb
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 266 deletions.
115 changes: 67 additions & 48 deletions modules/jcmBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,88 @@
var bidfactory = require('src/bidfactory.js');
var bidmanager = require('src/bidmanager.js');
var adloader = require('src/adloader.js');
var utils = require('src/utils.js');
var adaptermanager = require('src/adaptermanager');
import * as utils from 'src/utils';
import {registerBidder} from 'src/adapters/bidderFactory';
const BIDDER_CODE = 'jcm';
const URL = '//media.adfrontiers.com/pq'

var JCMAdapter = function JCMAdapter() {
window.pbjs = window.pbjs || {};
window.pbjs.processJCMResponse = function(JCMResponse) {
if (JCMResponse) {
var JCMRespObj = JSON.parse(JCMResponse);
if (JCMRespObj) {
var bids = JCMRespObj.bids;
for (var i = 0; i < bids.length; i++) {
var bid = bids[i];
var bidObject;
if (bid.cpm > 0) {
bidObject = bidfactory.createBid(1);
bidObject.bidderCode = 'jcm';
bidObject.cpm = bid.cpm;
bidObject.ad = decodeURIComponent(bid.ad.replace(/\+/g, '%20'));
bidObject.width = bid.width;
bidObject.height = bid.height;
bidmanager.addBidResponse(utils.getBidRequest(bid.callbackId).placementCode, bidObject);
} else {
bidObject = bidfactory.createBid(2);
bidObject.bidderCode = 'jcm';
bidmanager.addBidResponse(utils.getBidRequest(bid.callbackId).placementCode, bidObject);
}
}
}
}
};
export const spec = {
code: BIDDER_CODE,
aliases: ['jcarter'],
isBidRequestValid: function(bid) {
return !!(bid.params && bid.params.siteId && bid.bidId);
},

function _callBids(params) {
var BidRequest = {
buildRequests: function(validBidRequests) {
var BidRequestStr = {
bids: []
};

for (var i = 0; i < params.bids.length; i++) {
for (var i = 0; i < validBidRequests.length; i++) {
var adSizes = '';
var bid = params.bids[i];
var bid = validBidRequests[i];
for (var x = 0; x < bid.sizes.length; x++) {
adSizes += utils.parseGPTSingleSizeArray(bid.sizes[x]);
if (x !== (bid.sizes.length - 1)) {
adSizes += ',';
}
}

BidRequest.bids.push({
BidRequestStr.bids.push({
'callbackId': bid.bidId,
'siteId': bid.params.siteId,
'adSizes': adSizes
'adSizes': adSizes,
});
}

var JSONStr = JSON.stringify(BidRequest);
var reqURL = document.location.protocol + '//media.adfrontiers.com/pq?t=hb&bids=' + encodeURIComponent(JSONStr);
adloader.loadScript(reqURL);
}
var JSONStr = JSON.stringify(BidRequestStr);
var dataStr = 't=hb&ver=1.0&compact=true&bids=' + encodeURIComponent(JSONStr);

return {
method: 'GET',
url: URL,
data: dataStr
}
},

return {
callBids: _callBids
};
};
interpretResponse: function(serverResponse) {
const bidResponses = [];
// loop through serverResponses
if (serverResponse) {
if (serverResponse.bids) {
var bids = serverResponse.bids;
for (var i = 0; i < bids.length; i++) {
var bid = bids[i];
const bidResponse = {
requestId: bid.callbackId,
bidderCode: spec.code,
cpm: bid.cpm,
width: bid.width,
height: bid.height,
creativeId: bid.creativeId,
currency: 'USD',
netRevenue: bid.netRevenue,
ttl: bid.ttl,
ad: decodeURIComponent(bid.ad.replace(/\+/g, '%20'))
};
bidResponses.push(bidResponse);
};
};
}
return bidResponses;
},

adaptermanager.registerBidAdapter(new JCMAdapter(), 'jcm');
getUserSyncs: function(syncOptions) {
if (syncOptions.iframeEnabled) {
return [{
type: 'iframe',
url: '//media.adfrontiers.com/hb/jcm_usersync.html'
}];
}
if (syncOptions.image) {
return [{
type: 'image',
url: '//media.adfrontiers.com/hb/jcm_usersync.png'
}];
}
}
}

module.exports = JCMAdapter;
registerBidder(spec);
40 changes: 40 additions & 0 deletions modules/jcmBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#Overview

```
Module Name: JCM Bidder Adapter
Module Type: Bidder Adapter
Maintainer: george@jcartermarketing.com
```

# Description

Module that connects to J Carter Marketing demand sources

# Test Parameters
```
var adUnits = [
{
code: 'test-div1',
sizes: [[300, 250]], // display 300x250
bids: [
{
bidder: 'jcm',
params: {
siteId: '3608'
}
}
]
},{
code: 'test-div2',
sizes: [[728, 90]], // display 728x90
bids: [
{
bidder: 'jcm',
params: {
siteId: '3608'
}
}
]
}
];
Loading

0 comments on commit 923adfb

Please sign in to comment.