t1-node
Node implementation of a T1 API Library. Uses Bluebird for fast, simple callback handling via promises.
Compilation/Installation
From npm
npm install terminalone
From source
Checkout, then npm install .
Usage
For cookie authentication:
var t1 = ;var config ='user': t1_username'password': t1_user_password'api_key': application_mashery_key;var connection = config;
For oauth2 authentication, your web application will need to redirect to the T1 user authentication page during the process. The approach is outlined below:
var t1 = ;//the callback URL should match the one you specified in the developer portal for your applicationvar config ='api_key': application_mashery_key'client_secret': application_mashery_secret'redirect_uri': application_callback_urlvar connection = config;// tokenUpdatedCallback is an optional callback to a function, taking// a single argument which describes an access token.// This can be used update your token databse on automatic token refresh.var authorizationUrl = connection;// Redirect example using Express (see http://expressjs.com/api.html#res.redirect)res;var code = // Get the access token object (the authorization code is given from the previous step).connection;
Single Entities
Retrieve, edit and save a single entity
var agencyPromise = 'agency';agencyname = 'new name';agency;
Entity Lists
Returns a generator to entities
var userParams ='page_limit':10;t1EntityList;t1EntityList;for var entity of pg1entities console
Related entities
It's possible to include related entities by including in a 'with' property in userParams.
var userParams ='page_limit':10'with':'strategies';t1EntityList;t1EntityList;for var entity of pg1entities console
Targeting
Strategy Target Segments
To get a strategy's targeting segments:
var targetingSegmentsPromise =;
To edit strategy targeting segments:
targetingSegmentsinclude = 1 'OR';targetingSegmentsexclude = 119 'OR';targetingSegmentsinclude_op = 'OR';targetingSegmentsexclude_op = 'OR';targetingSegments;
Strategy Target Dimensions/Values
To get a strategy's targeting values:
var targetValuesPromise =;
To edit strategy targeting segments:
targetValuesinclude = 1 'OR';targetValues;targetValues;
=======
Strategy Audience Segments
To get a strategy's audience segments:
var audienceSegmentsPromise =;
To edit strategy audience segments:
audienceSegmentsinclude = 1405158;audienceSegmentsexclude = 1405158;targetingSegmentsinclude_op = 'OR';targetingSegmentsexclude_op = 'OR';targetingSegments;