Skip to content

Commit

Permalink
Retailspot bidAdapter : Endpoint update (#12602)
Browse files Browse the repository at this point in the history
* add retailspot GVL_ID,  update retailspotads domain name

* update port for local testing

* update unit tests

* update test parameters with new placement id

* simplify getSize workflow

* fix lint error on type definition

---------

Co-authored-by: Guillaume Andouard <[email protected]>
  • Loading branch information
rs-guian and guiann authored Dec 26, 2024
1 parent 12e70fd commit 0419f1a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
42 changes: 23 additions & 19 deletions modules/retailspotBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ import {BANNER, VIDEO} from '../src/mediaTypes.js';
/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid
* @typedef {import('../src/adapters/bidderFactory.js').BidderRequest} BidderRequest
*/

const BIDDER_CODE = 'retailspot';
const DEFAULT_SUBDOMAIN = 'ssp';
const PREPROD_SUBDOMAIN = 'ssp-preprod';
const HOST = 'retail-spot.io';
const ENDPOINT = '/prebid';
const DEV_URL = 'http://localhost:8090/prebid';
const GVL_ID = 1319;

const DEFAULT_SUBDOMAIN = 'hbapi';
const PREPROD_SUBDOMAIN = 'hbapi-preprod';
const HOST = 'retailspotads.com';
const ENDPOINT = '/';
const DEV_URL = 'http://localhost:3030/';

export const spec = {
code: BIDDER_CODE,
gvlid: GVL_ID,
supportedMediaTypes: [BANNER, VIDEO],
aliases: ['rs'], // short code
/**
Expand All @@ -25,15 +29,16 @@ export const spec = {
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
const sizes = getSize(getSizeArray(bid));
const sizes = getSize(bid);
const sizeValid = sizes.width > 0 && sizes.height > 0;

return deepAccess(bid, 'params.placement') && sizeValid;
},
/**
* Make a server request from the list of BidRequests.
*
* @param {BidRequests} - bidRequests.bids[] is an array of AdUnits and bids
* @param {BidRequest} bidRequests is an array of AdUnits and bids
* @param {BidderRequest} bidderRequest
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (bidRequests, bidderRequest) {
Expand Down Expand Up @@ -96,40 +101,39 @@ export const spec = {
}
}

function getSizeArray(bid) {
/* Get parsed size from request size */
function getSize(bid) {
let inputSize = bid.sizes || [];

if (bid.mediaTypes && bid.mediaTypes.banner) {
if (bid.mediaTypes?.banner) {
inputSize = bid.mediaTypes.banner.sizes || [];
}

// handle size in bid.params in formats: [w, h] and [[w,h]].
if (bid.params && Array.isArray(bid.params.size)) {
// Size can be [w, h] or array of sizes : [[w,h]].
if (Array.isArray(bid.params?.size)) {
inputSize = bid.params.size;
if (!Array.isArray(inputSize[0])) {
inputSize = [inputSize]
}
}

return parseSizesInput(inputSize);
}

/* Get parsed size from request size */
function getSize(sizesArray) {
const sizesArray = parseSizesInput(inputSize);
const parsed = {};
// the main requested size is the first one

// Use the first size as the main requested one
const size = sizesArray[0];

// size is ready
if (typeof size !== 'string') {
return parsed;
}

const parsedSize = size.toUpperCase().split('X');
// size is given as string "wwwxhhh" or "www*hhh"
const parsedSize = size.includes('*') ? size.split('*') : size.toUpperCase().split('X');
const width = parseInt(parsedSize[0], 10);
if (width) {
parsed.width = width;
}

const height = parseInt(parsedSize[1], 10);
if (height) {
parsed.height = height;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Banner and Video ad formats are supported.
bids: [{
bidder: "retailspot",
params: {
placement: "test-12345"
placement: "eq-609785-1856964-125234"
}
}]
};
Expand Down
8 changes: 4 additions & 4 deletions test/spec/modules/retailspotBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ describe('RetailSpot Adapter', function () {
];
const adapter = newBidder(spec);

const DEV_URL = 'http://localhost:8090/';
const DEV_URL = 'http://localhost:3030/';

describe('inherited functions', function () {
it('exists and is a function', function () {
Expand Down Expand Up @@ -333,7 +333,7 @@ describe('RetailSpot Adapter', function () {
const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest);
const payload = JSON.parse(request.data);

expect(request.url).to.contain('https://ssp.retail-spot.io/prebid');
expect(request.url).to.contain('https://hbapi.retailspotads.com/');
expect(request.method).to.equal('POST');

expect(payload).to.deep.equal(bidderRequest);
Expand All @@ -344,7 +344,7 @@ describe('RetailSpot Adapter', function () {
const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest);
const payload = JSON.parse(request.data);

expect(request.url).to.contain('https://ssp.retail-spot.io/prebid');
expect(request.url).to.contain('https://hbapi.retailspotads.com/');
expect(request.method).to.equal('POST');

expect(payload).to.deep.equal(bidderRequest);
Expand All @@ -355,7 +355,7 @@ describe('RetailSpot Adapter', function () {
const request = spec.buildRequests(bidRequestMultiPlacements, bidderRequest);
const payload = JSON.parse(request.data);

expect(request.url).to.contain('https://ssp.retail-spot.io/prebid');
expect(request.url).to.contain('https://hbapi.retailspotads.com/');
expect(request.method).to.equal('POST');

expect(payload).to.deep.equal(bidderRequest);
Expand Down

0 comments on commit 0419f1a

Please sign in to comment.