Ruby wrapper for the HubSpot API (HAPI)
Switch branches/tags
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


RHapi (Ruby HubSpot API Wrapper)

RHapi is a Ruby wrapper for the HubSpot API (HAPI).

To do:

  • Add method to create new leads.

  • Build out methods for Blogs API.

  • Write documentation.

Using RHapi

Intsall If you use RVM.

gem install r_hapi

If not you may need to do this:

sudo gem install r_hapi

First configure RHapi to work with your Hubspot API Key.

RHapi.configure do |config|
  config.api_key = "YOUR_API_KEY"

Then to get a list of leads.

leads = RHapi::Lead.find
leads.each do |lead|
  puts lead.first_name
  puts lead.last_name
  puts lead.state
  puts lead.guid

To find leads named Barny.

leads = RHapi::Lead.find("Barny")

You can also pass additional options to the find method.

options = {
  :sort       => "lastName",          # Possible sort values include: firstName, lastName, email, address, phone, insertedAt, lastConvertedAt, lastModifiedAt, closedAt
  :dir        => "asc",               # Use desc for descending.
  :max        => 25,                  # Maximum value is 100
  :offset     => 50,                  # Used in combination with max for paging results. 
  :startTime  => 1298721462000,       # Expressed as milliseconds since epoch time. Returned list will have only leads inserted after this time. Default is 0 and returns all leads up to max.
  :stopTime   => 1298721462000,       # Expressed as milliseconds since epoch time. 
  :timePivot  => "insertedAt",        # The field the start and stop times should be applied to in the search. Can be: insertedAt, firstConvertedAt, lastConvertedAt, lastModifiedAt, closedAt.
  :excludeConversionEvents => false,  # Used to exclude all items in the leadConversionEvents collection from the API results.
  :optout                  => false,  # Set to true to include only leads that have unsubscribed from lead nurturing. The default value, false, includes all leads. 
  :eligibleForEmail        => false,  # Set to true to include only leads eligible for email marketing.
  :bounced                 => false,  # Set to true to include only leads that HubSpot has tried to email, and the email bounced. The default value, false, includes all leads.
  :notImported             => false  # Set to true to include only web leads. The default value, false, includes both imported and web leads.
leads = RHapi::Lead.find("Barny", options)

To update a lead.

lead = leads.first
lead.first_name = "Fred"
lead.last_name  = "Flintsone"

You can also pass a params hash to update a lead.

params = {:first_name => "Fred", :last_name => "Flintstone", :city => "Bedrock"}

To get a single lead with a guid. Assumes the guid has be saved from a previous search.

lead = RHapi::Lead.find_by_guid(lead.guid)

Contributing to r_hapi

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet

  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.


Copyright © 2011 Tim Stephenson. See LICENSE.txt for further details.