Coder Social home page Coder Social logo

st3w4r / clearbit-node Goto Github PK

View Code? Open in Web Editor NEW

This project forked from clearbit/clearbit-node

0.0 2.0 0.0 78 KB

Node library for querying the Clearbit business intelligence APIs

Home Page: https://clearbit.com/docs

License: MIT License

JavaScript 100.00%

clearbit-node's Introduction

clearbit-node Build Status Code Climate Test Coverage

Node library for querying the Clearbit business intelligence APIs. Currently supports:

Setup

$ npm install clearbit
var clearbit = require('clearbit')('api_key');
// or
var Client   = require('clearbit').Client;
var clearbit = new Client({key: 'api_key'});

Performing Lookups

Person

Person.find(options) -> Promise

  • email String: The email address to look up (required)
  • webhook_id String: Custom identifier for the webhook request
  • subscribe Boolean: Set to true to subscribe to the changes
  • stream Boolean: Set to true to use the streaming API instead of webhooks
  • timeout Integer: The timeout in milliseconds after which a socket closed error will be thrown.
var Person = clearbit.Person;
Person.find({email: '[email protected]'})
  .then(function (person) {
    console.log('Name: ', person.name.fullName);
  })
  .catch(Person.QueuedError, function (err) {
    console.log(err); // Person is queued
  })
  .catch(Person.NotFoundError, function (err) {
    console.log(err); // Person could not be found
  })
  .catch(function (err) {
    console.log('Bad/invalid request, unauthorized, Clearbit error, or failed request');
  });

Company

Company.find(options) -> Promise

  • domain String: The company domain to look up (required)
  • webhook_id String: Custom identifier for the webhook request
  • stream Boolean: Set to true to use the streaming API instead of webhooks
  • timeout Integer: The timeout in milliseconds after which a socket closed error will be thrown.
var Company = clearbit.Company;
Company.find({domain: 'www.uber.com'})
  .then(function (company) {
    console.log('Name: ', company.name);
  })
  .catch(Company.QueuedError, function (err) {
    console.log(err); // Company is queued
  })
  .catch(Company.NotFoundError, function (err) {
    console.log(err); // Company could not be found
  })
  .catch(function (err) {
    console.log('Bad/invalid request, unauthorized, Clearbit error, or failed request');
  });

Error Handling

Lookups return 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:

Person.find({email: '[email protected]'})
  .catch(Person.NotFoundError, function () {
    // handle an unknown record
  })
  .catch(function () {
    // handle other errors
  });

Callbacks

If you really want to use node-style callbacks, use Bluebird's nodeify method:

Person.find({email: '[email protected]'}).nodeify(function (err, person) {
  if (err) {
    // handle
  }
  else {
    // person
  }
});

clearbit-node's People

Contributors

bendrucker avatar davidlumley avatar dcadenas avatar maccman avatar robholland avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.