Commit 59fddd1b by Alex MacCaw

Merge pull request #6 from clearbit/alex-add-flag

Add flagging API.
parents 7c23e29a 42d03e78
......@@ -2,6 +2,7 @@
var assert = require('assert');
var resource = require('./resource');
var _ = require('lodash');
function requireEmail (options) {
assert(options.email, 'An email must be provided');
......@@ -12,7 +13,17 @@ exports.Person = resource.create('Person', {
path: '/people/email/<%= email %>',
queryKeys: 'subscribe'
})
.on('preFind', requireEmail);
.on('preFind', requireEmail)
.include({
flag: function(params, options){
return this.client.request(_.extend({
api: this._options.api,
method: 'post',
path: _.template('/people/<%= id %>/flag', this),
query: params || {}
}, options));
}
});
exports.PersonCompany = resource.create('PersonCompany', {
api: 'person',
......
......@@ -27,7 +27,12 @@ ClearbitResource.find = Promise.method(function (options) {
}, options))
.bind(this)
.then(function (data) {
return new this(data);
return new this(
_.extend({}, data, {
_options: this._options,
client: this.client
})
);
})
.catch(isQueued, function () {
throw new this.QueuedError(this._name + ' lookup queued');
......@@ -48,7 +53,7 @@ exports.create = function (name, options) {
var Resource = function () {
ClearbitResource.apply(this, arguments);
};
_.extend(Resource, new EventEmitter(), EventEmitter.prototype, ClearbitResource, createErrors(name), {
_name: name,
_options: _.extend({}, options, {
......@@ -65,6 +70,11 @@ exports.create = function (name, options) {
on: function () {
Resource.on.apply(Resource, arguments);
return this;
},
include: function (props) {
_.extend(Resource.prototype, props);
return this;
}
});
};
......@@ -79,7 +79,7 @@ describe('Person', function () {
.then(function (personCompany) {
expect(personCompany)
.to.be.an.instanceOf(PersonCompany)
.and.have.have.keys('person', 'company')
.and.have.include.keys('person', 'company')
.and.have.deep.property('person.id', alex.id);
});
});
......
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