@mediamath/terminalone
Advanced tools
Comparing version
@@ -5,14 +5,13 @@ var expect = require('./chai_config').expect; | ||
describe("Get, create and save Entities", function () { | ||
describe("Get, create and save Entities", function() { | ||
t1conf = { | ||
preferCookieAuth: true, | ||
user: process.env.T1_API_USERNAME, | ||
password: process.env.T1_API_PASSWORD, | ||
api_key: process.env.T1_API_KEY, | ||
client_secret: process.env.T1_SECRET, | ||
apiBaseUrl: process.env.T1_BASEURL, | ||
redirect_uri: process.env.T1_REDIRECTURL, | ||
advertiser_id: parseInt(process.env.T1_ADVERTISER) | ||
// Tests will return 403 if user does not have access to advertiser | ||
}; | ||
var conn = new t1.T1Connection(t1conf); | ||
@@ -23,9 +22,9 @@ var testTimestamp = new Date().toISOString(); | ||
describe("#create and update single campaign", function () { | ||
describe("#create and update single campaign", function() { | ||
var campaign = new t1.Entity('campaign'); | ||
it("should save a new campaign", function () { | ||
it("should save a new campaign", function() { | ||
campaign.ad_server_id = 9; | ||
campaign.name = expectedName + ' campaign'; | ||
campaign.advertiser_id = t1conf.advertiser_id; | ||
campaign.advertiser_id = parseInt(process.env.T1_ADVERTISER); | ||
campaign.status = false; | ||
@@ -47,8 +46,8 @@ var start = new Date(), | ||
return expect(campaignPromise).to.eventually | ||
.have.property('id') && | ||
.have.property('id') && | ||
expect(campaignPromise).to.eventually | ||
.have.property('version', 0); | ||
.have.property('version', 0); | ||
}); | ||
it("should update name", function () { | ||
it("should update name", function() { | ||
campaignId = campaign.id; | ||
@@ -61,12 +60,12 @@ var expectedName = campaign.name + '_UPDATED'; | ||
return expect(campaignPromise).to.eventually | ||
.have.property('name', expectedName) && | ||
.have.property('name', expectedName) && | ||
expect(campaignPromise).to.eventually | ||
.have.property('version', version + 1); | ||
.have.property('version', version + 1); | ||
}); | ||
}); | ||
describe("#create a strategy", function () { | ||
describe("#create a strategy", function() { | ||
var strategy = new t1.Entity('strategy'); | ||
it("should save a new strategy", function () { | ||
it("should save a new strategy", function() { | ||
strategy.name = expectedName + ' strategy'; | ||
@@ -88,8 +87,8 @@ strategy.budget = 100; | ||
return expect(strategyPromise).to.eventually | ||
.have.property('id') && | ||
.have.property('id') && | ||
expect(strategyPromise).to.eventually | ||
.have.property('version', 0); | ||
.have.property('version', 0); | ||
}); | ||
it("set the strategy ID", function () { | ||
it("set the strategy ID", function() { | ||
strategyId = strategy.id; | ||
@@ -99,23 +98,28 @@ }); | ||
describe("#set up target segments", function () { | ||
describe("#set up target segments", function() { | ||
this.timeout(10000); | ||
var targetSegments = new t1.StrategyTargetSegments(); | ||
it("should get the target segments", function () { | ||
it("should get the target segments", function() { | ||
var targetSegmentsPromise = targetSegments.get(strategyId, conn); | ||
return expect(targetSegmentsPromise).to.eventually | ||
.have.property('include_op', 'OR') && | ||
.have.property('include_op', 'OR') && | ||
expect(targetSegmentsPromise).to.eventually | ||
.have.property('exclude_op', 'OR') && | ||
.have.property('exclude_op', 'OR') && | ||
expect(targetSegmentsPromise).to.eventually | ||
.have.property('include') | ||
.and.deep.equal([]) && | ||
.have.property('include') | ||
.and.deep.equal([]) && | ||
expect(targetSegmentsPromise).to.eventually | ||
.have.property('exclude') | ||
.and.deep.equal([]); | ||
.have.property('exclude') | ||
.and.deep.equal([]); | ||
}); | ||
it("should get a CPM", function () { | ||
targetSegments.include = [[865, 'OR'], [871, 'OR']]; | ||
targetSegments.exclude = [[362, 'OR']]; | ||
it("should get a CPM", function() { | ||
targetSegments.include = [ | ||
[865, 'OR'], | ||
[871, 'OR'] | ||
]; | ||
targetSegments.exclude = [ | ||
[362, 'OR'] | ||
]; | ||
@@ -130,3 +134,3 @@ var cpmPromise = targetSegments.getCpmEstimate(conn); | ||
it("should successfully save", function () { | ||
it("should successfully save", function() { | ||
var savePromise = targetSegments.save(conn); | ||
@@ -138,21 +142,21 @@ | ||
describe("#set up audience segments", function () { | ||
describe("#set up audience segments", function() { | ||
this.timeout(10000); | ||
var audienceSegments = new t1.StrategyAudienceSegments(); | ||
it("should get the target segments", function () { | ||
it("should get the target segments", function() { | ||
var audienceSegmentsPromise = audienceSegments.get(strategyId, conn); | ||
return expect(audienceSegmentsPromise).to.eventually | ||
.have.property('include_op', 'OR') && | ||
.have.property('include_op', 'OR') && | ||
expect(audienceSegmentsPromise).to.eventually | ||
.have.property('exclude_op', 'OR') && | ||
.have.property('exclude_op', 'OR') && | ||
expect(audienceSegmentsPromise).to.eventually | ||
.have.property('include') | ||
.and.deep.equal([]) && | ||
.have.property('include') | ||
.and.deep.equal([]) && | ||
expect(audienceSegmentsPromise).to.eventually | ||
.have.property('exclude') | ||
.and.deep.equal([]); | ||
.have.property('exclude') | ||
.and.deep.equal([]); | ||
}); | ||
it("should get a CPM", function () { | ||
it("should get a CPM", function() { | ||
audienceSegments.include = [131454, 131453]; | ||
@@ -169,3 +173,3 @@ audienceSegments.exclude = [131452]; | ||
it("should successfully save", function () { | ||
it("should successfully save", function() { | ||
var savePromise = audienceSegments.save(conn); | ||
@@ -177,7 +181,7 @@ | ||
describe("#set up target dimensions", function () { | ||
describe("#set up target dimensions", function() { | ||
this.timeout(10000); | ||
var targetValues = new t1.StrategyTargetValues(); | ||
it("should get the target values", function () { | ||
it("should get the target values", function() { | ||
var targetValuesPromise = targetValues.get(strategyId, conn); | ||
@@ -189,5 +193,5 @@ return expect(targetValuesPromise).to.eventually | ||
it("should successfully save", function () { | ||
it("should successfully save", function() { | ||
targetValues.addTargetValues('REGN', 'INCLUDE', 'OR', [23, 251]); | ||
it("should successfully save", function () { | ||
it("should successfully save", function() { | ||
@@ -202,19 +206,2 @@ var savePromise = targetValues.save(conn); | ||
}); | ||
describe("Test Oauth login", function (){ | ||
it("should return a authorization url", function () { | ||
conn.initializeOauth(); | ||
var authUrl = conn.fetchAuthUrl(); | ||
return expect(authUrl).to.contain('https://api.mediamath.com/oauth2/v1.0/authorize'); | ||
}); | ||
// TODO: can we obtain a valid code without doing the user auth? | ||
// it("should return a token", function () { | ||
// var tokenPromise = conn.getToken(process.env.OAUTH_CODE,"https://blog.mediamath.com/"); | ||
// return expect(tokenPromise).to.eventually | ||
// .have.property('token') | ||
// }); | ||
}); | ||
}); |
@@ -1,3 +0,4 @@ | ||
var expect = require('./chai_config').expect; | ||
var t1 = require('../index'); | ||
"use strict"; | ||
let expect = require('./chai_config').expect; | ||
let t1 = require('../index'); | ||
require('dotenv').load(); | ||
@@ -7,3 +8,3 @@ | ||
this.timeout(10000); | ||
t1conf = { | ||
let t1conf = { | ||
// To run these test, set the dotenv variables by copying .env.template and filling in the parameters. | ||
@@ -13,28 +14,23 @@ user: process.env.T1_API_USERNAME, | ||
api_key: process.env.T1_API_KEY, | ||
client_secret: process.env.T1_SECRET, | ||
apiBaseUrl: process.env.T1_BASEURL, | ||
redirect_uri: process.env.T1_REDIRECTURL, | ||
advertiser_id: parseInt(process.env.T1_ADVERTISER) | ||
// Tests will return 403 if user does not have access to advertiser | ||
}; | ||
var conn = new t1.T1Connection(t1conf); | ||
let conn = new t1.T1Connection(t1conf); | ||
it('should retrieve reports endpoint metadata', function() { | ||
var Report = new t1.Report('meta'); | ||
var reportPromise = Report.getMeta(conn) | ||
let Report = new t1.Report('meta'); | ||
let reportPromise = Report.getMeta(conn); | ||
return expect(reportPromise).to.eventually.have.property('reports') | ||
}); | ||
it('should retrieve performance report metadata', function() { | ||
var Report = new t1.Report('performance'); | ||
var reportPromise = Report.getMeta(conn) | ||
let Report = new t1.Report('performance'); | ||
let reportPromise = Report.getMeta(conn); | ||
return expect(reportPromise).to.eventually.have.property('Name', 'Performance Report in Campaign Currency') | ||
}); | ||
it('should retrieve performance report', function() { | ||
var Report = new t1.Report('performance'); | ||
var reportPromise = Report.get(conn, { | ||
let Report = new t1.Report('performance'); | ||
let reportPromise = Report.get(conn, { | ||
time_window: 'yesterday', | ||
time_rollup: 'by_day', | ||
dimensions: 'advertiser_id', | ||
filter: 'advertiser_id=' + t1conf.advertiser_id | ||
filter: 'advertiser_id=' + parseInt(process.env.T1_ADVERTISER), | ||
}) | ||
@@ -41,0 +37,0 @@ return expect(reportPromise).to.eventually.have.property('errors').to.be.empty |
@@ -45,3 +45,3 @@ "use strict"; | ||
return connection.post(endpoint, form).then(function (body) { | ||
return connection.postFormdata(endpoint, form).then(function (body) { | ||
var content = JSON.parse(body); | ||
@@ -48,0 +48,0 @@ return that.updateTargeting(content.data, content.meta); |
"use strict"; | ||
let EntityMap = require('./entitymap'); | ||
let SchemaProcessing = require('./schemaprocessing'); | ||
require('dotenv').load(); | ||
var EntityMap = require('./entitymap'); | ||
var SchemaProcessing = require('./schemaprocessing'); | ||
var Config = require('./common/config'); | ||
var Entity = function (type, connection, id) { | ||
let Entity = function (type, connection, id) { | ||
this.entity_type = type; | ||
@@ -19,6 +18,6 @@ | ||
} | ||
var that = this; | ||
let that = this; | ||
return SchemaProcessing.getSchema('userparams') | ||
.then(function (schema) { | ||
var verification = SchemaProcessing.validateJson(userParams, schema); | ||
let verification = SchemaProcessing.validateJson(userParams, schema); | ||
if (verification.length !== 0) { | ||
@@ -29,6 +28,6 @@ // you may want to specify a custom error type here, and set the verification | ||
} | ||
var queryString = connection.buildQueryString(EntityMap.getEndpoint(that.entity_type) + "/" + id, userParams); | ||
let queryString = connection.buildQueryString(EntityMap.getEndpoint(that.entity_type) + "/" + id, userParams); | ||
return connection.get(queryString); | ||
}).then(function (body) { | ||
var content = JSON.parse(body); | ||
let content = JSON.parse(body); | ||
return that.processEntity(content.data, content.meta); | ||
@@ -41,4 +40,4 @@ }); | ||
Entity.prototype.processEntity = function (data, meta) { | ||
for (var property in data) { | ||
if (!data.hasOwnProperty(property)) { | ||
for (let property in data) { | ||
if (!data.hasOwnProperty(property) || !data[property]) { | ||
continue; | ||
@@ -48,3 +47,3 @@ } | ||
data[property][0].hasOwnProperty('entity_type')) { | ||
var EntityList = require('./entitylist'); | ||
let EntityList = require('./entitylist'); | ||
data[property] = EntityList.processEntityList(data[property], {}); | ||
@@ -54,3 +53,3 @@ } | ||
data[property].hasOwnProperty('entity_type')) { | ||
var related = new Entity(data[property].entity_type); | ||
let related = new Entity(data[property].entity_type); | ||
related.processEntity(data[property], {}); | ||
@@ -70,6 +69,6 @@ data[property] = related; | ||
Entity.prototype.save = function (connection) { | ||
var that = this; | ||
let that = this; | ||
return SchemaProcessing.getSchema(that.entity_type) | ||
.then(function (schema) { | ||
var verification = SchemaProcessing.validateJson(that, schema); | ||
let verification = SchemaProcessing.validateJson(that, schema); | ||
if (verification.length !== 0) { | ||
@@ -79,13 +78,16 @@ throw new Error(verification); | ||
else { | ||
return that._getPostData() | ||
.then(function (form) { | ||
var endpoint = EntityMap.getEndpoint(that.entity_type); | ||
if (typeof that.id != 'undefined') { | ||
endpoint += "/" + that.id; | ||
} | ||
return connection.post(endpoint, form).then(function (body) { | ||
var content = JSON.parse(body); | ||
return that.processEntity(content.data, content.meta); | ||
}); | ||
}); | ||
let endpoint = EntityMap.getEndpoint(that.entity_type); | ||
let postFormat = EntityMap.getPostFormat(that.entity_type); | ||
if (typeof that.id !== 'undefined') { | ||
endpoint += "/" + that.id; | ||
} | ||
if (postFormat === 'json') { | ||
return that._saveJson(endpoint, connection); | ||
} | ||
else if (postFormat === 'formdata') { | ||
return that._saveFormData(endpoint, connection); | ||
} | ||
} | ||
@@ -103,9 +105,47 @@ }); | ||
Entity.prototype._saveJson = function (endpoint, connection) { | ||
let data = this._getJsonData(); | ||
let that = this; | ||
return connection.postJson(endpoint, data).then(function (body) { | ||
let content = JSON.parse(body); | ||
return that.processEntity(content.data, content.meta); | ||
}); | ||
Entity.prototype._getPostData = function () { | ||
var that = this; | ||
}; | ||
Entity.prototype._saveFormData = function (endpoint, connection) { | ||
let that = this; | ||
return that._getPostFormData() | ||
.then(function (form) { | ||
let endpoint = EntityMap.getEndpoint(that.entity_type); | ||
if (typeof that.id !== 'undefined') { | ||
endpoint += "/" + that.id; | ||
} | ||
return connection.postFormdata(endpoint, form).then(function (body) { | ||
let content = JSON.parse(body); | ||
return that.processEntity(content.data, content.meta); | ||
}); | ||
}); | ||
}; | ||
Entity.prototype._getJsonData = function () { | ||
let data = JSON.parse(JSON.stringify(this)); | ||
//remove any null properties; the API doesn't support them. | ||
for (let property in this) { | ||
if (this.hasOwnProperty(property) && !this[property]) { | ||
delete data[property]; | ||
} | ||
} | ||
return JSON.stringify(data); | ||
}; | ||
Entity.prototype._getPostFormData = function () { | ||
let that = this; | ||
return SchemaProcessing.getSchema(that.entity_type) | ||
.then(function (schema) { | ||
var schemaAllOf = schema.allOf; | ||
var encodeForPost = function (key, value) { | ||
let schemaAllOf = schema.allOf; | ||
let encodeForPost = function (key, value) { | ||
if (typeof value === "boolean") { | ||
@@ -120,3 +160,3 @@ return Number(value); | ||
var form = JSON.parse(JSON.stringify(that, encodeForPost)); | ||
let form = JSON.parse(JSON.stringify(that, encodeForPost)); | ||
schemaAllOf.map(function (schema) { | ||
@@ -131,3 +171,3 @@ Object.keys(schema.properties).forEach(function (key) { | ||
//flatten the currency elements | ||
for (var property in form) { | ||
for (let property in form) { | ||
if (!form.hasOwnProperty(property)) { | ||
@@ -145,5 +185,6 @@ continue; | ||
function _getOrSetCurrencyValue(obj, fieldName, currencyName, setAmount) { | ||
if (!currencyName) { | ||
currencyName = obj.currency_code || Config.defaultCurrencyCode; | ||
currencyName = obj.currency_code || (process.env.CURRENCY_CODE || 'USD'); | ||
} | ||
@@ -153,5 +194,5 @@ if (!obj[fieldName]) { | ||
} | ||
var currencyValues = obj[fieldName]; | ||
for (var currencyPair of currencyValues) { | ||
if (currencyPair.currency_code == currencyName) { | ||
let currencyValues = obj[fieldName]; | ||
for (let currencyPair of currencyValues) { | ||
if (currencyPair.currency_code === currencyName) { | ||
if (setAmount) { | ||
@@ -165,3 +206,3 @@ currencyPair.value = setAmount; | ||
if (setAmount) { | ||
var newEntry = { | ||
let newEntry = { | ||
currency_code: currencyName, | ||
@@ -168,0 +209,0 @@ value: setAmount |
"use strict"; | ||
var Entity = require('./entity'); | ||
var Config = require('./common/config'); | ||
var EntityMap = require('./entitymap'); | ||
var SchemaProcessing = require('./schemaprocessing'); | ||
@@ -11,3 +11,3 @@ | ||
// accept an object with user parameters: {'page_limit':10} | ||
EntityList.get = function (baseUrl, connection, userParams) { | ||
EntityList.get = function (base, connection, userParams) { | ||
if (!connection) { | ||
@@ -19,3 +19,3 @@ throw new Error("connection object must be provided"); | ||
.then(function (schema) { | ||
var verification = SchemaProcessing.validateJson(userParams, schema); | ||
let verification = SchemaProcessing.validateJson(userParams, schema); | ||
@@ -28,3 +28,5 @@ if (verification.length !== 0) { | ||
var queryString = connection.buildQueryString(baseUrl, userParams); | ||
// if it looks like a full path just use that; we're here from getNextPage. | ||
let queryString = /^[a-z_]*$/.test(base) ? | ||
connection.buildQueryString(EntityMap.getEndpoint(base), userParams) : base; | ||
@@ -34,3 +36,3 @@ return connection.get(queryString); | ||
.then(function (body) { | ||
var content = JSON.parse(body); | ||
let content = JSON.parse(body); | ||
return EntityList.processEntityList(content.data, content.meta); | ||
@@ -43,4 +45,4 @@ }); | ||
function* EntityGenerator(entities) { | ||
for (var entity of entities) { | ||
var newEntity = new Entity(entity.entity_type); | ||
for (let entity of entities) { | ||
let newEntity = new Entity(entity.entity_type); | ||
newEntity.processEntity(entity); | ||
@@ -58,6 +60,5 @@ yield newEntity; | ||
EntityList.getNextPage = function (retrieved, connection) { | ||
var retrievedNext = retrieved.meta.next_page; | ||
let retrievedNext = retrieved.meta.next_page; | ||
if (typeof retrievedNext !== 'undefined') { | ||
var nextPage = retrievedNext.substring(Config.apiUrl.length, retrievedNext.length); | ||
return this.get(nextPage, connection); | ||
return this.get(retrievedNext, connection); | ||
} | ||
@@ -64,0 +65,0 @@ }; |
@@ -1,42 +0,287 @@ | ||
var entityMap = { | ||
'atomic_creative': '/api/v2.0/atomic_creatives', | ||
'ad_server': '/api/v2.0/ad_servers', | ||
'advertiser': '/api/v2.0/advertisers', | ||
'audience_segment': '/api/v2.0/audience_segments', | ||
'agency': '/api/v2.0/agencies', | ||
'campaign': '/api/v2.0/campaigns', | ||
'concept': '/api/v2.0/concepts', | ||
'creative': '/api/v2.0/creatives', | ||
'creative_approval': '/api/v2.0/creative_approvals', | ||
"deal": '/api/v2.0/deals', | ||
"organization": '/api/v2.0/organizations', | ||
"pixel": '/api/v2.0/pixels', | ||
"pixel_bundle": '/api/v2.0/pixel_bundles', | ||
"pixel_provider": '/api/v2.0/pixel_providers', | ||
"placement_slot": '/api/v2.0/placement_slots', | ||
"publisher": '/api/v2.0/publishers', | ||
"publisher_site": '/api/v2.0/publisher_sites', | ||
"site_list": '/api/v2.0/site_lists', | ||
"site_placement": '/api/v2.0/site_placement', | ||
"strategy": '/api/v2.0/strategies', | ||
"strategy_concept": '/api/v2.0/strategy_concepts', | ||
"strategy_day_part": '/api/v2.0/strategy_day_parts', | ||
"strategy_domain": '/api/v2.0/strategy_domains', | ||
"strategy_supply_source": '/api/v2.0/strategy_supply_sources', | ||
"target_dimension": '/api/v2.0/target_dimensions', | ||
"target_value": '/api/v2.0/target_values', | ||
"targeting_vendor": '/api/v2.0/targeting_vendors', | ||
"user": '/api/v2.0/users', | ||
"vendor": '/api/v2.0/vendors', | ||
"vendor_contract": '/api/v2.0/vendor_contracts', | ||
"vendor_domain": '/api/v2.0/vendor_domains', | ||
"vendor_pixel": '/api/v2.0/vendor_pixels', | ||
"vendor_pixel_domain": '/api/v2.0/vendor_pixel_domains', | ||
"vertical": '/api/v2.0/verticals' | ||
"use strict"; | ||
let entityMap = { | ||
'atomic_creative': { | ||
'path': '/api/v2.0/atomic_creatives', | ||
'postformat': 'formdata' | ||
}, | ||
'atomic_creatives': { | ||
'path': '/api/v2.0/atomic_creatives', | ||
'postformat': 'formdata' | ||
}, | ||
'ad_server': { | ||
'path': '/api/v2.0/ad_servers', | ||
'postformat': 'formdata' | ||
}, | ||
'ad_servers': { | ||
'path': '/api/v2.0/ad_servers', | ||
'postformat': 'formdata' | ||
}, | ||
'advertiser': { | ||
'path': '/api/v2.0/advertisers', | ||
'postformat': 'formdata' | ||
}, | ||
'advertisers': { | ||
'path': '/api/v2.0/advertisers', | ||
'postformat': 'formdata' | ||
}, | ||
'audience_segment': { | ||
'path': '/api/v2.0/audience_segments', | ||
'postformat': 'formdata' | ||
}, | ||
'audience_segments': { | ||
'path': '/api/v2.0/audience_segments', | ||
'postformat': 'formdata' | ||
}, | ||
'agency': { | ||
'path': '/api/v2.0/agencies', | ||
'postformat': 'formdata' | ||
}, | ||
'agencies': { | ||
'path': '/api/v2.0/agencies', | ||
'postformat': 'formdata' | ||
}, | ||
'campaign': { | ||
'path': '/api/v2.0/campaigns', | ||
'postformat': 'formdata' | ||
}, | ||
'campaigns': { | ||
'path': '/api/v2.0/campaigns', | ||
'postformat': 'formdata' | ||
}, | ||
'concept': { | ||
'path': '/api/v2.0/concepts', | ||
'postformat': 'formdata' | ||
}, | ||
'concepts': { | ||
'path': '/api/v2.0/concepts', | ||
'postformat': 'formdata' | ||
}, | ||
'creative': { | ||
'path': '/api/v2.0/creatives', | ||
'postformat': 'formdata' | ||
}, | ||
'creatives': { | ||
'path': '/api/v2.0/creatives', | ||
'postformat': 'formdata' | ||
}, | ||
'creative_approval': { | ||
'path': '/api/v2.0/creative_approvals', | ||
'postformat': 'formdata' | ||
}, | ||
'creative_approvals': { | ||
'path': '/api/v2.0/creative_approvals', | ||
'postformat': 'formdata' | ||
}, | ||
"deal": { | ||
'path': '/media/v1.0/deals', | ||
'postformat': 'json' | ||
}, | ||
"deals": { | ||
'path': '/media/v1.0/deals', | ||
'postformat': 'json' | ||
}, | ||
"organization": { | ||
'path': '/api/v2.0/organizations', | ||
'postformat': 'formdata' | ||
}, | ||
"organizations": { | ||
'path': '/api/v2.0/organizations', | ||
'postformat': 'formdata' | ||
}, | ||
"pixel": { | ||
'path': '/api/v2.0/pixels', | ||
'postformat': 'formdata' | ||
}, | ||
"pixels": { | ||
'path': '/api/v2.0/pixels', | ||
'postformat': 'formdata' | ||
}, | ||
"pixel_bundle": { | ||
'path': '/api/v2.0/pixel_bundles', | ||
'postformat': 'formdata' | ||
}, | ||
"pixel_bundles": { | ||
'path': '/api/v2.0/pixel_bundles', | ||
'postformat': 'formdata' | ||
}, | ||
"pixel_provider": { | ||
'path': '/api/v2.0/pixel_providers', | ||
'postformat': 'formdata' | ||
}, | ||
"pixel_providers": { | ||
'path': '/api/v2.0/pixel_providers', | ||
'postformat': 'formdata' | ||
}, | ||
"placement_slot": { | ||
'path': '/api/v2.0/placement_slots', | ||
'postformat': 'formdata' | ||
}, | ||
"placement_slots": { | ||
'path': '/api/v2.0/placement_slots', | ||
'postformat': 'formdata' | ||
}, | ||
"publisher": { | ||
'path': '/api/v2.0/publishers', | ||
'postformat': 'formdata' | ||
}, | ||
"publishers": { | ||
'path': '/api/v2.0/publishers', | ||
'postformat': 'formdata' | ||
}, | ||
"publisher_site": { | ||
'path': '/api/v2.0/publisher_sites', | ||
'postformat': 'formdata' | ||
}, | ||
"publisher_sites": { | ||
'path': '/api/v2.0/publisher_sites', | ||
'postformat': 'formdata' | ||
}, | ||
"site_list": { | ||
'path': '/api/v2.0/site_lists', | ||
'postformat': 'formdata' | ||
}, | ||
"site_lists": { | ||
'path': '/api/v2.0/site_lists', | ||
'postformat': 'formdata' | ||
}, | ||
"site_placement": { | ||
'path': '/api/v2.0/site_placement', | ||
'postformat': 'formdata' | ||
}, | ||
"site_placements": { | ||
'path': '/api/v2.0/site_placement', | ||
'postformat': 'formdata' | ||
}, | ||
"strategy": { | ||
'path': '/api/v2.0/strategies', | ||
'postformat': 'formdata' | ||
}, | ||
"strategies": { | ||
'path': '/api/v2.0/strategies', | ||
'postformat': 'formdata' | ||
}, | ||
"strategy_concept": { | ||
'path': '/api/v2.0/strategy_concepts', | ||
'postformat': 'formdata' | ||
}, | ||
"strategy_concepts": { | ||
'path': '/api/v2.0/strategy_concepts', | ||
'postformat': 'formdata' | ||
}, | ||
"strategy_day_part": { | ||
'path': '/api/v2.0/strategy_day_parts', | ||
'postformat': 'formdata' | ||
}, | ||
"strategy_day_parts": { | ||
'path': '/api/v2.0/strategy_day_parts', | ||
'postformat': 'formdata' | ||
}, | ||
"strategy_domain": { | ||
'path': '/api/v2.0/strategy_domains', | ||
'postformat': 'formdata' | ||
}, | ||
"strategy_domains": { | ||
'path': '/api/v2.0/strategy_domains', | ||
'postformat': 'formdata' | ||
}, | ||
"strategy_supply_source": { | ||
'path': '/api/v2.0/strategy_supply_sources', | ||
'postformat': 'formdata' | ||
}, | ||
"strategy_supply_sources": { | ||
'path': '/api/v2.0/strategy_supply_sources', | ||
'postformat': 'formdata' | ||
}, | ||
"target_dimension": { | ||
'path': '/api/v2.0/target_dimensions', | ||
'postformat': 'formdata' | ||
}, | ||
"target_dimensions": { | ||
'path': '/api/v2.0/target_dimensions', | ||
'postformat': 'formdata' | ||
}, | ||
"target_value": { | ||
'path': '/api/v2.0/target_values', | ||
'postformat': 'formdata' | ||
}, | ||
"target_values": { | ||
'path': '/api/v2.0/target_values', | ||
'postformat': 'formdata' | ||
}, | ||
"targeting_vendor": { | ||
'path': '/api/v2.0/targeting_vendors', | ||
'postformat': 'formdata' | ||
}, | ||
"targeting_vendors": { | ||
'path': '/api/v2.0/targeting_vendors', | ||
'postformat': 'formdata' | ||
}, | ||
"user": { | ||
'path': '/api/v2.0/users', | ||
'postformat': 'formdata' | ||
}, | ||
"users": { | ||
'path': '/api/v2.0/users', | ||
'postformat': 'formdata' | ||
}, | ||
"vendor": { | ||
'path': '/api/v2.0/vendors', | ||
'postformat': 'formdata' | ||
}, | ||
"vendors": { | ||
'path': '/api/v2.0/vendors', | ||
'postformat': 'formdata' | ||
}, | ||
"vendor_contract": { | ||
'path': '/api/v2.0/vendor_contracts', | ||
'postformat': 'formdata' | ||
}, | ||
"vendor_contracts": { | ||
'path': '/api/v2.0/vendor_contracts', | ||
'postformat': 'formdata' | ||
}, | ||
"vendor_domain": { | ||
'path': '/api/v2.0/vendor_domains', | ||
'postformat': 'formdata' | ||
}, | ||
"vendor_domains": { | ||
'path': '/api/v2.0/vendor_domains', | ||
'postformat': 'formdata' | ||
}, | ||
"vendor_pixel": { | ||
'path': '/api/v2.0/vendor_pixels', | ||
'postformat': 'formdata' | ||
}, | ||
"vendor_pixels": { | ||
'path': '/api/v2.0/vendor_pixels', | ||
'postformat': 'formdata' | ||
}, | ||
"vendor_pixel_domain": { | ||
'path': '/api/v2.0/vendor_pixel_domains', | ||
'postformat': 'formdata' | ||
}, | ||
"vendor_pixel_domains": { | ||
'path': '/api/v2.0/vendor_pixel_domains', | ||
'postformat': 'formdata' | ||
}, | ||
"vertical": { | ||
'path': '/api/v2.0/verticals', | ||
'postformat': 'formdata' | ||
}, | ||
"verticals": { | ||
'path': '/api/v2.0/verticals', | ||
'postformat': 'formdata' | ||
} | ||
}; | ||
function getEndpoint(entity) { | ||
return entityMap[entity]; | ||
return entityMap[entity].path; | ||
} | ||
function getPostFormat(entity) { | ||
return entityMap[entity].postformat; | ||
} | ||
exports.getEndpoint = getEndpoint; | ||
exports.getPostFormat = getPostFormat; |
'use strict'; | ||
var Config = require('./common/config'); | ||
var csv = require('babyparse'); | ||
@@ -6,0 +3,0 @@ |
@@ -8,10 +8,7 @@ var common = require('./common'); | ||
"properties": { | ||
"advertiser_id": { | ||
"id": "/deal/advertiser_id", | ||
"type": "integer" | ||
"end_datetime": { | ||
"id": "/deal/end_datetime", | ||
"type": "string", | ||
"format": "datetime" | ||
}, | ||
"currency_code": { | ||
"id": "/deal/currency_code", | ||
"type": "string" | ||
}, | ||
"deal_identifier": { | ||
@@ -21,13 +18,5 @@ "id": "/deal/deal_identifier", | ||
}, | ||
"deal_source": { | ||
"id": "/deal/deal_source", | ||
"enum": [ | ||
"USER", | ||
"INTERNAL" | ||
], | ||
"default": "INTERNAL" | ||
}, | ||
"description": { | ||
"id": "/deal/description", | ||
"type": "string" | ||
"type": ["string", "null"] | ||
}, | ||
@@ -37,22 +26,72 @@ "start_datetime": { | ||
"type": "string", | ||
"format": "datetimezone" | ||
"format": "datetime" | ||
}, | ||
"end_datetime": { | ||
"id": "/deal/end_datetime", | ||
"type": "string", | ||
"format": "datetimezone" | ||
"permissions": { | ||
"type": "object", | ||
"properties": { | ||
"all_organizations": { | ||
"id": "/deal/permissions/all_organizations", | ||
"type": "boolean" | ||
}, | ||
"agency_ids": { | ||
"id": "/deal/permissions/agency_ids", | ||
"type": "array", | ||
"items": { | ||
"type": "integer" | ||
}, | ||
"minItems": 0, | ||
"uniqueItems": true | ||
}, | ||
"organization_ids": { | ||
"id": "/deal/permissions/organization_ids", | ||
"type": "array", | ||
"items": { | ||
"type": "integer" | ||
}, | ||
"minItems": 0, | ||
"uniqueItems": true | ||
}, | ||
"advertiser_ids": { | ||
"id": "/deal/permissions/advertiser_ids", | ||
"type": "array", | ||
"items": { | ||
"type": "integer" | ||
}, | ||
"minItems": 0, | ||
"uniqueItems": true | ||
} | ||
} | ||
}, | ||
"media_type": { | ||
"id": "/deal/media_type", | ||
"enum": [ | ||
"DISPLAY", | ||
"VIDEO" | ||
], | ||
"default": "DISPLAY" | ||
"owner": { | ||
"type": "object", | ||
"properties": { | ||
"type": { | ||
"id": "/deal/owner/type", | ||
"enum": [ | ||
"INTERNAL", | ||
"ORGANIZATION", | ||
"AGENCY", | ||
"ADVERTISER" | ||
] | ||
}, | ||
"id": { | ||
"id": "/deal/price/id", | ||
"type": "integer" | ||
} | ||
} | ||
}, | ||
"partner_sourced": { | ||
"id": "/deal/partner_sourced", | ||
"type": "boolean" | ||
"price": { | ||
"type": "object", | ||
"properties": { | ||
"value": { | ||
"id": "/deal/price/value", | ||
"type": "string", | ||
"pattern": "[0-9]+(\.[0-9]+)?" | ||
}, | ||
"currency_code": { | ||
"id": "/deal/price/currency_code", | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"price": common.currency_array, | ||
"price_method": { | ||
@@ -72,6 +111,2 @@ "id": "/deal/price_method", | ||
}, | ||
"publisher_id": { | ||
"id": "/deal/publisher_id", | ||
"type": "integer" | ||
}, | ||
"status": { | ||
@@ -83,7 +118,7 @@ "id": "/deal/status", | ||
"id": "/deal/supply_source_id", | ||
"type": "integer" | ||
"type": ["integer", "null"] | ||
}, | ||
"zone_name": { | ||
"id": "/deal/zone_name", | ||
"type": "string" | ||
"sub_supply_source_id": { | ||
"id": "/deal/sub_supply_source_id", | ||
"type": ["integer", "null"] | ||
}, | ||
@@ -93,4 +128,3 @@ "created_on": { | ||
"type": "string", | ||
"format": "datetimezone", | ||
"readonly": true | ||
"format": "datetime" | ||
}, | ||
@@ -100,20 +134,16 @@ "updated_on": { | ||
"type": "string", | ||
"format": "datetimezone", | ||
"readonly": true | ||
"format": "datetime" | ||
} | ||
}, | ||
"required": [ | ||
"advertiser_id", | ||
"start_datetime", | ||
"end_datetime", | ||
"deal_identifier", | ||
"media_type", | ||
"name", | ||
"owner", | ||
"permissions", | ||
"price", | ||
"price_method", | ||
"price_method", | ||
"price_type", | ||
"publisher_id", | ||
"status", | ||
"supply_source_id" | ||
"status" | ||
] | ||
@@ -120,0 +150,0 @@ }, |
@@ -57,3 +57,3 @@ "use strict"; | ||
return connection.post(endpoint, form).then(function (body) { | ||
return connection.postFormdata(endpoint, form).then(function (body) { | ||
that.price_estimate = JSON.parse(body).data.prop[0]; | ||
@@ -60,0 +60,0 @@ return that; |
@@ -53,3 +53,3 @@ "use strict"; | ||
return connection.post(endpoint, form).then(function (body) { | ||
return connection.postFormdata(endpoint, form).then(function (body) { | ||
that.price_estimate = JSON.parse(body).data.prop[0]; | ||
@@ -56,0 +56,0 @@ return that; |
@@ -0,143 +1,139 @@ | ||
"use strict"; | ||
var RequestPromise = require('request-promise'); | ||
var QueryString = require('querystring'); | ||
var Config = require('./common/config'); | ||
var BPromise = require('bluebird'); | ||
var OauthService = require('simple-oauth2'); | ||
var T1Connection = function (t1config) { | ||
this.cookieAuthed = false; | ||
this.t1config = t1config; | ||
var pkg = require('../package.json'); | ||
this.requestHeaders = { | ||
'Accept': 'application/vnd.mediamath.v1+json', | ||
'User-Agent': pkg.name + '-node/' + pkg.version | ||
}; | ||
var T1Connection = function(t1config) { | ||
this.t1config = t1config; | ||
this.baseUrl = t1config.baseUrl || 'https://api.mediamath.com/'; | ||
var pkg = require('../package.json'); | ||
this.requestHeaders = { | ||
'Accept': 'application/vnd.mediamath.v1+json', | ||
'User-Agent': pkg.name + '-node/' + pkg.version | ||
}; | ||
}; | ||
if (!t1config.apiBaseUrl) { | ||
this.t1config.apiBaseUrl = Config.apiBaseUrl; | ||
T1Connection.prototype.ensureAuthenticated = function() { | ||
var that = this; | ||
return BPromise.try(function() { | ||
if (!that.requestHeaders.adama_session || !that.requestHeaders.Authorization) { | ||
if (that.t1config.preferCookieAuth !== true) { | ||
return that.getOAuthToken(); | ||
} else { | ||
return that.getCookieSession(); | ||
} | ||
} | ||
}); | ||
}; | ||
T1Connection.prototype.ensureAuthenticated = function () { | ||
var that = this; | ||
return BPromise.try(function () { | ||
if (!that.cookieAuthed && this.oauth2 === undefined) { | ||
return RequestPromise.post({ | ||
jar: true, | ||
url: that.t1config.apiBaseUrl + "/api/v2.0/login", | ||
headers: that.requestHeaders, | ||
withCredentials: true, | ||
form: { | ||
user: that.t1config.user, | ||
password: that.t1config.password, | ||
api_key: that.t1config.api_key | ||
} | ||
}).then(function () { | ||
that.cookieAuthed = true; | ||
}).catch(function (error) { | ||
console.error("a connection error occurred: " + error.message); | ||
}); | ||
T1Connection.prototype.getCookieSession = function() { | ||
var that = this; | ||
} else if (that.oauth2) { | ||
if (that.oauth2Token) { | ||
if (that.oauth2Token.expired()) { | ||
that.oauth2Token.refresh() | ||
.then((result) => { | ||
that.oauth2Token = result; | ||
if (that.tokenUpdatedCallback !== undefined) { | ||
that.tokenUpdatedCallback(result.token); | ||
} | ||
}); | ||
} | ||
} | ||
else { | ||
BPromise.reject("No oauth2 token! Ensure the " + | ||
"oauth2 flow is completed by calling getToken()"); | ||
} | ||
} | ||
}); | ||
let request = RequestPromise.post({ | ||
jar: true, | ||
url: this.baseUrl + 'api/v2.0/login', | ||
headers: that.requestHeaders, | ||
withCredentials: true, | ||
form: { | ||
user: that.t1config.user, | ||
password: that.t1config.password, | ||
api_key: that.t1config.api_key | ||
} | ||
}).then(function(result) { | ||
return JSON.parse(result); | ||
}).catch(function(error) { | ||
console.error('a connection error occurred: ' + error.message); | ||
}); | ||
return request; | ||
}; | ||
T1Connection.prototype.initializeOauth = function (tokenUpdatedCallback) { | ||
var that = this; | ||
var credentials = { | ||
client: { | ||
id: that.t1config.api_key, | ||
secret: that.t1config.client_secret | ||
}, | ||
auth: { | ||
tokenHost: Config.apiBaseUrl, | ||
tokenPath: 'oauth2/v1.0/token', | ||
authorizePath: 'oauth2/v1.0/authorize' | ||
}, | ||
http: { | ||
headers: that.requestHeaders | ||
} | ||
}; | ||
that.tokenUpdatedCallback = tokenUpdatedCallback; | ||
that.oauth2 = OauthService.create(credentials); | ||
}; | ||
T1Connection.prototype.getOAuthToken = function() { | ||
var that = this; | ||
// Call to start off the oauth2 flow | ||
T1Connection.prototype.fetchAuthUrl = function (tokenUpdatedCallback) { | ||
var that = this; | ||
if (!that.oauth2) { | ||
that.initializeOauth(tokenUpdatedCallback); | ||
let credentials = { | ||
client: { | ||
id: this.t1config.client_id, | ||
secret: this.t1config.client_secret | ||
}, | ||
auth: { | ||
tokenHost: 'https://sso.mediamath.auth0.com', | ||
tokenPath: '/oauth/token' | ||
}, | ||
options: { | ||
useBasicAuthorizationHeader: false | ||
} | ||
return this.oauth2.authorizationCode.authorizeURL({ | ||
redirect_uri: that.t1config.redirect_uri | ||
}; | ||
if (that.t1config.environment === 'dev') { | ||
credentials.auth.tokenHost = 'https://sso.mediamath-dev.auth0.com'; | ||
} | ||
let tokenConfig = { | ||
username: that.t1config.user, | ||
password: that.t1config.password, | ||
scope: 'openid profile' | ||
}; | ||
var OAuthConnection = OauthService.create(credentials); | ||
return OAuthConnection.ownerPassword | ||
.getToken(tokenConfig) | ||
.then((result) => { | ||
const token = OAuthConnection.accessToken.create(result); | ||
that.requestHeaders.Authorization = 'Bearer ' + token.token.id_token; | ||
}); | ||
}; | ||
// your application should redirect to the T1 user authorisation URL fetched | ||
// from fetchAuthUrl(). T1 will then 301 to your redirect_uri with a 'code' URL param. | ||
// Use that code to obtain the access token. The flow is now complete. | ||
// t1-node will handle setting the bearer headers, and renewing access. | ||
T1Connection.prototype.getToken = function (code) { | ||
var that = this; | ||
that.tokenConfig = { | ||
code: code, | ||
redirect_uri: that.t1config.redirect_uri | ||
}; | ||
return that.oauth2.authorizationCode.getToken(that.tokenConfig) | ||
.then((result) => { | ||
that.oauth2Token = that.oauth2.accessToken.create(result); | ||
}); | ||
T1Connection.prototype.copyHeaders = function(source, sink) { | ||
Object.keys(source).forEach(function(key) { | ||
sink[key] = source[key]; | ||
}); | ||
}; | ||
T1Connection.prototype.copyHeaders = function (source, sink) { | ||
Object.keys(source).forEach(function (key) { | ||
sink[key] = source[key]; | ||
T1Connection.prototype.get = function(endpoint) { | ||
// Check if there's a full path going in here, and fix it. | ||
if (endpoint.includes(this.baseUrl)) { | ||
endpoint = endpoint.substring(this.baseUrl.length, endpoint.length); | ||
} | ||
var options = { | ||
jar: true, | ||
headers: this.requestHeaders, | ||
url: this.baseUrl + endpoint, | ||
withCredentials: true | ||
}; | ||
return this.ensureAuthenticated() | ||
.then(function() { | ||
return RequestPromise.get(options); | ||
}); | ||
}; | ||
T1Connection.prototype.get = function (endpoint) { | ||
var options = { | ||
jar: true, | ||
headers: this.requestHeaders, | ||
url: this.t1config.apiBaseUrl + endpoint, | ||
withCredentials: true | ||
T1Connection.prototype.getSession = function() { | ||
return this.get('session'); | ||
}; | ||
T1Connection.prototype.postFormdata = function (endpoint, form) { | ||
var formdata = QueryString.stringify(form); | ||
var contentLength = formdata.length; | ||
var postHeaders = { | ||
'Content-Length': contentLength, | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
}; | ||
return this.ensureAuthenticated() | ||
.then(function () { | ||
return RequestPromise.get(options); | ||
}); | ||
return this._post(endpoint, postHeaders, formdata); | ||
}; | ||
T1Connection.prototype.getSession = function () { | ||
return this.get('session'); | ||
T1Connection.prototype.postJson = function (endpoint, json) { | ||
var postHeaders = { | ||
'Content-Type': 'application/json' | ||
}; | ||
return this._post(endpoint, postHeaders, json); | ||
}; | ||
T1Connection.prototype.post = function (endpoint, form) { | ||
T1Connection.prototype._post = function (endpoint, headers, data) { | ||
var that = this; | ||
var formData = QueryString.stringify(form); | ||
var contentLength = formData.length; | ||
var postHeaders = { | ||
'Content-Length': contentLength, | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
}; | ||
if (this.oauth2Token) { | ||
postHeaders.Authorization = 'Bearer ' + this.oauth2Token.token.access_token; | ||
headers.Authorization = 'Bearer ' + this.oauth2Token.token.access_token; | ||
} | ||
this.copyHeaders(this.requestHeaders, postHeaders); | ||
this.copyHeaders(this.requestHeaders, headers); | ||
return this.ensureAuthenticated() | ||
@@ -148,5 +144,5 @@ .then(function () { | ||
withCredentials: true, | ||
headers: postHeaders, | ||
headers: headers, | ||
url: that.t1config.apiBaseUrl + endpoint, | ||
body: formData | ||
body: data | ||
} | ||
@@ -157,37 +153,35 @@ ); | ||
T1Connection.prototype.buildQueryString = function (baseUrl, userParams) { | ||
var endpoint = baseUrl; | ||
if (!userParams) { | ||
userParams = {}; | ||
} | ||
userParams.api_key = this.t1config.api_key !== undefined ? this.t1config.api_key : 'noapikey'; | ||
T1Connection.prototype.buildQueryString = function(baseUrl, userParams) { | ||
var endpoint = baseUrl; | ||
if (!userParams) { | ||
userParams = {}; | ||
} | ||
userParams.api_key = this.t1config.api_key !== undefined ? this.t1config.api_key : 'noapikey'; | ||
var urlParams = []; | ||
if (userParams.limit !== undefined) { | ||
var entity = Object.keys(userParams.limit)[0]; | ||
endpoint += ('/limit/' + entity + | ||
'=' + userParams.limit[entity]); | ||
var urlParams = []; | ||
if (userParams.limit !== undefined) { | ||
var entity = Object.keys(userParams.limit)[0]; | ||
endpoint += ('/limit/' + entity + | ||
'=' + userParams.limit[entity]); | ||
} | ||
for (var p in userParams) { | ||
if (!userParams.hasOwnProperty(p)) { | ||
continue; | ||
} | ||
for (var p in userParams) { | ||
if (!userParams.hasOwnProperty(p)) { | ||
continue; | ||
} | ||
if (p === 'limit') { | ||
//skip | ||
} | ||
else if (p === 'with') { | ||
urlParams.push(userParams[p].map(function (i) { | ||
return 'with=' + i; | ||
}).join('&')); | ||
} | ||
else { | ||
urlParams.push(encodeURIComponent(p) + "=" + encodeURIComponent(userParams[p])); | ||
} | ||
if (p === 'limit') { | ||
//skip | ||
} else if (p === 'with') { | ||
urlParams.push(userParams[p].map(function(i) { | ||
return 'with=' + i; | ||
}).join('&')); | ||
} else { | ||
urlParams.push(encodeURIComponent(p) + '=' + encodeURIComponent(userParams[p])); | ||
} | ||
} | ||
if (Object.keys(userParams).length > 0) { | ||
endpoint += '?' + urlParams.join("&"); | ||
} | ||
if (Object.keys(userParams).length > 0) { | ||
endpoint += '?' + urlParams.join('&'); | ||
} | ||
return endpoint; | ||
return endpoint; | ||
}; | ||
@@ -194,0 +188,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"license": "Apache-2.0", | ||
"version": "0.6.2", | ||
"version": "0.7.0", | ||
"engines": { | ||
@@ -8,0 +8,0 @@ "node": ">= 0.12" |
@@ -8,3 +8,3 @@ t1-node | ||
#### From npm | ||
` npm install terminalone ` | ||
` npm install @mediamath/terminalone ` | ||
#### From source | ||
@@ -60,5 +60,10 @@ Checkout, then `npm install .` | ||
.get(1234, connection) | ||
.then(function(agency) {this.agency = agency}); | ||
agency.name = 'new name'; | ||
agency.save(connection).done(console.log('saved')); | ||
.then(function(agency) { | ||
agency = agency; | ||
agency.name = 'new name'; | ||
return agency.save(connection) | ||
}) | ||
.then(function () { | ||
console.log('saved')}) | ||
.catch(error => console.log(error)); | ||
``` | ||
@@ -74,6 +79,12 @@ | ||
}; | ||
t1.EntityList.get('campaigns', connection, userParams).then(function(list) {this.pg1 = list}); | ||
t1.EntityList.getNextPage(pg1, connection).then(function(list) {this.pg2 = list}); | ||
for (var entity of pg1.entities) {console.log(entity)} | ||
var that = this; | ||
t1.EntityList.get('campaigns', connection, userParams) | ||
.then(function(list) { | ||
that.pg1 = list; | ||
return t1.EntityList.getNextPage(pg1, connection) | ||
}) | ||
.then(function(list) { | ||
that.pg2 = list; | ||
for (var entity of list.entities) {console.log(entity)}}); | ||
``` | ||
@@ -87,9 +98,9 @@ | ||
var userParams = { | ||
'page_limit':10 | ||
'page_limit':10, | ||
'with':['strategies'] | ||
}; | ||
t1.EntityList.get('campaigns', connection, userParams).then(function(list) {this.pg1 = list}); | ||
t1.EntityList.getNextPage(pg1, connection).then(function(list) {this.pg2 = list}); | ||
for (var entity of pg1.entities) {console.log(entity)} | ||
var that = this; | ||
t1.EntityList.get('campaigns', connection, userParams).then(function(list) { | ||
that.pg1 = list; | ||
for (var entity of list.entities) {console.log(entity)}}); | ||
``` | ||
@@ -113,3 +124,3 @@ | ||
targetingSegments.exclude_op = 'OR'; | ||
targetingSegments.save(connection).done(console.log('saved')); | ||
targetingSegments.save(connection).then(function () { console.log('saved') }); | ||
``` | ||
@@ -129,3 +140,3 @@ | ||
targetValues.addTargetValues('REGN', 'INCLUDE', 'OR', [23, 251]); | ||
targetValues.save(connection).done(console.log('saved')); | ||
targetValues.save(connection).then(function () { console.log('saved') }); | ||
``` | ||
@@ -147,3 +158,3 @@ | ||
targetingSegments.exclude_op = 'OR'; | ||
targetingSegments.save(connection).done(console.log('saved')); | ||
targetingSegments.save(connection).then(function () { console.log('saved') }); | ||
``` | ||
@@ -150,0 +161,0 @@ |
@@ -103,3 +103,3 @@ var BPromise = require('bluebird'); | ||
var amt = campaign.getCurrencyValue('goal_value'); | ||
var form = campaign._getPostData(); | ||
var form = campaign._getPostFormData(); | ||
@@ -106,0 +106,0 @@ return expect(form).to.eventually |
@@ -1,2 +0,2 @@ | ||
var BPromise = require('bluebird'); | ||
"use strict"; | ||
var expect = require('./chai_config').expect; | ||
@@ -7,31 +7,23 @@ var sinon = require('sinon'); | ||
describe("entityList", function () { | ||
var connectionStub = {}; | ||
connectionStub.get = function () { | ||
}; | ||
connectionStub.post = function () { | ||
}; | ||
connectionStub.buildQueryString = function () { | ||
return ""; | ||
}; | ||
var sandbox, getStub, postStub; | ||
var parsedResult = "aisdaiusd"; | ||
var service = t1.EntityList; | ||
beforeEach(function () { | ||
sandbox = sinon.sandbox.create(); | ||
var t1config = {}; | ||
postStub = sandbox.stub(connectionStub, "post") | ||
.returns(BPromise.try(function () { | ||
return parsedResult; | ||
})); | ||
}); | ||
class ConnectionStub { | ||
afterEach(function () { | ||
sandbox.restore(); | ||
}); | ||
get() { | ||
}; | ||
post() { | ||
return "" | ||
}; | ||
buildQueryString(base, userParams) { | ||
var t1Connection = new t1.T1Connection(t1config); | ||
return t1Connection.buildQueryString(base, userParams) | ||
}; | ||
} | ||
describe("#get with count", function () { | ||
@@ -41,39 +33,40 @@ var userParams = {'page_limit': 10}; | ||
it("should have 10 entities", function () { | ||
parsedResult = common.loadFixture('campaigns-10'); | ||
let parsedResult = common.loadFixture('campaigns-10'); | ||
getStub = sandbox.stub(connectionStub, "get") | ||
.returns(BPromise.try(function () { | ||
return parsedResult; | ||
})); | ||
var campaigns = service.get('campaigns', connectionStub, userParams); | ||
return expect(campaigns).to.eventually | ||
.have.property('entities') && | ||
let conn = new ConnectionStub(); | ||
expect(campaigns).to.eventually | ||
.have.property('meta') | ||
.and.have.property('count', userParams.page_limit); | ||
sinon.stub(conn, 'get') | ||
.resolves(parsedResult); | ||
return service.get('campaigns', conn, userParams).then(function (data) { | ||
expect(data).to.have.property('meta') | ||
.and.have.property('count', userParams.page_limit); | ||
expect(conn.get.called).to.equal(true); | ||
expect(conn.get.getCall(0).args[0]).equal("/api/v2.0/campaigns?page_limit=10&api_key=noapikey"); | ||
} | ||
); | ||
}); | ||
}); | ||
describe("#get first page", function () { | ||
describe("#get next page", function () { | ||
var userParams = {}; | ||
it("should have 100 entities", function () { | ||
parsedResult = common.loadFixture('campaigns-100'); | ||
it("should have request the correct next page of entities", function () { | ||
let parsedResult = common.loadFixture('campaigns-100'); | ||
getStub = sandbox.stub(connectionStub, "get") | ||
.returns(BPromise.try(function () { | ||
return parsedResult; | ||
})); | ||
var campaigns = service.get('campaigns', connectionStub, userParams); | ||
let conn = new ConnectionStub(); | ||
return expect(campaigns).to.eventually | ||
.have.property('entities') && | ||
expect(campaigns).to.eventually | ||
.have.property('meta').and.have.property('next_page'); | ||
sinon.stub(conn, 'get') | ||
.resolves(parsedResult); | ||
return service.get('campaigns', conn, userParams).then(function (page1) { | ||
return service.getNextPage(page1, conn) | ||
}).then(function (page2) { | ||
expect(conn.get.callCount).to.equal(2) | ||
expect(conn.get.getCall(1).args[0]).equal("https://api.mediamath.com/api/v2.0/campaigns?page_offset=100&api_key=noapikey"); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -55,3 +55,3 @@ { | ||
"meta": { | ||
"next_page": "https://api.mediamath.com/api/v2.0/campaigns?page_offset=100&api_key=q6su6nn9fjsamr37p5tv5kc5", | ||
"next_page": "https://api.mediamath.com/api/v2.0/campaigns?page_offset=10&api_key=noapikey", | ||
"etag": "2f5baa394203cee2b85dfac0f179bb6e5b8e4022", | ||
@@ -58,0 +58,0 @@ "count": 10, |
@@ -505,3 +505,3 @@ { | ||
"meta": { | ||
"next_page": "https://api.mediamath.com/api/v2.0/campaigns?page_offset=100&api_key=q6su6nn9fjsamr37p5tv5kc5", | ||
"next_page": "https://api.mediamath.com/api/v2.0/campaigns?page_offset=100&api_key=noapikey", | ||
"etag": "2f5baa394203cee2b85dfac0f179bb6e5b8e4022", | ||
@@ -508,0 +508,0 @@ "count": 100, |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
94
10.59%206
5.64%258122
-93.19%5961
-94.57%24
60%