Commit 17ac5d7a by 3rd-Eden

[fix] Always default to the "old" rates

[fix] Added missing callback [fix] Allow the API to be rewritten
parent 86554d76
......@@ -69,9 +69,9 @@ FullContact.prototype.request = function req(packet, args) {
, self = this;
request(packet, function requested(err, res, body) {
self.ratereset = +res.headers['X-Rate-Limit-Reset'];
self.ratelimit = +res.headers['X-Rate-Limit-Limit'];
self.remaining = +res.headers['X-Rate-Limit-Remaining'];
self.ratereset = +res.headers['X-Rate-Limit-Reset'] || self.ratereste;
self.ratelimit = +res.headers['X-Rate-Limit-Limit'] || self.ratelimit;
self.remaining = +res.headers['X-Rate-Limit-Remaining'] || self.remaining;
if (err) return fn(err);
......@@ -96,6 +96,8 @@ FullContact.prototype.request = function req(packet, args) {
return fn(err);
}
fn(undefined, body);
});
return this;
......@@ -207,8 +209,9 @@ FullContact.prototype.args = function parser(args) {
*/
FullContact.define = function define(where, name, fn) {
Object.defineProperty(where, name, {
configurable: true,
get: function get() {
return where[name] = fn();
return where[name] = fn.call(this);
},
set: function set(value) {
Object.defineProperty(where, name, {
......
......@@ -10,7 +10,54 @@ describe('FullContact', function () {
//
var key = process.env.API_KEY;
//
// Some of the requests take a really long time, so set a really long timeout
//
this.timeout(20000);
it('exposes the createClient api which initializes the constructor', function () {
var api = FullContact.createClient(key);
expect(api).to.be.instanceOf(FullContact);
});
it('exposes the Person constructor', function () {
expect(FullContact.Person).to.be.a('function');
});
it('exposes the Location constructor', function () {
expect(FullContact.Location).to.be.a('function');
});
it('exposes the Email constructor', function () {
expect(FullContact.Email).to.be.a('function');
});
it('exposes the Name constructor', function () {
expect(FullContact.Name).to.be.a('function');
});
it('sets the x-rate properties on request', function (done) {
var fc = new FullContact(key);
['remaining', 'ratelimit', 'ratereset'].forEach(function (prop) {
expect(fc[prop]).to.equal(0);
});
fc.person.email('arnout@observe.it', function normalize(err, data) {
if (err) return done(err);
['remaining', 'ratelimit', 'ratereset'].forEach(function (prop) {
expect(fc[prop]).to.not.equal(0);
expect(fc[prop]).to.be.a('number');
});
done();
});
});
it('decreases the rate remaining on request');
it('errors when an invalid API key is given');
it('does batch requests');
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment