ubivar
Advanced tools
Comparing version 0.1.3-beta7 to 0.1.3-beta8
{ | ||
"name": "ubivar", | ||
"version": "0.1.3-beta7", | ||
"version": "0.1.3-beta8", | ||
"description": "API wrapper to Ubivar", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -27,23 +27,18 @@ # Ubivar node.js bindings | ||
Every resource is accessed via your `ubivar` instance: | ||
Every resource is accessed via your `ubivar` instance and accepts an optional | ||
callback as the last argument. The sample code below retrieves your account | ||
information (as json) and updates the primary phone with a random value. | ||
```js | ||
var Ubivar = require("ubivar") | ||
, ubivar = new Ubivar("your-token", "your-api-version") | ||
``` | ||
, ubivar = new Ubivar("YOUR_API_ACCESS_TOKEN", "latest") | ||
, rval = Math.random() | ||
Every resource accepts an optional callback as the last argument. | ||
ubivar.retrieve.me(function(err, res){ | ||
console.log(err, res) | ||
```js | ||
ubivar.accounts.create( { | ||
"user_id" : "test_123" | ||
, "session_id" : "test_session_id_123" | ||
, "user_email" : "test_email@email-123.com" | ||
, "first_name" : "test_yourfirstname_123" | ||
, "last_name" : "test_yourlastname_123" | ||
, "primary_phone" : "+123456789-123" | ||
}, function(err, resource){ | ||
err // null if no error | ||
resource // the created resource (account) | ||
ubivar.update.me({"primary_phone":rval}, function(err, res){ | ||
console.log(err, res) | ||
}) | ||
}) | ||
``` | ||
@@ -50,0 +45,0 @@ |
@@ -124,2 +124,4 @@ "use strict" | ||
it("Should create and return a resource", function(done){ | ||
@@ -180,13 +182,119 @@ ubivar[resource].create(example[0], function(err, res){ | ||
it("Should list the resources", function(done){ | ||
var params = {"start_after": 0, "end_before": 1} | ||
, nList = params.end_before - params.start_after | ||
describe("Should list and paginate", function(){ | ||
var ids = [] | ||
ubivar[resource].list(params, function(err, res){ | ||
if(res.status === 200 && res.data.length === nList){ | ||
before(function(done){ | ||
var example = require("../data/"+resource) | ||
this.timeout(5000) | ||
ubivar[resource].create(example[0], function(err, res){ | ||
if(err) return done(err) | ||
ids.push(res.data[0].id) | ||
ubivar[resource].create(example[0], function(err, res){ | ||
if(err) return done(err) | ||
ids.push(res.data[0].id) | ||
ubivar[resource].create(example[0], function(err, res){ | ||
if(err) return done(err) | ||
ids.push(res.data[0].id) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
it("Should limit retrieved resources to N=1", function(done){ | ||
var nLimit = 1 | ||
ubivar[resource].list({limit:nLimit}, function(err, res){ | ||
if(err) done(err) | ||
else if(res.data.length === nLimit) done() | ||
else done(new Error("Should 'limit' list to N="+nLimit+" resources")) | ||
}) | ||
}) | ||
it("Should limit retrieved resources to N=2", function(done){ | ||
var nLimit = 2 | ||
ubivar[resource].list({limit:nLimit}, function(err, res){ | ||
if(err) done(err) | ||
else if(res.data.length === nLimit) done() | ||
else done(new Error("Should 'limit' list to N="+nLimit+" resources")) | ||
}) | ||
}) | ||
it("Should 'start_after' when paginating", function(done){ | ||
var nLimit = 2 | ||
ubivar[resource].list({"start_after": ids[0], "limit":nLimit}, function(err, res){ | ||
if(err) return done(err) | ||
if(res.data.length !== nLimit) return done(new Error("Should return N="+nLimit)) | ||
var returnedIds = _.pluck(res.data, "id") | ||
if(_.contains(returnedIds, ids[0])){ | ||
return done(new Error("Should not return 'starting_after' id")) | ||
} | ||
done() | ||
} else { | ||
done(new Error("Did not return a list of " + resource)) | ||
} | ||
}) | ||
}) | ||
it("Should 'start_after' and 'end_before' when paginating", function(done){ | ||
var nLimit = 1 | ||
ubivar[resource].list({"end_before": ids[2], "start_after":ids[0]}, function(err, res){ | ||
if(err) return done(err) | ||
if(res.data.length !== nLimit){ | ||
console.log(res.data);return done(new Error("Should return N="+nLimit)) | ||
} | ||
var returnedIds = _.pluck(res.data, "id") | ||
if(_.contains(returnedIds, ids[1])) return done() | ||
else return done(new Error("Should not return 'starting_after' id")) | ||
}) | ||
}) | ||
it("Should list ids greater than (gt) a given id", function(done){ | ||
var nLimit = 2 | ||
, object = {"id":{"gt":ids[0]}, "limit":nLimit} | ||
ubivar[resource].list(object, function(err, res){ | ||
if(err) return done(err) | ||
if(res.data.length !== nLimit) return done(new Error("Should return N="+nLimit)) | ||
var returnedIds = _.pluck(res.data, "id") | ||
if(_.contains(returnedIds, ids[1]) && _.contains(returnedIds, ids[2])){ | ||
return done() | ||
} | ||
return done(new Error("Should contain the right ids")) | ||
}) | ||
}) | ||
it("Should list and order DESC the ids that are less than (lt) an id", function(done){ | ||
var nLimit = 2 | ||
ubivar[resource].list({"id":{"lt":ids[2]}, "order":"-id", "limit":nLimit}, function(err, res){ | ||
if(err) return done(err) | ||
if(res.data.length !== nLimit) return done(new Error("Should return N="+nLimit)) | ||
var returnedIds = _.pluck(res.data, "id") | ||
if(_.contains(returnedIds, ids[0]) && _.contains(returnedIds, ids[1]) && !_.contains(returnedIds,ids[2])){ | ||
return done() | ||
} | ||
return done(new Error("Should contain the right ids")) | ||
}) | ||
}) | ||
it("Should list ids greater than or equal (gte) to a given id", function(done){ | ||
var nLimit = 3 | ||
ubivar[resource].list({"id":{"gte":ids[0]}, "limit":nLimit}, function(err, res){ | ||
if(err) return done(err) | ||
if(res.data.length !== nLimit) return done(new Error("Should return N="+nLimit)) | ||
var returnedIds = _.pluck(res.data, "id") | ||
if(_.contains(returnedIds, ids[0]) && _.contains(returnedIds, ids[1]) && _.contains(returnedIds, ids[2])){ | ||
return done() | ||
} | ||
return done(new Error("Should contain the right ids")) | ||
}) | ||
}) | ||
it("Should list and order DESC the ids that are less than or equal (lte) an id", function(done){ | ||
var nLimit = 3 | ||
ubivar[resource].list({"id":{"lte":ids[2]}, "order":"-id", "limit":nLimit}, function(err, res){ | ||
if(err) return done(err) | ||
if(res.data.length !== nLimit) return done(new Error("Should return N="+nLimit)) | ||
var returnedIds = _.pluck(res.data, "id") | ||
if(_.contains(returnedIds, ids[0]) && _.contains(returnedIds, ids[1]) && _.contains(returnedIds,ids[2])){ | ||
return done() | ||
} | ||
return done(new Error("Should contain the right ids")) | ||
}) | ||
}) | ||
}) | ||
@@ -193,0 +301,0 @@ }) |
37872
850
108
10