UNPKG

okanjo

Version:

Integrate your application with the Okanjo API.

95 lines (85 loc) 2.88 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. */ /** * Request handler * @param {Client} [client] * @constructor */ function Provider(client) { this.client = client; } /** * Compiles the query into an executable request * @param {Query} query – The query to build */ Provider.prototype.compile = function(query) { var provider = this; // Attach execute function to the query query.execute = function(callback) { return provider.execute(query, callback); }; // Future: Attach cache/execute function to the query }; /** * Executes the query * @param {Query} query - The query to execute * @param {requestCallback} callback – Callback to fire when request is completed * @abstract */ Provider.prototype.execute = function(query, callback) { //console.error('Okanjo Base Provider Execute:', query); callback(new Error('Transport provider not implemented'), null); }; /** * Fires the client-given unauthorized hook in the event a response comes back 401-Unauthorized * which generally means, your session is dead, jim. * @param {object} err - The response payload * @param {Query} query - The offending query * @return {*} * @protected */ Provider.prototype._unauthorizedHook = function(err, query) { if (typeof this.client.config.onUnauthorizedResponse === "function") { this.client.config.onUnauthorizedResponse(err, query); } }; /** * @callback requestCallback * @param {object|null} error * @param {object|null} response */ module.exports = Provider;