Skip to content

Commit

Permalink
Update Platformio Adapter (#2468)
Browse files Browse the repository at this point in the history
* Add PlatformioBidAdapter

* Update platformioBidAdapter.js

* Add files via upload

* Update hello_world.html

* Update platformioBidAdapter.js

* Update platformioBidAdapter_spec.js

* Update hello_world.html

* Update platformioBidAdapter_spec.js

* Update platformioBidAdapter.js

* Update hello_world.html

* Add files via upload

* Update platformioBidAdapter

## Type of change
- [x] Other

## Description of change
1. RequestURL changes
2. Add placementCode to request params

* Update platformioBidAdapter

* Update platformioBidAdapter

## Type of change
- [x] Other

## Description of change
1. RequestURL changes
2. Add placementCode to request params

* Add files via upload

* Add files via upload

* Add files via upload

* Update platformioBidAdapter.js

Endpoint URL change

* Update platformioBidAdapter_spec.js

Endpoint URL change

* Update platformioBidAdapter_spec.js

* Update platformioBidAdapter_spec.js

* Update platformioBidAdapter.js

* Update platformioBidAdapter.js

* Update platformioBidAdapter_spec.js

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Update platformioBidAdapter.js

* Update platformioBidAdapter_spec.js

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Update platformioBidAdapter_spec.js

* Update platformioBidAdapter.js

* Update platformioBidAdapter.md

* Add files via upload

* Add files via upload

* Add files via upload

* Update platformioBidAdapter.md

* Update platformioBidAdapter.md

* Update platformioBidAdapter.js

* Update platformioBidAdapter_spec.js

* Update platformioBidAdapter.md

* Add files via upload

* Add files via upload

* Delete hello_world.html

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload
  • Loading branch information
varashellov authored and jsnellbaker committed May 3, 2018
1 parent bea6ab0 commit 59db2fe
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 18 deletions.
69 changes: 54 additions & 15 deletions modules/platformioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const NATIVE_DEFAULTS = {
IMG_MIN: 150,
ICON_MIN: 50,
};

const DEFAULT_MIMES = ['video/mp4', 'video/webm', 'application/x-shockwave-flash', 'application/javascript'];
const VIDEO_TARGETING = ['mimes', 'skippable', 'playback_method', 'protocols', 'api'];
const DEFAULT_PROTOCOLS = [2, 3, 5, 6];
Expand All @@ -22,15 +21,16 @@ export const spec = {
supportedMediaTypes: [BANNER, NATIVE, VIDEO],

isBidRequestValid: bid => (
!!(bid && bid.params && bid.params.pubId && bid.params.siteId)
!!(bid && bid.params && bid.params.pubId && bid.params.placementId)
),
buildRequests: bidRequests => {
const request = {
id: bidRequests[0].bidderRequestId,
at: 2,
imp: bidRequests.map(slot => impression(slot)),
site: site(bidRequests),
device: device(),
app: app(bidRequests),
device: device(bidRequests),
};
return {
method: 'POST',
Expand Down Expand Up @@ -101,6 +101,7 @@ function bidResponseAvailable(bidRequest, bidResponse) {
function impression(slot) {
return {
id: slot.bidId,
secure: window.location.protocol === 'https:' ? 1 : 0,
'banner': banner(slot),
'native': nativeImpression(slot),
'video': videoImpression(slot),
Expand All @@ -110,10 +111,16 @@ function impression(slot) {
}

function getSizes(slot) {
const size = slot.params.size.toUpperCase().split('X');
if (slot.params.size) {
const size = slot.params.size.toUpperCase().split('X');
return {
width: parseInt(size[0]),
height: parseInt(size[1]),
};
}
return {
width: parseInt(size[0]),
height: parseInt(size[1]),
width: 1,
height: 1,
};
}

Expand Down Expand Up @@ -207,25 +214,57 @@ function dataAsset(id, params, type, defaultLen) {
function site(bidderRequest) {
const pubId = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.pubId : '0';
const siteId = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.siteId : '0';
return {
publisher: {
id: pubId.toString(),
domain: utils.getTopWindowLocation().hostname,
},
id: siteId.toString(),
ref: utils.getTopWindowReferrer(),
page: utils.getTopWindowLocation().href,
const appParams = bidderRequest[0].params.app;
if (!appParams) {
return {
publisher: {
id: pubId.toString(),
domain: utils.getTopWindowLocation().hostname,
},
id: siteId.toString(),
ref: utils.getTopWindowReferrer(),
page: utils.getTopWindowLocation().href,
}
}
return null;
}

function app(bidderRequest) {
const pubId = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.pubId : '0';
const appParams = bidderRequest[0].params.app;
if (appParams) {
return {
publisher: {
id: pubId.toString(),
},
id: appParams.id,
name: appParams.name,
bundle: appParams.bundle,
storeurl: appParams.storeUrl,
domain: appParams.domain,
}
}
return null;
}

function device() {
function device(bidderRequest) {
const lat = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.latitude : '';
const lon = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.longitude : '';
const ifa = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.ifa : '';
return {
dnt: utils.getDNT() ? 1 : 0,
ua: navigator.userAgent,
language: (navigator.language || navigator.browserLanguage || navigator.userLanguage || navigator.systemLanguage),
w: (window.screen.width || window.innerWidth),
h: (window.screen.height || window.innerHeigh),
geo: {
lat: lat,
lon: lon,
},
ifa: ifa,
};
}

function parse(rawResponse) {
try {
if (rawResponse) {
Expand Down
6 changes: 5 additions & 1 deletion modules/platformioBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Please use ```platformio``` as the bidder code.
pubId: '29521',
siteId: '26048',
placementId: '123',
bidFloor: '0.001', // optional
ifa: 'XXX-XXX', // optional
latitude: '40.712775', // optional
longitude: '-74.005973', // optional
}
}]
},
Expand Down Expand Up @@ -76,7 +80,7 @@ Please use ```platformio``` as the bidder code.
size: '640X480',
placementId: '123',
video: {
skippable: true,
skipppable: true,
}
}
}]
Expand Down
39 changes: 37 additions & 2 deletions test/spec/modules/platformioBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ describe('Platform.io Adapter Tests', () => {
siteId: '26047',
placementId: '123',
size: '300x250',
bidFloor: '0.001'
bidFloor: '0.001',
ifa: 'IFA',
latitude: '40.712775',
longitude: '-74.005973'
}
}, {
placementCode: '/DfpAccount2/slot2',
Expand All @@ -24,7 +27,7 @@ describe('Platform.io Adapter Tests', () => {
siteId: '26047',
placementId: '1234',
size: '728x90',
bidFloor: '0.000001'
bidFloor: '0.000001',
}
}];
const nativeSlotConfig = [{
Expand Down Expand Up @@ -58,6 +61,21 @@ describe('Platform.io Adapter Tests', () => {
size: '640x480'
}
}];
const appSlotConfig = [{
placementCode: '/DfpAccount1/slot5',
bidId: 'bid12345',
params: {
pubId: '29521',
placementId: '1234',
app: {
id: '1111',
name: 'app name',
bundle: 'io.platform.apps',
storeUrl: 'http://platform.io/apps',
domain: 'platform.io'
}
}
}];

it('Verify build request', () => {
const request = spec.buildRequests(slotConfigs);
Expand All @@ -74,6 +92,9 @@ describe('Platform.io Adapter Tests', () => {
// device object
expect(ortbRequest.device).to.not.equal(null);
expect(ortbRequest.device.ua).to.equal(navigator.userAgent);
expect(ortbRequest.device.ifa).to.equal('IFA');
expect(ortbRequest.device.geo.lat).to.equal('40.712775');
expect(ortbRequest.device.geo.lon).to.equal('-74.005973');
// slot 1
expect(ortbRequest.imp[0].tagid).to.equal('123');
expect(ortbRequest.imp[0].banner).to.not.equal(null);
Expand Down Expand Up @@ -278,4 +299,18 @@ describe('Platform.io Adapter Tests', () => {
expect(spec.isBidRequestValid(nativeSlotConfig[0])).to.equal(true);
expect(spec.isBidRequestValid(videoSlotConfig[0])).to.equal(true);
});

it('Verify app requests', () => {
const request = spec.buildRequests(appSlotConfig);
const ortbRequest = JSON.parse(request.data);
expect(ortbRequest.site).to.equal(null);
expect(ortbRequest.app).to.not.be.null;
expect(ortbRequest.app.publisher).to.not.equal(null);
expect(ortbRequest.app.publisher.id).to.equal('29521');
expect(ortbRequest.app.id).to.equal('1111');
expect(ortbRequest.app.name).to.equal('app name');
expect(ortbRequest.app.bundle).to.equal('io.platform.apps');
expect(ortbRequest.app.storeurl).to.equal('http://platform.io/apps');
expect(ortbRequest.app.domain).to.equal('platform.io');
});
});

0 comments on commit 59db2fe

Please sign in to comment.