Code Monkey home page Code Monkey logo

clearbit-ruby's Introduction

⚠️ DEPRECATION WARNING

This package is no longer being maintained. If you're looking to integrate with Clearbit's API we recommend looking at the HTTP requests available in our documentation at clearbit.com/docs

Clearbit

A Ruby API client to https://clearbit.com.

Installation

Add this line to your application's Gemfile:

gem 'clearbit'

And then execute:

$ bundle

Or install it yourself as:

$ gem install clearbit

Usage

First authorize requests by setting the API key found on your account's settings page.

Clearbit.key = ENV['CLEARBIT_KEY']

Then you can lookup people by email address:

result = Clearbit::Enrichment.find(email: '[email protected]', stream: true)

person  = result.person
company = result.company

Passing the stream option makes the operation blocking - it could hang for 4-5 seconds if we haven't seen the email before. Alternatively you can use our webhook API.

Without the stream option, the operation is non-blocking, and we will immediately return either the enriched data or Clearbit::Pending object.

result = Clearbit::Enrichment.find(email: '[email protected]')

if result.pending?
  # Lookup queued - try again later
end

# Later
unless result.pending?
  person  = result.person
  company = result.company
end

In either case, if a person or company can't be found, the result will be nil.

See the documentation for more information.

Name to Domain

To find the domain based on the name of a resource, you can use the NameDomain API.

name = Clearbit::NameDomain.find(name: 'Uber')

For more information look at the documentation.

Company lookup

You can lookup company data by domain name:

company = Clearbit::Enrichment::Company.find(domain: 'uber.com', stream: true)

If the company can't be found, then nil will be returned.

See the documentation for more information.

Analytics

NOTE: We strongly recommend using clearbit.js for Analytics and integrating with Clearbit X. It handles a lot of complexity, like generating anonymous_ids and associating them with user_ids when a user is identified. It also automatically tracks page views with the full data set.

Identifying Users

Identify users by sending their user_id, and adding details like their email and company_domain to create People and Companies inside of Clearbit X.

Clearbit::Analytics.identify(
  user_id: '1234', # Required if no anonymous_id is sent. The user's ID in your database.
  anonymous_id: session[:anonymous_id], # Required if no user_id is sent. A UUID to track anonymous users.
  traits: {
    email: '[email protected]', # Optional, but strongly recommended
    company_domain: 'clearbit.com',     # Optional, but strongly recommended
    first_name: 'David', # Optional
    last_name: 'Lumley', # Optional
    # … other analytical traits can also be sent, like the plan a user is on etc
  },
  context: {
    ip: '89.102.33.1' # Optional, but strongly recommended when identifying users
  }                   # as they sign up, or log in
)

Page Views

Use the page method, and send the users anonymous_id along with the url they're viewing, and the ip the request comes from in order to create Companies inside of Clearbit X and track their page views.

Clearbit::Analytics.page(
  user_id: '1234', # Required if no anonymous_id is sent. The user's ID in your database.
  anonymous_id: session[:anonymous_id], # Required if no user_id is sent. A UUID to track anonymous users.
  name: 'Clearbit Ruby Library', # Optional, but strongly recommended
  properties: {
    url: 'https://github.com/clearbit/clearbit-ruby?utm_source=google', # Required. Likely to be request.referer
    path: '/clearbit/clearbit-ruby', # Optional, but strongly recommended
    search: '?utm_source=google', # Optional, but strongly recommended
    referrer: nil, # Optional. Unlikely to be request.referrer.
  },
  context: {
    ip: '89.102.33.1', # Optional, but strongly recommended.
  },
)

Other APIs

For more info on our other APIs (such as the Watchlist or Discover APIs), please see our main documentation.

Webhooks

For rack apps use the Clearbit::Webhook module to wrap deserialization and verify the webhook is from trusted party:

post '/v1/webhooks/clearbit' do
  begin
    webhook = Clearbit::Webhook.new(request.env)
    webhook.type #=> 'person'
    webhook.body.name.given_name #=> 'Alex'

    # ...
  rescue Clearbit::Errors::InvalidWebhookSignature => e
    # ...
  end
end

The global Clearbit.key can be overriden for multi-tenant apps using multiple Clearbit keys like so:

webhook = Clearbit::Webhook.new(request.env, 'CLEARBIT_KEY')

Proxy Support

Passing the proxy option allows you to specify a proxy server to pass the request through.

company = Clearbit::Enrichment::Company.find(
  domain: 'uber.com',
  proxy: 'https://user:[email protected]:8080'
)

clearbit-ruby's People

Contributors

bentona avatar bsteven3 avatar davidlumley avatar evenstensberg avatar harlow avatar jcody avatar lurraca avatar maccman avatar nicosuave avatar rebeccaryang avatar robholland avatar soffes avatar trevorturk avatar tristandunn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clearbit-ruby's Issues

autocomplete

Are there any plans to include the autocomplete api?

I know I can go directly from javascript:

$.getJSON('https://autocomplete.clearbit.com/v1/companies/suggest'

I believe this free version is up until a certain limit.

In order to use the non free version, I would think this would be a server query to avoid putting the api keys on the client.

Nestful dependency

Where can I find 'nestful', '~> 1.1.0'? RubyGems and nestful repo show that the latest version is 1.0.7

[email protected] is invalid

[email protected] is invalid. This email address is also valid from mailtester.com.

Failed. Response code = 422. Response message = Unprocessable Entity. Response Body = { "error": { "type": "email_invalid", "message": "Invalid email." } }.

Missing tags for recent releases?

While the most recent release is v0.3.1, the most recent tag is v0.2.8.

It'd be nice to add the missing tags to the right released commits to avoid confusion.

person always nil if :stream option not specified

Clearbit::Enrichment.find(email: '[email protected]')

webhook result:
"body":{"person":null,"company":{"id":"41825e9a-8390-458c-a0e3-57fca7317392","name":"Alex MacCaw","legalName":null,"domain":"alexmaccaw.com","domainAliases":[],"url":"http://alexmaccaw.com","site":{"url":"http://alexmaccaw.com","title":"Alex MacCaw","h1":"Alex MacCaw","metaDescription":"JavaScript programmer, O'Reilly author, open source hacker","metaAuthor":"Alex MacCaw"},"category":{"sector":null,"industryGroup":null,"industry":null,"subIndustry":null},"tags":[],"description":"https://t.co/2Rm44uqoVU co-founder. Tea, Earl Grey, hot.","raised":null,"location":null,"geo":{"streetNumber":null,"streetName":null,"subPremise":null,"city":null,"postalCode":null,"state":null,"stateCode":null,"country":null,"countryCode":null,"lat":null,"lng":null},"employees":null,"logo":"https://logo.clearbit.com/alexmaccaw.com","google":{"rank":5},"alexa":{"usRank":271236,"globalRank":500558},"facebook":{"handle":null,"likes":null},"linkedin":{"handle":null},"twitter":{"handle":"maccaw","id":"2006261","bio":"https://t.co/2Rm44uqoVU co-founder. Tea, Earl Grey, hot.","followers":16646,"following":1954,"location":"San Francisco","site":"https://t.co/lBoBBpfLBK","avatar":"https://pbs.twimg.com/profile_images/658880981017882629/nlXSOJnc_normal.jpg"},"angellist":{"id":null,"handle":null,"description":null,"followers":null,"blogUrl":null},"crunchbase":{"handle":null},"emailProvider":false,"type":"private","ticker":null,"phone":null}},"status":200,"type":"person_company","id":null}

Clearbit::Enrichment::Person.find(email: '[email protected]')

webhook result:

{"body":null,"status":404,"type":"person","id":null}

Versioning is not handled for pagination

I want to use Prospector API version 2018-11-16
For this I am using
Clearbit::Person.version = '2018-11-16'

And Its not working, when I pass page and page_size to it
Clearbit::Prospector.search method

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.