Skip to content

Commit

Permalink
feat(sublime-adapter): accept 1x1 format + handle timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
SublimeTheo committed Jun 7, 2019
1 parent c2f453f commit 59c9e10
Showing 1 changed file with 45 additions and 6 deletions.
51 changes: 45 additions & 6 deletions modules/sublimeBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { registerBidder } from 'src/adapters/bidderFactory';
import { config } from '../src/config';
import * as utils from '../src/utils';

const BIDDER_CODE = 'sublime';
const DEFAULT_BID_HOST = 'pbjs.sskzlabs.com';
const DEFAULT_SAC_HOST = 'sac.ayads.co';
const DEFAULT_CALLBACK_NAME = 'sublime_prebid_callback';
const DEFAULT_PROTOCOL = 'https';
const SUBLIME_VERSION = '0.3.2';
const SUBLIME_VERSION = '0.3.3';
let SUBLIME_ZONE = null;

/**
Expand Down Expand Up @@ -58,19 +59,27 @@ export const spec = {
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: (validBidRequests, bidderRequest) => {
window.sublime = window.sublime ? window.sublime : {}

if (bidderRequest && bidderRequest.gdprConsent) {
const gdpr = {
consentString: bidderRequest.gdprConsent.consentString,
gdprApplies: (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') ? bidderRequest.gdprConsent.gdprApplies : true
};

window.sublime = (typeof window.sublime !== 'undefined') ? window.sublime : {};
window.sublime.gdpr = (typeof window.sublime.gdpr !== 'undefined') ? window.sublime.gdpr : {};
window.sublime.gdpr.injected = {
consentString: gdpr.consentString,
gdprApplies: gdpr.gdprApplies
};
}

window.sublime.pbjs = (typeof window.sublime.pbjs !== 'undefined') ? window.sublime.pbjs : {};
window.sublime.pbjs.injected = {
bt: config.getConfig('bidderTimeout'),
ts: Date.now()
};

// Grab only the first `validBidRequest`
let bid = validBidRequests[0];

Expand Down Expand Up @@ -109,13 +118,27 @@ export const spec = {
script.src = 'https://' + sacHost + '/sublime/' + SUBLIME_ZONE + '/prebid?callback=' + callbackName;
document.body.appendChild(script);

// Initial size object
let sizes = {
w: null,
h: null
};

if (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes && bid.mediaTypes.banner.sizes[0]) {
// Setting size for banner if they exist
sizes.w = bid.mediaTypes.banner.sizes[0][0] || false;
sizes.h = bid.mediaTypes.banner.sizes[0][1] || false;
}

return {
method: 'GET',
url: protocol + '://' + bidHost + '/bid',
data: {
prebid: 1,
request_id: requestId,
z: SUBLIME_ZONE
z: SUBLIME_ZONE,
w: sizes.w || 1800,
h: sizes.h || 1000
}
};
},
Expand All @@ -124,19 +147,35 @@ export const spec = {
* Unpack the response from the server into a list of bids.
*
* @param {*} serverResponse A successful response from the server.
* @param {*} bidRequest An object with bid request informations
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: (serverResponse) => {
interpretResponse: (serverResponse, bidRequest) => {
const bidResponses = [];
const response = serverResponse.body;

if (response) {
// Setting our returned sizes object to default values
let returnedSizes = {
width: 1800,
height: 1000
};

// Verifying Banner sizes
if (bidRequest && bidRequest.data.w === 1 && bidRequest.data.h === 1) {
// If banner sizes are 1x1 we set our default size object to 1x1
returnedSizes = {
width: 1,
height: 1
};
}

const regexNoAd = /no ad/gmi;
const bidResponse = {
requestId: serverResponse.body.request_id || '',
cpm: serverResponse.body.cpm || 0,
width: 1800,
height: 1000,
width: returnedSizes.width,
height: returnedSizes.height,
creativeId: 1,
dealId: 1,
currency: serverResponse.body.currency || 'USD',
Expand Down

0 comments on commit 59c9e10

Please sign in to comment.