faithlife-api
Advanced tools
Comparing version 0.3.1 to 0.4.0
@@ -32,3 +32,3 @@ /*! | ||
AccountsApiClient.prototype.getLoggedInUser = function getLoggedInUser() { | ||
return this.get('/v2/users/me'); | ||
return this.get('/v1/users/me').then(); | ||
}; | ||
@@ -41,3 +41,3 @@ | ||
AccountsApiClient.prototype.getUser = function getUser(userId) { | ||
return this.get('/v2/users/' + userId); | ||
return this.get('/v1/users/' + userId).then(); | ||
}; | ||
@@ -50,3 +50,3 @@ | ||
AccountsApiClient.prototype.createGroup = function createGroup(group) { | ||
return this.post('/v2/groups', group); | ||
return this.post('/v1/groups').send(group).then(); | ||
}; | ||
@@ -59,3 +59,3 @@ | ||
AccountsApiClient.prototype.getGroup = function getGroup(groupIdOrToken) { | ||
return this.get('/v2/groups/' + groupIdOrToken); | ||
return this.get('/v1/groups/' + groupIdOrToken).then(); | ||
}; | ||
@@ -68,3 +68,3 @@ | ||
AccountsApiClient.prototype.getGroupsForUser = function getGroupsForUser(userId) { | ||
return this.get('/v2/users/' + userId + '/groups'); | ||
return this.get('/v1/users/' + userId + '/groups').then(); | ||
}; | ||
@@ -71,0 +71,0 @@ |
@@ -5,5 +5,7 @@ /*! | ||
*/ | ||
var express = require('express'); | ||
var https = require('https'); | ||
var url = require('url'); | ||
var mi = require('mi'); | ||
var makeRequest = require('./request'); | ||
var superagent = require('superagent'); | ||
var superagentThen = require('superagent-then'); | ||
@@ -57,6 +59,12 @@ /** | ||
/** | ||
* Make a `method` request to `path` with the `body` entity as the body, | ||
* returning a promise to be fulfilled with the Response or rejected with | ||
* and HTTP error. | ||
* Creates a Promise-ready Superagent Request. For most requests: | ||
* | ||
* 1. `request.send()` should be used to provide a body. | ||
* 1. `request.then()` should be used (it's Promises/A+ compatible) to capture | ||
* the response or error. Otherwise (if it's a fire-and-forget request), | ||
* `request.end()` must be used to flush the socket and complete the request. | ||
* | ||
* See [https://github.com/visionmedia/superagent]() for more information on | ||
* the methods available to Requests. | ||
* | ||
* NOTE: A successfully-made request may not have been responded to with a | ||
@@ -66,3 +74,3 @@ * successful (200-ish) status code. Please check the status code in an | ||
*/ | ||
BaseApiClient.prototype.request = function request(method, path, body) { | ||
BaseApiClient.prototype.request = function request(method, path) { | ||
path = this.getUrl(path); | ||
@@ -72,13 +80,7 @@ | ||
return makeRequest({ | ||
method: method, | ||
url: path, | ||
headers: { | ||
Authorization: this._authorization | ||
}, | ||
content: body | ||
}) | ||
.then(null, function (err) { | ||
return superagent(method, path) | ||
.set('Authorization', this._authorization) | ||
.use(superagentThen) | ||
.on('error', function (err) { | ||
console.error('Error in %s %s: %s', method, path, err); | ||
throw err; | ||
}); | ||
@@ -91,4 +93,4 @@ }; | ||
*/ | ||
BaseApiClient.prototype.get = function get(path, body) { | ||
return this.request('GET', path, body); | ||
BaseApiClient.prototype.get = function get(path) { | ||
return this.request('GET', path); | ||
}; | ||
@@ -100,4 +102,4 @@ | ||
*/ | ||
BaseApiClient.prototype.post = function post(path, body) { | ||
return this.request('POST', path, body); | ||
BaseApiClient.prototype.post = function post(path) { | ||
return this.request('POST', path); | ||
}; | ||
@@ -109,4 +111,4 @@ | ||
*/ | ||
BaseApiClient.prototype.put = function put(path, body) { | ||
return this.request('PUT', path, body); | ||
BaseApiClient.prototype.put = function put(path) { | ||
return this.request('PUT', path); | ||
}; | ||
@@ -118,4 +120,4 @@ | ||
*/ | ||
BaseApiClient.prototype.del = function del(path, body) { | ||
return this.request('DELETE', path, body); | ||
BaseApiClient.prototype.del = function del(path) { | ||
return this.request('DELETE', path); | ||
}; | ||
@@ -129,14 +131,24 @@ | ||
var self = this; | ||
var app = express(); | ||
var app = require('express')(); | ||
app.use(function (request, response, next) { | ||
var child = self.getChild({ | ||
auth: request.authorization | ||
var parsedUrl = url.parse(self.getUrl(request.path)); | ||
var outgoing = https.request({ | ||
method: request.method, | ||
hostname: parsedUrl.hostname, | ||
path: parsedUrl.path, | ||
headers: { | ||
'Authorization': request.authorization | ||
} | ||
}); | ||
return child.request(request.method, request.path, request.body) | ||
.then(function (data) { | ||
response.set(data.headers); | ||
response.send(data.status, data.content); | ||
}); | ||
outgoing.on('response', function (incoming) { | ||
response.status(incoming.statusCode); | ||
response.set(incoming.headers); | ||
incoming.pipe(response); | ||
}); | ||
request.pipe(outgoing); | ||
outgoing.end(); | ||
}); | ||
@@ -143,0 +155,0 @@ |
@@ -0,5 +1,7 @@ | ||
var BaseApiClient = require('./base'); | ||
var AccountsApiClient = require('./accounts'); | ||
module.exports = { | ||
Client: BaseApiClient, | ||
Accounts: AccountsApiClient | ||
}; |
{ | ||
"name": "faithlife-api", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "A collection of CommonJS modules for interacting with the Faithlife API.", | ||
@@ -17,3 +17,4 @@ "main": "lib/index.js", | ||
"mi": "~1.0.0", | ||
"superagent": "~0.18.2", | ||
"superagent": "git://github.com/Schoonology/superagent", | ||
"superagent-then": "~1.0.0", | ||
"when": "~3.4.4" | ||
@@ -20,0 +21,0 @@ }, |
Git dependency
Supply chain riskContains a dependency which resolves to a remote git URL. Dependencies fetched from git URLs are not immutable and can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
9387
6
8
267
1
1
+ Addedsuperagent-then@~1.0.0
+ Addedsuperagent-then@1.0.1(transitive)