Commit f6cf7583 by Alex MacCaw

Add flagging API.

parent 7c23e29a
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
var assert = require('assert'); var assert = require('assert');
var resource = require('./resource'); var resource = require('./resource');
var _ = require('lodash');
function requireEmail (options) { function requireEmail (options) {
assert(options.email, 'An email must be provided'); assert(options.email, 'An email must be provided');
...@@ -12,7 +13,17 @@ exports.Person = resource.create('Person', { ...@@ -12,7 +13,17 @@ exports.Person = resource.create('Person', {
path: '/people/email/<%= email %>', path: '/people/email/<%= email %>',
queryKeys: 'subscribe' 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', { exports.PersonCompany = resource.create('PersonCompany', {
api: 'person', api: 'person',
......
...@@ -27,7 +27,12 @@ ClearbitResource.find = Promise.method(function (options) { ...@@ -27,7 +27,12 @@ ClearbitResource.find = Promise.method(function (options) {
}, options)) }, options))
.bind(this) .bind(this)
.then(function (data) { .then(function (data) {
return new this(data); return new this(
_.extend({}, data, {
_options: this._options,
client: this.client
})
);
}) })
.catch(isQueued, function () { .catch(isQueued, function () {
throw new this.QueuedError(this._name + ' lookup queued'); throw new this.QueuedError(this._name + ' lookup queued');
...@@ -48,7 +53,7 @@ exports.create = function (name, options) { ...@@ -48,7 +53,7 @@ exports.create = function (name, options) {
var Resource = function () { var Resource = function () {
ClearbitResource.apply(this, arguments); ClearbitResource.apply(this, arguments);
}; };
_.extend(Resource, new EventEmitter(), EventEmitter.prototype, ClearbitResource, createErrors(name), { _.extend(Resource, new EventEmitter(), EventEmitter.prototype, ClearbitResource, createErrors(name), {
_name: name, _name: name,
_options: _.extend({}, options, { _options: _.extend({}, options, {
...@@ -65,6 +70,11 @@ exports.create = function (name, options) { ...@@ -65,6 +70,11 @@ exports.create = function (name, options) {
on: function () { on: function () {
Resource.on.apply(Resource, arguments); Resource.on.apply(Resource, arguments);
return this; return this;
},
include: function (props) {
_.extend(Resource.prototype, props);
return this;
} }
}); });
}; };
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