UNPKG

okanjo

Version:

Integrate your application with the Okanjo API.

1,399 lines (1,283 loc) 154 kB
/* * Date: 1/26/16 11:59 AM * * ---- * * (c) Okanjo Partners Inc * https://okanjo.com * support@okanjo.com * * https://github.com/okanjo/okanjo-nodejs * * ---- * * TL;DR? see: http://www.tldrlegal.com/license/mit-license * * The MIT License (MIT) * Copyright (c) 2013 Okanjo Partners Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ var Provider = require('../src/provider'), Query = require('../src/query'); /** * SDK Base * @param {object} [config] Client options * @namespace * @constructor */ function Client(config) { // Allow client to be initialized as: var api = new Client("api_key"); if (typeof config === "string") { config = { key: config }; } else { config = config || {}; } this.config = config; // Connect the right default provider based on runtime context if (typeof config.provider === "function") { // Context is provided in the config - use the constructor as-is this.provider = new config.provider(this); } else { // Detect context if (process.browser) { // Running in browser - default to proxy mode //this.provider = new (require('../src/providers/jquery_provider'))(this); this.provider = new (require('../src/providers/fetch_provider'))(this); } else { // Running in Node - Use the HTTP provider by default to make real requests this.provider = new (require('../src/providers/http_provider'))(this); } } // Attach resources for (var i = 0; i < Client.resourceBinders.length; i++) { Client.resourceBinders[i](this); } } /** * SDK Version */ Client.Version = '5.1.0'; /** * Expose the Provider base class * @type {Provider} */ Client.Provider = Provider; /** * Expose the Query base class * @type {Query} */ Client.Query = Query; /** * Routes a request through the client's registered transport provider * @param {object} spec - Query specifications * @param {function} callback * @return {Query} - A compiled query, ready to rock and roll, or be modified and executed yourself */ Client.prototype._makeRequest = function(spec, callback) { // Build the query var query = new Query(this.config, spec); // Compile the query this.provider.compile(query); // If we have a callback, execute the request if (callback) { query.execute(callback); } // Return the query for reuse or manual execution return query; }; /** * Container for resource binder functions * @type {Array} */ Client.resourceBinders = []; module.exports = Client; /* istanbul ignore next: generated code */ Client.resourceBinders.push(function(Client) { /** * Accounts * @namespace Client.accounts */ Client.accounts = { /** * Registers a new Okanjo account * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.accounts# */ create: function(payload, callback) { return Client._makeRequest({ api: 'api', action: 'account.create', method: 'POST', path: '/accounts', payload: payload }, callback); }, /** * Retrieves an account * @param {string} account_id – Object identifier. * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.accounts# */ retrieve: function(account_id, callback) { return Client._makeRequest({ api: 'api', action: 'account.retrieve', method: 'GET', path: '/accounts/{account_id}', pathParams: { account_id: account_id } }, callback); }, /** * Returns manageable accounts, or accounts on a given resource. * @param {object} [query] - Filter arguments * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.accounts# */ list: function(query, callback) { // Shift optional arguments, if necessary if (typeof query === "function") { callback = query; query = undefined; } return Client._makeRequest({ api: 'api', action: 'account.list', method: 'GET', path: '/accounts', query: query }, callback); }, /** * Updates an account * @param {string} account_id – Object identifier. * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.accounts# */ update: function(account_id, payload, callback) { return Client._makeRequest({ api: 'api', action: 'account.update', method: 'PUT', path: '/accounts/{account_id}', pathParams: { account_id: account_id }, payload: payload }, callback); }, /** * Sets the oauth binding on behalf of an account by platform administrators * @param {string} account_id – Object identifier. * @param {string} provider – OAuth provider * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.accounts# */ bind_oauth: function(account_id, provider, payload, callback) { return Client._makeRequest({ api: 'api', action: 'account.bind_oauth', method: 'PUT', path: '/accounts/{account_id}/oauth/{provider}', pathParams: { account_id: account_id, provider: provider }, payload: payload }, callback); }, /** * Deregister an account with an OAuth provider * @param {string} account_id – Object identifier. * @param {string} provider – OAuth provider * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.accounts# */ deregister_oauth: function(account_id, provider, callback) { return Client._makeRequest({ api: 'api', action: 'account.deregister_oauth', method: 'DELETE', path: '/accounts/{account_id}/oauth/{provider}', pathParams: { account_id: account_id, provider: provider } }, callback); }, /** * Requests a password reset for an account with the given email address * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.accounts# */ recover: function(payload, callback) { return Client._makeRequest({ api: 'api', action: 'account.recover', method: 'POST', path: '/accounts/recover', payload: payload }, callback); }, /** * Register an account with an OAuth provider * @param {string} account_id – Object identifier. * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.accounts# */ register_oauth: function(account_id, payload, callback) { return Client._makeRequest({ api: 'api', action: 'account.register_oauth', method: 'POST', path: '/accounts/{account_id}/oauth', pathParams: { account_id: account_id }, payload: payload }, callback); }, /** * Retrieves an account's access control list. This provides an overview of what the account has access to. * @param {string} account_id – Account id for the acl to be retrieved. * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.accounts# */ retrieve_acl: function(account_id, callback) { return Client._makeRequest({ api: 'api', action: 'account.retrieve_acl', method: 'GET', path: '/accounts/{account_id}/acl', pathParams: { account_id: account_id } }, callback); } }; /** * Ads * @namespace Client.ads */ Client.ads = { /** * Returns content to fill a placement. * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.ads# */ fill: function(payload, callback) { return Client._makeRequest({ api: 'api', action: 'ads.fill', method: 'POST', path: '/content', payload: payload }, callback); } }; /** * Articles * @namespace Client.articles */ Client.articles = { /** * Creates an article for distribution * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.articles# */ create: function(payload, callback) { return Client._makeRequest({ api: 'api', action: 'article.create', method: 'POST', path: '/articles', payload: payload }, callback); }, /** * Retrieves an article * @param {alternatives} url_or_id – URL or ID of the article * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.articles# */ retrieve: function(url_or_id, callback) { return Client._makeRequest({ api: 'api', action: 'article.retrieve', method: 'GET', path: '/articles/{url_or_id}', pathParams: { url_or_id: url_or_id } }, callback); }, /** * Lists articles that meet the given criteria. * @param {object} [query] - Filter arguments * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.articles# */ list: function(query, callback) { // Shift optional arguments, if necessary if (typeof query === "function") { callback = query; query = undefined; } return Client._makeRequest({ api: 'api', action: 'article.list', method: 'GET', path: '/articles', query: query }, callback); }, /** * Modifies an article * @param {alternatives} url_or_id – URL or ID of the article * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.articles# */ update: function(url_or_id, payload, callback) { return Client._makeRequest({ api: 'api', action: 'article.update', method: 'PUT', path: '/articles/{url_or_id}', pathParams: { url_or_id: url_or_id }, payload: payload }, callback); }, /** * Follows the article URL. * @param {string} article_id – ID of the article * @param {object} [query] - Filter arguments * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.articles# */ follow: function(article_id, query, callback) { // Shift optional arguments, if necessary if (typeof query === "function") { callback = query; query = undefined; } return Client._makeRequest({ api: 'api', action: 'article.follow', method: 'GET', path: '/articles/{article_id}/follow', pathParams: { article_id: article_id }, query: query }, callback); }, /** * Retrieves an article's content * @param {alternatives} url_or_id – URL or ID of the article * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.articles# */ retrieve_content: function(url_or_id, callback) { return Client._makeRequest({ api: 'api', action: 'article.retrieve_content', method: 'GET', path: '/articles/{url_or_id}/content', pathParams: { url_or_id: url_or_id } }, callback); } }; /** * Creatives * @namespace Client.creatives */ Client.creatives = { /** * Creates a creative * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.creatives# */ create: function(payload, callback) { return Client._makeRequest({ api: 'api', action: 'creative.create', method: 'POST', path: '/creatives', payload: payload }, callback); }, /** * Retrieves a creative * @param {string} creative_id – Object identifier. * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.creatives# */ retrieve: function(creative_id, callback) { return Client._makeRequest({ api: 'api', action: 'creative.retrieve', method: 'GET', path: '/creatives/{creative_id}', pathParams: { creative_id: creative_id } }, callback); }, /** * Lists creatives * @param {object} [query] - Filter arguments * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.creatives# */ list: function(query, callback) { // Shift optional arguments, if necessary if (typeof query === "function") { callback = query; query = undefined; } return Client._makeRequest({ api: 'api', action: 'creative.list', method: 'GET', path: '/creatives', query: query }, callback); }, /** * Updates a creative * @param {string} creative_id – Object identifier. * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.creatives# */ update: function(creative_id, payload, callback) { return Client._makeRequest({ api: 'api', action: 'creative.update', method: 'PUT', path: '/creatives/{creative_id}', pathParams: { creative_id: creative_id }, payload: payload }, callback); }, /** * Deletes a creative * @param {string} creative_id – Object identifier. * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.creatives# */ delete: function(creative_id, callback) { return Client._makeRequest({ api: 'api', action: 'creative.delete', method: 'DELETE', path: '/creatives/{creative_id}', pathParams: { creative_id: creative_id } }, callback); }, /** * Follows the click-through URL. * @param {string} creative_id – Object identifier. * @param {object} [query] - Filter arguments * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.creatives# */ follow: function(creative_id, query, callback) { // Shift optional arguments, if necessary if (typeof query === "function") { callback = query; query = undefined; } return Client._makeRequest({ api: 'api', action: 'creative.follow', method: 'GET', path: '/creatives/{creative_id}/follow', pathParams: { creative_id: creative_id }, query: query }, callback); } }; /** * Domains * @namespace Client.domains */ Client.domains = { /** * Associates a domain with the property. * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.domains# */ create: function(payload, callback) { return Client._makeRequest({ api: 'api', action: 'domain.create', method: 'POST', path: '/domains', payload: payload }, callback); }, /** * Retrieves a domain with the given name. * @param {string} domain_name – Fully qualified domain name * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.domains# */ retrieve: function(domain_name, callback) { return Client._makeRequest({ api: 'api', action: 'domain.retrieve', method: 'GET', path: '/domains/{domain_name}', pathParams: { domain_name: domain_name } }, callback); }, /** * List domains with the given criteria. * @param {object} [query] - Filter arguments * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.domains# */ list: function(query, callback) { // Shift optional arguments, if necessary if (typeof query === "function") { callback = query; query = undefined; } return Client._makeRequest({ api: 'api', action: 'domain.list', method: 'GET', path: '/domains', query: query }, callback); }, /** * Updates a domain with the given name. * @param {string} domain_name – Fully qualified domain name * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.domains# */ update: function(domain_name, payload, callback) { return Client._makeRequest({ api: 'api', action: 'domain.update', method: 'PUT', path: '/domains/{domain_name}', pathParams: { domain_name: domain_name }, payload: payload }, callback); }, /** * Dissociates a domain from its associated property. * @param {string} domain_name – Fully qualified domain name * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.domains# */ delete: function(domain_name, callback) { return Client._makeRequest({ api: 'api', action: 'domain.delete', method: 'DELETE', path: '/domains/{domain_name}', pathParams: { domain_name: domain_name } }, callback); } }; /** * Organizations * @namespace Client.organizations */ Client.organizations = { /** * Creates a new organization under the current user. * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.organizations# */ create: function(payload, callback) { return Client._makeRequest({ api: 'api', action: 'organization.create', method: 'POST', path: '/organizations', payload: payload }, callback); }, /** * Gets a particular organization if visible to the current user. * @param {string} org_id – Object identifier. * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.organizations# */ retrieve: function(org_id, callback) { return Client._makeRequest({ api: 'api', action: 'organization.retrieve', method: 'GET', path: '/organizations/{org_id}', pathParams: { org_id: org_id } }, callback); }, /** * Lists organizations visible to the current user. * @param {object} [query] - Filter arguments * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.organizations# */ list: function(query, callback) { // Shift optional arguments, if necessary if (typeof query === "function") { callback = query; query = undefined; } return Client._makeRequest({ api: 'api', action: 'organization.list', method: 'GET', path: '/organizations', query: query }, callback); }, /** * Updates an organization * @param {string} org_id – Object identifier. * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.organizations# */ update: function(org_id, payload, callback) { return Client._makeRequest({ api: 'api', action: 'organization.update', method: 'PUT', path: '/organizations/{org_id}', pathParams: { org_id: org_id }, payload: payload }, callback); } }; /** * Placements * @namespace Client.placements */ Client.placements = { /** * Creates a ProductMatch placement * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.placements# */ create: function(payload, callback) { return Client._makeRequest({ api: 'api', action: 'placement.create', method: 'POST', path: '/placements', payload: payload }, callback); }, /** * Retrieves a ProductMatch placement * @param {string} placement_id – Object identifier. * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.placements# */ retrieve: function(placement_id, callback) { return Client._makeRequest({ api: 'api', action: 'placement.retrieve', method: 'GET', path: '/placements/{placement_id}', pathParams: { placement_id: placement_id } }, callback); }, /** * List ProductMatch placements * @param {object} [query] - Filter arguments * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.placements# */ list: function(query, callback) { // Shift optional arguments, if necessary if (typeof query === "function") { callback = query; query = undefined; } return Client._makeRequest({ api: 'api', action: 'placement.list', method: 'GET', path: '/placements', query: query }, callback); }, /** * Updates a ProductMatch placement * @param {string} placement_id – Object identifier. * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.placements# */ update: function(placement_id, payload, callback) { return Client._makeRequest({ api: 'api', action: 'placement.update', method: 'PUT', path: '/placements/{placement_id}', pathParams: { placement_id: placement_id }, payload: payload }, callback); }, /** * Deletes a ProductMatch placement * @param {string} placement_id – Object identifier. * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.placements# */ delete: function(placement_id, callback) { return Client._makeRequest({ api: 'api', action: 'placement.delete', method: 'DELETE', path: '/placements/{placement_id}', pathParams: { placement_id: placement_id } }, callback); }, /** * Creates a placement test, used for A-B testing. * @param {string} placement_id – Object identifier. * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.placements# */ create_test: function(placement_id, payload, callback) { return Client._makeRequest({ api: 'api', action: 'placement.create_test', method: 'POST', path: '/placements/{placement_id}/tests', pathParams: { placement_id: placement_id }, payload: payload }, callback); }, /** * Deletes a placement test. * @param {string} placement_id – Object identifier. * @param {string} placement_test_id – Object identifier. * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.placements# */ delete_test: function(placement_id, placement_test_id, callback) { return Client._makeRequest({ api: 'api', action: 'placement.delete_test', method: 'DELETE', path: '/placements/{placement_id}/tests/{placement_test_id}', pathParams: { placement_id: placement_id, placement_test_id: placement_test_id } }, callback); }, /** * Updates a placement test. * @param {string} placement_id – Object identifier. * @param {string} placement_test_id – Object identifier. * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.placements# */ update_test: function(placement_id, placement_test_id, payload, callback) { return Client._makeRequest({ api: 'api', action: 'placement.update_test', method: 'PUT', path: '/placements/{placement_id}/tests/{placement_test_id}', pathParams: { placement_id: placement_id, placement_test_id: placement_test_id }, payload: payload }, callback); } }; /** * Platforms * @namespace Client.platforms */ Client.platforms = { /** * Retrieves a platform * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.platforms# */ retrieve: function(callback) { return Client._makeRequest({ api: 'api', action: 'platform.retrieve', method: 'GET', path: '/platform', }, callback); }, /** * Modifies a platform * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.platforms# */ update: function(payload, callback) { return Client._makeRequest({ api: 'api', action: 'platform.update', method: 'PUT', path: '/platform', payload: payload }, callback); } }; /** * Products * @namespace Client.products */ Client.products = { /** * Creates a product * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.products# */ create: function(payload, callback) { return Client._makeRequest({ api: 'api', action: 'product.create', method: 'POST', path: '/products', payload: payload }, callback); }, /** * Retrieves a product * @param {string} product_id – Object identifier. * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.products# */ retrieve: function(product_id, callback) { return Client._makeRequest({ api: 'api', action: 'product.retrieve', method: 'GET', path: '/products/{product_id}', pathParams: { product_id: product_id } }, callback); }, /** * Lists products * @param {object} [query] - Filter arguments * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.products# */ list: function(query, callback) { // Shift optional arguments, if necessary if (typeof query === "function") { callback = query; query = undefined; } return Client._makeRequest({ api: 'api', action: 'product.list', method: 'GET', path: '/products', query: query }, callback); }, /** * Updates a product * @param {string} product_id – Object identifier. * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.products# */ update: function(product_id, payload, callback) { return Client._makeRequest({ api: 'api', action: 'product.update', method: 'PUT', path: '/products/{product_id}', pathParams: { product_id: product_id }, payload: payload }, callback); }, /** * Deletes a product * @param {string} product_id – Object identifier. * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.products# */ delete: function(product_id, callback) { return Client._makeRequest({ api: 'api', action: 'product.delete', method: 'DELETE', path: '/products/{product_id}', pathParams: { product_id: product_id } }, callback); }, /** * Follows the purchase URL. * @param {string} product_id – Object identifier. * @param {object} [query] - Filter arguments * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.products# */ follow: function(product_id, query, callback) { // Shift optional arguments, if necessary if (typeof query === "function") { callback = query; query = undefined; } return Client._makeRequest({ api: 'api', action: 'product.follow', method: 'GET', path: '/products/{product_id}/follow', pathParams: { product_id: product_id }, query: query }, callback); } }; /** * Properties * @namespace Client.properties */ Client.properties = { /** * Creates a new property. * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.properties# */ create: function(payload, callback) { return Client._makeRequest({ api: 'api', action: 'property.create', method: 'POST', path: '/properties', payload: payload }, callback); }, /** * Retrieves a property. * @param {string} property_id – Object identifier. * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.properties# */ retrieve: function(property_id, callback) { return Client._makeRequest({ api: 'api', action: 'property.retrieve', method: 'GET', path: '/properties/{property_id}', pathParams: { property_id: property_id } }, callback); }, /** * Returns accessible properties. * @param {object} [query] - Filter arguments * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.properties# */ list: function(query, callback) { // Shift optional arguments, if necessary if (typeof query === "function") { callback = query; query = undefined; } return Client._makeRequest({ api: 'api', action: 'property.list', method: 'GET', path: '/properties', query: query }, callback); }, /** * Updates a property. * @param {string} property_id – Object identifier. * @param {object} payload - Resource or parameters * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.properties# */ update: function(property_id, payload, callback) { return Client._makeRequest({ api: 'api', action: 'property.update', method: 'PUT', path: '/properties/{property_id}', pathParams: { property_id: property_id }, payload: payload }, callback); } }; /** * Reporting * @namespace Client.reporting */ Client.reporting = { /** * Returns a histogram of clicks in timescale * @param {object} [query] - Filter arguments * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.reportings# */ click_date_histogram: function(query, callback) { // Shift optional arguments, if necessary if (typeof query === "function") { callback = query; query = undefined; } return Client._makeRequest({ api: 'api', action: 'reporting.click_date_histogram', method: 'GET', path: '/reporting/clicks/date-histogram', query: query }, callback); }, /** * Returns the top N results per aggregation group * @param {object} [query] - Filter arguments * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.reportings# */ click_top_n: function(query, callback) { // Shift optional arguments, if necessary if (typeof query === "function") { callback = query; query = undefined; } return Client._makeRequest({ api: 'api', action: 'reporting.click_top_n', method: 'GET', path: '/reporting/clicks/top-n', query: query }, callback); }, /** * Returns a histogram of page metrics in timescale * @param {object} [query] - Filter arguments * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.reportings# */ page_date_histogram: function(query, callback) { // Shift optional arguments, if necessary if (typeof query === "function") { callback = query; query = undefined; } return Client._makeRequest({ api: 'api', action: 'reporting.page_date_histogram', method: 'GET', path: '/reporting/pages/date-histogram', query: query }, callback); }, /** * Returns the complete placement performance report for the given time range * @param {object} [query] - Filter arguments * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.reportings# */ page_report: function(query, callback) { // Shift optional arguments, if necessary if (typeof query === "function") { callback = query; query = undefined; } return Client._makeRequest({ api: 'api', action: 'reporting.page_report', method: 'GET', path: '/reporting/pages/report', query: query }, callback); }, /** * Returns the top N results per aggregation group * @param {object} [query] - Filter arguments * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.reportings# */ page_top_n: function(query, callback) { // Shift optional arguments, if necessary if (typeof query === "function") { callback = query; query = undefined; } return Client._makeRequest({ api: 'api', action: 'reporting.page_top_n', method: 'GET', path: '/reporting/pages/top-n', query: query }, callback); }, /** * Returns a histogram of resource metrics in timescale * @param {object} [query] - Filter arguments * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.reportings# */ resource_date_histogram: function(query, callback) { // Shift optional arguments, if necessary if (typeof query === "function") { callback = query; query = undefined; } return Client._makeRequest({ api: 'api', action: 'reporting.resource_date_histogram', method: 'GET', path: '/reporting/resources/date-histogram', query: query }, callback); }, /** * Returns the complete resource performance report for the given time range * @param {object} [query] - Filter arguments * @param {requestCallback} [callback] – Optional callback. When present, the request is executed * @return {Query} - Compiled query ready for execution * @memberof Client.reportings# */ resource_report: function(query, callback) { // Shift optional arguments, if necessary