Commit dae8cdfb by Alex MacCaw

Add discovery API. Move Person/Company under Enrichment

parent 613bc437
......@@ -16,9 +16,10 @@ function ClearbitClient (config) {
this.key = config.key || process.env.CLEARBIT_KEY;
assert(!!this.key, 'An API key must be provided');
this.Company = require('./company').Company(this);
this.Person = require('./person').Person(this);
this.PersonCompany = require('./person').PersonCompany(this);
this.Enrichment = require('./enrichment').Enrichment(this);
this.Company = require('./enrichment/company').Company(this);
this.Person = require('./enrichment/person').Person(this);
this.Discovery = require('./discovery').Discovery(this);
this.Watchlist = require('./watchlist').Watchlist(this);
this.WatchlistCandidate = require('./watchlist').WatchlistCandidate(this);
this.WatchlistEntity = require('./watchlist').WatchlistEntity(this);
......
'use strict';
var assert = require('assert');
var resource = require('./resource');
var _ = require('lodash');
exports.Discovery = resource.create('Discovery', {api: 'discovery'})
.extend(null, {
search: function (options) {
options = options || {};
return this.post(
'/companies/search',
options
);
}
});
'use strict';
var assert = require('assert');
var resource = require('./resource');
var _ = require('lodash');
var Company = require('./enrichment/company');
var Person = require('./enrichment/person');
exports.Enrichment = resource.create('Enrichment', {api: 'person'})
.extend(null, {
find: function(options){
options = options || {};
if (options.domain)
return Company.find(options);
assert(options.email, 'An email must be provided');
return this.get(
'/combined/email/' + options.email,
_.omit(options, 'email')
);
},
Company: Company,
Person: Person
});
'use strict';
var assert = require('assert');
var resource = require('./resource');
var resource = require('../resource');
var _ = require('lodash');
exports.Company = resource.create('Company', {api: 'company'})
......
'use strict';
var assert = require('assert');
var resource = require('./resource');
var resource = require('../resource');
var _ = require('lodash');
exports.Person = resource.create('Person', {api: 'person'})
......@@ -21,16 +21,3 @@ exports.Person = resource.create('Person', {api: 'person'})
);
}
});
exports.PersonCompany = resource.create('PersonCompany', {api: 'person'})
.extend(null, {
find: function(options){
options = options || {};
assert(options.email, 'An email must be provided');
return this.get(
'/combined/email/' + options.email,
_.omit(options, 'email')
);
}
});
......@@ -30,7 +30,8 @@ ClearbitResource.post = function (path, options) {
options = _.extend({
path: path,
method: 'post',
query: extractParams(options)
json: true,
body: extractParams(options)
}, this.options, options);
return this.client.request(options)
......
'use strict';
var expect = require('chai').use(require('chai-as-promised')).expect;
var nock = require('nock');
var Discovery = require('../')('k').Discovery;
describe('Discovery', function () {
var mock;
before(function () {
mock = nock('https://discovery.clearbit.com');
});
after(nock.cleanAll);
afterEach(function () {
mock.done();
});
var fixtures = require('./fixtures/discovery');
describe('Discovery#search', function () {
it('can search for companies', function () {
mock
.post('/v1/companies/search')
.reply(200, fixtures);
return Discovery.search({query: {name: 'uber'}})
.then(function (result) {
expect(result.results)
.to.deep.equal(fixtures.results);
});
});
});
});
{
"page": 0,
"total": 1,
"results": [{
"id": "027b0d40-016c-40ea-8925-a076fa640992",
"name": "Uber",
"legalName": "Uber, Inc.",
"domain": "uber.com",
"url": "http://uber.com",
"site": {
"url": "http://uber.com",
"title": null,
"h1": null,
"meta_description": null,
"meta_author": null
},
"categories": [
"Transportation",
"Design",
"SEO",
"Automotive",
"Real Time",
"Limousines",
"Public Transportation",
"Transport"
],
"description": "Uber is a mobile app connecting passengers with drivers for hire.",
"founders": [
"Travis Kalanick",
"Garrett Camp"
],
"raised": 1500000000.0,
"location": "San Francisco, California, U.S.",
"google": {
"rank": 7
},
"alexa": {
"usRank": 2730,
"globalRank": 2567
},
"facebook": {
"handle": "uber.IND"
},
"linkedin": {
"handle": "company/uber.com"
},
"twitter": {
"handle": "uber",
"id": 19103481,
"bio": "Everyone's Private Driver. Question, concern or praise? Tweet at your local community manager here: https://t.co/XdHQjJXn :)",
"followers": 155226,
"following": 325,
"location": "Global",
"site": "http://t.co/PtMbwFTeQA",
"avatar": "https://pbs.twimg.com/profile_images/378800000762572812/91ea09a6535666e18ca3c56f731f67ef_normal.jpeg"
},
"employees": 200,
"logo": "http://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/Uber_logotype.svg/220px-Uber_logotype.svg.png",
"personal": false
}]
}
......@@ -3,7 +3,7 @@
var expect = require('chai').use(require('chai-as-promised')).expect;
var nock = require('nock');
var Person = require('../')('k').Person;
var PersonCompany = require('../')('k').PersonCompany;
var Enrichment = require('../')('k').Enrichment;
describe('Person', function () {
......@@ -66,7 +66,7 @@ describe('Person', function () {
});
describe('PersonCompany#find', function () {
describe('Enrichment#find', function () {
it('can find a person by email', function () {
mock
......@@ -75,10 +75,10 @@ describe('Person', function () {
person: alex,
company: company
});
return PersonCompany.find({email: 'alex@alexmaccaw.com'})
return Enrichment.find({email: 'alex@alexmaccaw.com'})
.then(function (personCompany) {
expect(personCompany)
.to.be.an.instanceOf(PersonCompany)
.to.be.an.instanceOf(Enrichment)
.and.have.include.keys('person', 'company')
.and.have.deep.property('person.id', alex.id);
});
......@@ -92,8 +92,8 @@ describe('Person', function () {
type: 'queued'
}
});
return expect(PersonCompany.find({email: 'alex@alexmaccaw.com'}))
.to.be.rejectedWith(PersonCompany.QueuedError);
return expect(Enrichment.find({email: 'alex@alexmaccaw.com'}))
.to.be.rejectedWith(Enrichment.QueuedError);
});
});
......
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