forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Real Time Data Module: Mobian Brand Safety (prebid#11798)
* add mobian brand safety variables * directly set site.ext.data in a getBidRequestData function
- Loading branch information
1 parent
50f5f28
commit c746637
Showing
3 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { submodule } from '../src/hook.js'; | ||
import { ajaxBuilder } from '../src/ajax.js'; | ||
export const MOBIAN_URL = 'http://impact-analytics-staging.themobian.com'; | ||
|
||
export const mobianBrandSafetySubmodule = { | ||
name: 'mobianBrandSafety', | ||
gvlid: null, | ||
init: init, | ||
getBidRequestData: getBidRequestData | ||
}; | ||
|
||
function init() { | ||
return true; | ||
} | ||
function getBidRequestData(bidReqConfig, callback, config) { | ||
const { site: ortb2Site } = bidReqConfig.ortb2Fragments.global; | ||
const pageUrl = encodeURIComponent(getPageUrl()); | ||
const requestUrl = `${MOBIAN_URL}?url=${pageUrl}`; | ||
|
||
const ajax = ajaxBuilder(); | ||
|
||
return new Promise((resolve) => { | ||
ajax(requestUrl, { | ||
success: function(response) { | ||
const risks = ['garm_high_risk', 'garm_medium_risk', 'garm_low_risk', 'garm_no_risk']; | ||
const riskLevels = ['high_risk', 'medium_risk', 'low_risk', 'no_risk']; | ||
|
||
let mobianGarmRisk = 'unknown'; | ||
for (let i = 0; i < risks.length; i++) { | ||
if (response[risks[i]]) { | ||
mobianGarmRisk = riskLevels[i]; | ||
break; | ||
} | ||
} | ||
const risk = { | ||
'mobianGarmRisk': mobianGarmRisk | ||
}; | ||
resolve(risk); | ||
ortb2Site.ext.data['mobian'] = risk | ||
}, | ||
error: function () { | ||
resolve({}); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
function getPageUrl() { | ||
return window.location.href; | ||
} | ||
|
||
submodule('realTimeData', mobianBrandSafetySubmodule); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Overview | ||
|
||
Module Name: Mobian Rtd Provider | ||
Module Type: Rtd Provider | ||
Maintainer: rich.rodriguez@themobian.com | ||
|
||
# Description | ||
|
||
RTD provider for themobian Brand Safety determinations. Publishers | ||
should use this to get Mobian's GARM Risk evaluations for | ||
a URL. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
import { mobianBrandSafetySubmodule, MOBIAN_URL } from 'modules/mobianRtdProvider.js'; | ||
import * as ajax from 'src/ajax.js'; | ||
|
||
describe('Mobian RTD Submodule', function () { | ||
let ajaxStub; | ||
let bidReqConfig; | ||
|
||
beforeEach(function () { | ||
bidReqConfig = { | ||
ortb2Fragments: { | ||
global: { | ||
site: { | ||
ext: { | ||
data: {} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
}); | ||
|
||
afterEach(function () { | ||
ajaxStub.restore(); | ||
}); | ||
|
||
it('should return no_risk when server responds with garm_no_risk', function () { | ||
ajaxStub = sinon.stub(ajax, 'ajaxBuilder').returns(function(url, callbacks) { | ||
callbacks.success({ | ||
garm_no_risk: true, | ||
garm_low_risk: false, | ||
garm_medium_risk: false, | ||
garm_high_risk: false | ||
}); | ||
}); | ||
|
||
return mobianBrandSafetySubmodule.getBidRequestData(bidReqConfig, {}, {}).then((risk) => { | ||
expect(risk).to.have.property('mobianGarmRisk'); | ||
expect(risk['mobianGarmRisk']).to.equal('no_risk'); | ||
expect(bidReqConfig.ortb2Fragments.global.site.ext.data.mobian).to.deep.equal(risk); | ||
}); | ||
}); | ||
|
||
it('should return low_risk when server responds with garm_no_risk', function () { | ||
ajaxStub = sinon.stub(ajax, 'ajaxBuilder').returns(function(url, callbacks) { | ||
callbacks.success({ | ||
garm_no_risk: false, | ||
garm_low_risk: true, | ||
garm_medium_risk: false, | ||
garm_high_risk: false | ||
}); | ||
}); | ||
|
||
return mobianBrandSafetySubmodule.getBidRequestData(bidReqConfig, {}, {}).then((risk) => { | ||
expect(risk).to.have.property('mobianGarmRisk'); | ||
expect(risk['mobianGarmRisk']).to.equal('low_risk'); | ||
expect(bidReqConfig.ortb2Fragments.global.site.ext.data.mobian).to.deep.equal(risk); | ||
}); | ||
}); | ||
|
||
it('should return medium_risk when server responds with garm_medium_risk', function () { | ||
ajaxStub = sinon.stub(ajax, 'ajaxBuilder').returns(function(url, callbacks) { | ||
callbacks.success({ | ||
garm_no_risk: false, | ||
garm_low_risk: false, | ||
garm_medium_risk: true, | ||
garm_high_risk: false | ||
}); | ||
}); | ||
|
||
return mobianBrandSafetySubmodule.getBidRequestData(bidReqConfig, {}, {}).then((risk) => { | ||
expect(risk).to.have.property('mobianGarmRisk'); | ||
expect(risk['mobianGarmRisk']).to.equal('medium_risk'); | ||
expect(bidReqConfig.ortb2Fragments.global.site.ext.data.mobian).to.deep.equal(risk); | ||
}); | ||
}); | ||
|
||
it('should return high_risk when server responds with garm_high_risk', function () { | ||
ajaxStub = sinon.stub(ajax, 'ajaxBuilder').returns(function(url, callbacks) { | ||
callbacks.success({ | ||
garm_no_risk: false, | ||
garm_low_risk: false, | ||
garm_medium_risk: false, | ||
garm_high_risk: true | ||
}); | ||
}); | ||
|
||
return mobianBrandSafetySubmodule.getBidRequestData(bidReqConfig, {}, {}).then((risk) => { | ||
expect(risk).to.have.property('mobianGarmRisk'); | ||
expect(risk['mobianGarmRisk']).to.equal('high_risk'); | ||
expect(bidReqConfig.ortb2Fragments.global.site.ext.data.mobian).to.deep.equal(risk); | ||
}); | ||
}); | ||
|
||
it('should return unknown when server response is not of the expected shape', function () { | ||
ajaxStub = sinon.stub(ajax, 'ajaxBuilder').returns(function(url, callbacks) { | ||
callbacks.success('unexpected output not even of the right type'); | ||
}); | ||
|
||
return mobianBrandSafetySubmodule.getBidRequestData(bidReqConfig, {}, {}).then((risk) => { | ||
expect(risk).to.have.property('mobianGarmRisk'); | ||
expect(risk['mobianGarmRisk']).to.equal('unknown'); | ||
expect(bidReqConfig.ortb2Fragments.global.site.ext.data.mobian).to.deep.equal(risk); | ||
}); | ||
}); | ||
}); |