node-freeagent2
Advanced tools
Comparing version 0.0.5 to 0.0.6
// Generated by CoffeeScript 1.3.3 | ||
var FreeAgent, crypto, proxyUrl, qs, request, _; | ||
(function() { | ||
var FreeAgent, crypto, proxyUrl, qs, request, _; | ||
request = require('request'); | ||
request = require('request'); | ||
crypto = require('crypto'); | ||
crypto = require('crypto'); | ||
qs = require('querystring'); | ||
qs = require('querystring'); | ||
_ = require('underscore'); | ||
_ = require('underscore'); | ||
proxyUrl = process.env.HTTPS_PROXY || process.env.https_proxy; | ||
proxyUrl = process.env.HTTPS_PROXY || process.env.https_proxy; | ||
FreeAgent = (function() { | ||
FreeAgent = (function() { | ||
function FreeAgent(access_token, sandboxMode) { | ||
this.access_token = access_token; | ||
if (sandboxMode) { | ||
this.baseUri = 'https://api.sandbox.freeagent.com/v2/'; | ||
} else { | ||
this.baseUri = 'https://api.freeagent.com/v2/'; | ||
function FreeAgent(access_token, sandboxMode) { | ||
this.access_token = access_token; | ||
if (sandboxMode) { | ||
this.baseUri = 'https://api.sandbox.freeagent.com/v2/'; | ||
} else { | ||
this.baseUri = 'https://api.freeagent.com/v2/'; | ||
} | ||
} | ||
} | ||
FreeAgent.prototype._prepareHeaders = function(access_token, options) { | ||
if (!options) { | ||
options = {}; | ||
} | ||
return _.extend(options, { | ||
proxy: proxyUrl, | ||
headers: { | ||
'Accept': 'application/json', | ||
'User-Agent': 'node-freeagent2', | ||
'Authorization': "Bearer " + access_token | ||
FreeAgent.prototype._prepareHeaders = function(access_token, options) { | ||
if (!options) { | ||
options = {}; | ||
} | ||
}); | ||
}; | ||
return _.extend(options, { | ||
proxy: proxyUrl, | ||
headers: { | ||
'Accept': 'application/json', | ||
'User-Agent': 'node-freeagent2', | ||
'Authorization': "Bearer " + access_token | ||
} | ||
}); | ||
}; | ||
FreeAgent.prototype.getCompany = function(callback) { | ||
return this._getRequest('company', null, function(error, data) { | ||
return callback(error, data.company); | ||
}); | ||
}; | ||
FreeAgent.prototype._getRequest = function(url, options, callback) { | ||
var requestUri; | ||
requestUri = this.baseUri + url; | ||
if (options) { | ||
requestUri += '?' + qs.stringify(options); | ||
} | ||
return request.get(this._prepareHeaders(this.access_token, { | ||
uri: requestUri, | ||
json: true | ||
}), function(error, response, body) { | ||
if (!error) { | ||
if (response.statusCode < 400) { | ||
return callback(null, body); | ||
} else { | ||
return callback(new Error("" + response.statusCode + " : " + body)); | ||
} | ||
} else { | ||
return callback(error); | ||
} | ||
}); | ||
}; | ||
FreeAgent.prototype.getProjects = function(callback) { | ||
return this._getRequest('projects', null, callback); | ||
}; | ||
FreeAgent.prototype.getUsers = function(callback) { | ||
return this._getRequest('users', null, callback); | ||
}; | ||
FreeAgent.prototype.getUserProfile = function(callback) { | ||
return this._getRequest('users/me', null, callback); | ||
}; | ||
FreeAgent.prototype._getRequest = function(url, options, callback) { | ||
var requestUri; | ||
requestUri = this.baseUri + url; | ||
if (options) { | ||
requestUri += '?' + qs.stringify(options); | ||
} | ||
return request.get(this._prepareHeaders(this.access_token, { | ||
uri: requestUri, | ||
json: true | ||
}), function(error, response, body) { | ||
if (!error) { | ||
if (response.statusCode < 400) { | ||
return callback(null, body); | ||
FreeAgent.prototype._processParams = function(optionsOrCallback, callback) { | ||
if (typeof optionsOrCallback === 'function') { | ||
return { | ||
options: null, | ||
callback: optionsOrCallback | ||
}; | ||
} else { | ||
if (callback) { | ||
return { | ||
options: optionsOrCallback, | ||
callback: callback | ||
}; | ||
} else { | ||
return callback(new Error("" + response.statusCode + " : " + body)); | ||
throw new Error("No callback defined!"); | ||
} | ||
} else { | ||
return callback(error); | ||
} | ||
}); | ||
}; | ||
}; | ||
return FreeAgent; | ||
FreeAgent.prototype.getCompany = function(optionsOrCallback, callback) { | ||
var params; | ||
params = this._processParams(optionsOrCallback, callback); | ||
return this._getRequest('company', params.options, function(error, data) { | ||
if (!error && data && data.company) { | ||
return params.callback(null, data.company); | ||
} else { | ||
return params.callback(error); | ||
} | ||
}); | ||
}; | ||
})(); | ||
FreeAgent.prototype.getProjects = function(optionsOrCallback, callback) { | ||
var params; | ||
params = this._processParams(optionsOrCallback, callback); | ||
return this._getRequest('projects', params.options, params.callback); | ||
}; | ||
module.exports = FreeAgent; | ||
FreeAgent.prototype.getProjectWithId = function(projectUri, optionsOrCallback, callback) { | ||
var params; | ||
params = this._processParams(optionsOrCallback, callback); | ||
return this._getRequest('projects/' + projectUri, params.options, params.callback); | ||
}; | ||
FreeAgent.prototype.getTasksForProject = function(projectUri, optionsOrCallback, callback) { | ||
var params; | ||
params = this._processParams(optionsOrCallback, callback); | ||
return this._getRequest('tasks/' + projectUri, params.options, params.callback); | ||
}; | ||
FreeAgent.prototype.getUsers = function(optionsOrCallback, callback) { | ||
var params; | ||
params = this._processParams(optionsOrCallback, callback); | ||
return this._getRequest('users', params.options, params.callback); | ||
}; | ||
FreeAgent.prototype.getTimeslips = function(optionsOrCallback, callback) { | ||
var params; | ||
params = this._processParams(optionsOrCallback, callback); | ||
return this._getRequest('timeslips', params.options, params.callback); | ||
}; | ||
FreeAgent.prototype.getInvoices = function(optionsOrCallback, callback) { | ||
var params; | ||
params = this._processParams(optionsOrCallback, callback); | ||
return this._getRequest('invoices', params.options, params.callback); | ||
}; | ||
FreeAgent.prototype.getInvoicesForProject = function(projectUri, optionsOrCallback, callback) { | ||
var params; | ||
params = this._processParams(optionsOrCallback, callback); | ||
return this._getRequest('invoices', _.extend(params.options, { | ||
project: projectUri | ||
}), params.callback); | ||
}; | ||
return FreeAgent; | ||
})(); | ||
module.exports = FreeAgent; | ||
}).call(this); |
@@ -12,3 +12,3 @@ // Generated by CoffeeScript 1.3.3 | ||
baseUri = "https://api.sandbox.freeagent.com/v2/"; | ||
baseUri = "https://api.freeagent.com/v2/"; | ||
@@ -15,0 +15,0 @@ Strategy = function(options, verify) { |
{ | ||
"name": "node-freeagent2", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Node.js OAuth2 REST Library for use with the FreeAgent v2 API, with Passport Authentication Strategy", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
20682
162
0