Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "clearbit", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Client for Clearbit.co business intelligence APIs", | ||
@@ -5,0 +5,0 @@ "main": "./src", |
@@ -15,3 +15,3 @@ clearbit-node [![Build Status](https://travis-ci.org/bendrucker/clearbit-node.svg?branch=master)](https://travis-ci.org/bendrucker/clearbit-node) [![Code Climate](https://codeclimate.com/github/bendrucker/clearbit-node/badges/gpa.svg)](https://codeclimate.com/github/bendrucker/clearbit-node) [![Test Coverage](https://codeclimate.com/github/bendrucker/clearbit-node/badges/coverage.svg)](https://codeclimate.com/github/bendrucker/clearbit-node) | ||
var clearbit = require('clearbit')('api_key'); | ||
// or | ||
// or | ||
var Client = require('clearbit').Client; | ||
@@ -29,4 +29,3 @@ var clearbit = new Client({key: 'api_key'}); | ||
* `subscribe` *Boolean*: Set to `true` to subscribe to the changes | ||
* `company` *Boolean*: Set to `true` to include a company lookup on the email’s domain name in the response | ||
* `stream` *Boolean*: Set to `true` to use the [streaming API](https://clearbit.co/docs?shell#streaming) instead of webhooks | ||
* `stream` *Boolean*: Set to `true` to use the [streaming API](https://clearbit.co/docs?shell#streaming) instead of webhooks | ||
@@ -37,6 +36,7 @@ ```js | ||
.then(function (person) { | ||
if (!person.pending()) { | ||
console.log('Name: ', person.name.fullName); | ||
} | ||
console.log('Name: ', person.name.fullName); | ||
}) | ||
.catch(Person.QueuedError, function (err) { | ||
console.log(err); // Person is queued | ||
}) | ||
.catch(Person.NotFoundError, function (err) { | ||
@@ -50,5 +50,2 @@ console.log(err); // Person could not be found | ||
#### `person.pending()` -> `Boolean` | ||
If Clearbit responds with a `202` status indicating that lookup has been queued, `person.pending` returns `true`. | ||
### Company | ||
@@ -59,3 +56,3 @@ | ||
* `webhook_id` *String*: Custom identifier for the webhook request | ||
* `stream` *Boolean*: Set to `true` to use the [streaming API](https://clearbit.co/docs?shell#streaming) instead of webhooks | ||
* `stream` *Boolean*: Set to `true` to use the [streaming API](https://clearbit.co/docs?shell#streaming) instead of webhooks | ||
@@ -66,6 +63,7 @@ ```js | ||
.then(function (company) { | ||
if (!company.pending()) { | ||
console.log('Name: ', company.name); | ||
} | ||
console.log('Name: ', company.name); | ||
}) | ||
.catch(Company.QueuedError, function (err) { | ||
console.log(err); // Company is queued | ||
}) | ||
.catch(Company.NotFoundError, function (err) { | ||
@@ -79,5 +77,2 @@ console.log(err); // Company could not be found | ||
#### `company.pending()` -> `Boolean` | ||
If Clearbit responds with a `202` status indicating that lookup has been queued, `company.pending` returns `true`. | ||
### Error Handling | ||
@@ -84,0 +79,0 @@ Lookups return [Bluebird](https://github.com/petkaantonov/bluebird) promises. Any status code >=400 will trigger an error, including lookups than do not return a result. You can easily filter out unknown records from true errors using [Bluebird's error class matching](https://github.com/petkaantonov/bluebird/blob/master/API.md#catchfunction-errorclassfunction-predicate-function-handler---promise): |
@@ -20,2 +20,3 @@ 'use strict'; | ||
this.Company = require('./company')(this); | ||
this.PersonCompany = require('./person_company')(this); | ||
} | ||
@@ -70,3 +71,3 @@ | ||
.spread(function (response, body) { | ||
if (response.statusCode >= 400) { | ||
if (response.statusCode === 202 || response.statusCode >= 400) { | ||
var message = body.error ? body.error.message : http.STATUS_CODES[response.statusCode] || 'Unknown'; | ||
@@ -73,0 +74,0 @@ throw _.extend(new this.ClearbitError(message), { |
@@ -13,4 +13,2 @@ 'use strict'; | ||
Company.prototype.pending = utils.pending; | ||
Company.find = Promise.method(function (options) { | ||
@@ -24,2 +22,5 @@ assert(options && options.domain, 'A domain must be provided'); | ||
.then(utils.cast) | ||
.catch(utils.isQueued, function () { | ||
throw new this.QueuedError('Company lookup queued'); | ||
}) | ||
.catch(utils.isUnknownRecord, function () { | ||
@@ -32,4 +33,5 @@ throw new this.NotFoundError('Company not found'); | ||
Company.NotFoundError = utils.NotFoundError; | ||
Company.QueuedError = utils.QueuedError; | ||
return Company; | ||
}; |
@@ -13,4 +13,2 @@ 'use strict'; | ||
Person.prototype.pending = utils.pending; | ||
Person.find = Promise.method(function (options) { | ||
@@ -25,2 +23,5 @@ assert(options && options.email, 'An email must be provided'); | ||
.then(utils.cast) | ||
.catch(utils.isQueued, function () { | ||
throw new this.QueuedError('Person lookup queued'); | ||
}) | ||
.catch(utils.isUnknownRecord, function () { | ||
@@ -33,4 +34,5 @@ throw new this.NotFoundError('Person not found'); | ||
Person.NotFoundError = utils.NotFoundError; | ||
Person.QueuedError = utils.QueuedError; | ||
return Person; | ||
}; |
@@ -9,7 +9,4 @@ 'use strict'; | ||
exports.pending = function () { | ||
return !this.id; | ||
}; | ||
exports.NotFoundError = createError('NotFoundError'); | ||
exports.QueuedError = createError('QueuedError'); | ||
@@ -19,1 +16,5 @@ exports.isUnknownRecord = function (err) { | ||
}; | ||
exports.isQueued = function (err) { | ||
return err.type === 'queued'; | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12145
10
203
97
2