Skip to content

Commit

Permalink
ADSS-281 implement getUserSyncs and putting checks for empty ad serve…
Browse files Browse the repository at this point in the history
…r response (#2377)
  • Loading branch information
bruscantini authored and jaiminpanchal27 committed Apr 13, 2018
1 parent f5900ff commit 055d3fb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
38 changes: 36 additions & 2 deletions modules/gumgumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ function buildRequests (validBidRequests) {
function interpretResponse (serverResponse, bidRequest) {
const bidResponses = []
const serverResponseBody = serverResponse.body
const defaultResponse = {
ad: {
price: 0,
id: 0,
markup: ''
},
pag: {
pvid: 0
}
}
const {
ad: {
price: cpm,
Expand All @@ -158,7 +168,7 @@ function interpretResponse (serverResponse, bidRequest) {
pag: {
pvid
}
} = serverResponseBody
} = Object.assign(defaultResponse, serverResponseBody)
let isTestUnit = (bidRequest.data && bidRequest.data.pi === 3 && bidRequest.data.si === 9)
let [width, height] = utils.parseSizesInput(bidRequest.sizes)[0].split('x')

Expand All @@ -183,11 +193,35 @@ function interpretResponse (serverResponse, bidRequest) {
return bidResponses
}

/**
* Register the user sync pixels which should be dropped after the auction.
*
* @param {SyncOptions} syncOptions Which user syncs are allowed?
* @param {ServerResponse[]} serverResponses List of server's responses.
* @return {UserSync[]} The user syncs which should be dropped.
*/
function getUserSyncs (syncOptions, serverResponses) {
const responses = serverResponses.map((response) => {
return (response.body && response.body.pxs && response.body.pxs.scr) || []
})
const userSyncs = responses.reduce(function (usersyncs, response) {
return usersyncs.concat(response)
}, [])
const syncs = userSyncs.map((sync) => {
return {
type: sync.t === 'f' ? 'iframe' : 'image',
url: sync.u
}
})
return syncs;
}

export const spec = {
code: BIDDER_CODE,
aliases: ALIAS_BIDDER_CODE,
isBidRequestValid,
buildRequests,
interpretResponse
interpretResponse,
getUserSyncs
}
registerBidder(spec)
22 changes: 22 additions & 0 deletions test/spec/modules/gumgumBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,26 @@ describe('gumgumAdapter', () => {
expect(result.length).to.equal(0);
});
})
describe('getUserSyncs', () => {
const syncOptions = {
'iframeEnabled': 'true'
}
const response = {
'pxs': {
'scr': [
{
't': 'i',
'u': 'https://c.gumgum.com/images/pixel.gif'
},
{
't': 'f',
'u': 'https://www.nytimes.com/'
}
]
}
}
let result = spec.getUserSyncs(syncOptions, [{ body: response }]);
expect(result[0].type).to.equal('image')
expect(result[1].type).to.equal('iframe')
})
});

0 comments on commit 055d3fb

Please sign in to comment.