Commit ee326f30 by Alex MacCaw

Merge pull request #11 from clearbit/alex-discovery

Discovery API
parents 613bc437 73cb13da
...@@ -3,8 +3,9 @@ clearbit-node [![Build Status](https://travis-ci.org/clearbit/clearbit-node.svg? ...@@ -3,8 +3,9 @@ clearbit-node [![Build Status](https://travis-ci.org/clearbit/clearbit-node.svg?
Node library for querying the [Clearbit](https://clearbit.com) business intelligence APIs. Currently supports: Node library for querying the [Clearbit](https://clearbit.com) business intelligence APIs. Currently supports:
* [Person API](https://clearbit.com/docs#person-api) * [Enrichment API](https://clearbit.com/docs#enrichment-api)
* [Company API](https://clearbit.com/docs#company-api) * [Discovery API](https://clearbit.com/docs#discovery-api)
* [Watchlist API](https://clearbit.com/docs#watchlist-api)
## Setup ## Setup
```bash ```bash
......
{ {
"name": "clearbit", "name": "clearbit",
"version": "1.1.3", "version": "1.2.0",
"description": "Client for Clearbit.co business intelligence APIs", "description": "Client for Clearbit.co business intelligence APIs",
"main": "./src", "main": "./src",
"scripts": { "scripts": {
......
...@@ -16,9 +16,10 @@ function ClearbitClient (config) { ...@@ -16,9 +16,10 @@ function ClearbitClient (config) {
this.key = config.key || process.env.CLEARBIT_KEY; this.key = config.key || process.env.CLEARBIT_KEY;
assert(!!this.key, 'An API key must be provided'); assert(!!this.key, 'An API key must be provided');
this.Company = require('./company').Company(this); this.Enrichment = require('./enrichment').Enrichment(this);
this.Person = require('./person').Person(this); this.Company = require('./enrichment/company').Company(this);
this.PersonCompany = require('./person').PersonCompany(this); this.Person = require('./enrichment/person').Person(this);
this.Discovery = require('./discovery').Discovery(this);
this.Watchlist = require('./watchlist').Watchlist(this); this.Watchlist = require('./watchlist').Watchlist(this);
this.WatchlistCandidate = require('./watchlist').WatchlistCandidate(this); this.WatchlistCandidate = require('./watchlist').WatchlistCandidate(this);
this.WatchlistEntity = require('./watchlist').WatchlistEntity(this); this.WatchlistEntity = require('./watchlist').WatchlistEntity(this);
...@@ -58,8 +59,9 @@ ClearbitClient.prototype.request = function (options) { ...@@ -58,8 +59,9 @@ ClearbitClient.prototype.request = function (options) {
return needle.requestAsync( return needle.requestAsync(
options.method, options.method,
this.url(options), this.url(options),
options.query, options.body || options.query,
{ {
json: options.json,
headers: options.headers, headers: options.headers,
timeout: options.stream ? 60000 : 10000, timeout: options.stream ? 60000 : 10000,
username: this.key, username: this.key,
......
'use strict';
var resource = require('./resource');
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'; 'use strict';
var assert = require('assert'); var assert = require('assert');
var resource = require('./resource'); var resource = require('../resource');
var _ = require('lodash'); var _ = require('lodash');
exports.Company = resource.create('Company', {api: 'company'}) exports.Company = resource.create('Company', {api: 'company'})
......
'use strict'; 'use strict';
var assert = require('assert'); var assert = require('assert');
var resource = require('./resource'); var resource = require('../resource');
var _ = require('lodash'); var _ = require('lodash');
exports.Person = resource.create('Person', {api: 'person'}) exports.Person = resource.create('Person', {api: 'person'})
...@@ -21,16 +21,3 @@ 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) { ...@@ -30,7 +30,8 @@ ClearbitResource.post = function (path, options) {
options = _.extend({ options = _.extend({
path: path, path: path,
method: 'post', method: 'post',
query: extractParams(options) json: true,
body: extractParams(options)
}, this.options, options); }, this.options, options);
return this.client.request(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
}]
}
'use strict'; 'use strict';
var expect = require('chai').use(require('chai-as-promised')).expect; var expect = require('chai').use(require('chai-as-promised')).expect;
var nock = require('nock'); var nock = require('nock');
var Person = require('../')('k').Person; var Person = require('../')('k').Person;
var PersonCompany = require('../')('k').PersonCompany; var Enrichment = require('../')('k').Enrichment;
describe('Person', function () { describe('Person', function () {
...@@ -66,7 +66,7 @@ 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 () { it('can find a person by email', function () {
mock mock
...@@ -75,10 +75,10 @@ describe('Person', function () { ...@@ -75,10 +75,10 @@ describe('Person', function () {
person: alex, person: alex,
company: company company: company
}); });
return PersonCompany.find({email: 'alex@alexmaccaw.com'}) return Enrichment.find({email: 'alex@alexmaccaw.com'})
.then(function (personCompany) { .then(function (personCompany) {
expect(personCompany) expect(personCompany)
.to.be.an.instanceOf(PersonCompany) .to.be.an.instanceOf(Enrichment)
.and.have.include.keys('person', 'company') .and.have.include.keys('person', 'company')
.and.have.deep.property('person.id', alex.id); .and.have.deep.property('person.id', alex.id);
}); });
...@@ -92,8 +92,8 @@ describe('Person', function () { ...@@ -92,8 +92,8 @@ describe('Person', function () {
type: 'queued' type: 'queued'
} }
}); });
return expect(PersonCompany.find({email: 'alex@alexmaccaw.com'})) return expect(Enrichment.find({email: 'alex@alexmaccaw.com'}))
.to.be.rejectedWith(PersonCompany.QueuedError); .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