Skip to content

Commit

Permalink
New Bid Adapter: Shinez (#6597)
Browse files Browse the repository at this point in the history
* Shinze adapter version 1.0.0

* map for arrays replaced with forEach, fpd temporarily removed

* switched to only public interface testing

* Usage of URL removed
  • Loading branch information
Soterix authored Apr 20, 2021
1 parent 4eade73 commit e174e27
Show file tree
Hide file tree
Showing 3 changed files with 268 additions and 0 deletions.
83 changes: 83 additions & 0 deletions modules/shinezBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';

const BIDDER_CODE = 'shinez';
const BIDDER_SHORT_CODE = 'shz';
const ADAPTER_VERSION = '1.0.0';

const TARGET_URL = 'https://shinez-ssp.shinez.workers.dev/prebid';

export const spec = {
code: BIDDER_CODE,
version: ADAPTER_VERSION,
aliases: {
code: BIDDER_SHORT_CODE
},
supportedMediaTypes: [ BANNER ],
isBidRequestValid: isBidRequestValid,
buildRequests: buildRequests,
interpretResponse: interpretResponse,
};

export const internal = {
TARGET_URL
}

function isBidRequestValid(bid) {
return !!(bid && bid.params &&
bid.params.placementId && typeof bid.params.placementId === 'string' &&
(bid.params.unit == null || (typeof bid.params.unit === 'string' && bid.params.unit.length > 0))
);
}

function buildRequests(validBidRequests, bidderRequest) {
const utcOffset = (new Date()).getTimezoneOffset();
const data = [];
validBidRequests.forEach(function(bidRequest) {
data.push(_buildServerBidRequest(bidRequest, bidderRequest, utcOffset));
});
const request = {
method: 'POST',
url: TARGET_URL,
data: data
};
return request;
}

function interpretResponse(serverResponse, request) {
const bids = [];
serverResponse.body.forEach(function(serverBid) {
bids.push(_convertServerBid(serverBid));
});
return bids;
}

function _buildServerBidRequest(bidRequest, bidderRequest, utcOffset) {
return {
bidId: bidRequest.bidId,
transactionId: bidRequest.transactionId,
crumbs: bidRequest.crumbs,
mediaTypes: bidRequest.mediaTypes,
refererInfo: bidderRequest.refererInfo,
placementId: bidRequest.params.placementId,
utcOffset: utcOffset,
adUnitCode: bidRequest.adUnitCode,
unit: bidRequest.params.unit
}
}

function _convertServerBid(response) {
return {
requestId: response.bidId,
cpm: response.cpm,
currency: response.currency,
width: response.width,
height: response.height,
ad: response.ad,
ttl: response.ttl,
creativeId: response.creativeId,
netRevenue: response.netRevenue
};
}

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

```
Module Name: Shinez Bidder Adapter
Module Type: Bidder Adapter
Maintainer: tech-team@shinez.io
```

# Description

Connects to shinez.io demand sources.

The Shinez adapter requires setup and approval from the Shinez team.
Please reach out to tech-team@shinez.io for more information.

# Test Parameters

```javascript
var adUnits = [{
code: "test-div",
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
bids: [{
bidder: "shinez",
params: {
placementId: "00654321"
}
}]
}];
```
152 changes: 152 additions & 0 deletions test/spec/modules/shinezBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import { expect } from 'chai';
import sinon from 'sinon';
import { spec, internal } from 'modules/shinezBidAdapter.js';

describe('shinezBidAdapter', () => {
let sandbox;
beforeEach(() => {
sandbox = sinon.sandbox.create();
});
afterEach(() => {
sandbox.restore();
});
describe('isBidRequestValid', () => {
const cases = [
[
'should return false when placementId is missing',
{
params: {},
},
false,
],
[
'should return false when placementId has wrong type',
{
params: {
placementId: 123,
},
},
false,
],
[
'should return false when unit has wrong type',
{
params: {
placementId: '00654321',
unit: 150,
},
},
false,
],
[
'should return true when required params found and valid',
{
params: {
placementId: '00654321',
},
},
true,
],
[
'should return true when all params found and valid',
{
params: {
placementId: '00654321',
unit: '__header-bid-1',
},
},
true,
],
];
cases.map(([description, request, expected]) => {
it(description, () => {
const result = spec.isBidRequestValid(request);
expect(result).to.be.equal(expected);
});
});
});
describe('buildRequests', () => {
it('should build server request correctly', () => {
const utcOffset = 300;
const validBidRequests = [
{
params: {
placementId: '00654321',
unit: 'header-bid-tag-1-shinez',
},
crumbs: {
pubcid: 'c8584a82-bec3-4347-8d3e-e7612438a161',
},
mediaTypes: {
banner: {
sizes: [[300, 250]],
},
},
adUnitCode: 'header-bid-tag-1',
transactionId: '665760dc-a249-4be7-ae86-91f417b2c65d',
},
];
const bidderRequest = {
refererInfo: {
referer: 'http://site-with-ads.com',
},
};
sandbox.stub(Date.prototype, 'getTimezoneOffset').returns(utcOffset);
const result = spec.buildRequests(validBidRequests, bidderRequest);
const expectedData = [
{
bidId: validBidRequests[0].bidId,
transactionId: validBidRequests[0].transactionId,
crumbs: validBidRequests[0].crumbs,
mediaTypes: validBidRequests[0].mediaTypes,
refererInfo: bidderRequest.refererInfo,
adUnitCode: validBidRequests[0].adUnitCode,
utcOffset: utcOffset,
placementId: validBidRequests[0].params.placementId,
unit: validBidRequests[0].params.unit,
},
];
expect(result.method, "request should be POST'ed").equal('POST');
expect(result.url, 'request should be send to correct url').equal(
internal.TARGET_URL
);
expect(result.data, 'request should have correct payload').to.deep.equal(
expectedData
);
});
});
describe('interpretResponse', () => {
it('should interpret bid responses correctly', () => {
const response = {
body: [
{
bidId: '2ece6496f4d0c9',
cpm: 0.03,
currency: 'USD',
width: 300,
height: 250,
ad: `<h1>The Ad</h1>`,
ttl: 60,
creativeId: 'V8qlA6guwm',
netRevenue: true,
},
],
};
const bids = [
{
requestId: response.body[0].bidId,
cpm: response.body[0].cpm,
currency: response.body[0].currency,
width: response.body[0].width,
height: response.body[0].height,
ad: response.body[0].ad,
ttl: response.body[0].ttl,
creativeId: response.body[0].creativeId,
netRevenue: response.body[0].netRevenue,
},
];
const result = spec.interpretResponse(response);
expect(result).to.deep.equal(bids);
});
});
});

0 comments on commit e174e27

Please sign in to comment.