0.02
No release in over a year
This gem is designed to make it easier to integrate with the Hubspot API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 3.36
~> 0.14.2
~> 13.0
~> 3.12.0
~> 1.2
~> 0.6.0
~> 2.18.1
~> 0.17.0
~> 3.14

Runtime

~> 0.21.0
 Project Readme

EasyHubspot

Stable: stable version Latest: latest version CI Code Climate Test Coverage

This is a lightweight wrapper for the Hubspot API. It is designed to be easy to use and to provide a simple setup for the most common use cases.

This gem utilizes the v3 hubspot-api

CRM Objects

  • Contacts

  • Deals

  • Products

  • Line Items

  • Error Handling

Dependencies

Compatibility

  • ruby >= 2.6.10
  • rails >= 6.0

Installation

Add this line to your application's Gemfile:

gem 'easy_hubspot'

Usage

Add the following to your config/initializers/easy_hubspot.rb file:

EasyHubspot.config do |c|
  c.access_token = 'YOUR API KEY'
  c.base_url = 'https://api.hubapi.com/'
end

Or run the generator:

rails g easy_hubspot:install

Contacts

Please refrence the hubspot docs

# Create a contact 
  # required: body 
  # returns: parsed hubspot contact
  EasyHubspot::Contact.create_contact(properties: { email: '', firstname: '', lastname: '' , etc: ''})

# Update a contact 
# required: contact_id, body
# - contact_id: can be a hubspot contact_id or email
# returns: parsed hubspot contact
  EasyHubspot::Contact.update_contact(123, properties: { email: '', firstname: '', lastname: '' , etc: ''})

# Get a contact
# required: contact_id
# - contact_id: can be a hubspot contact_id or email
# returns: parsed hubspot contact
  EasyHubspot::Contact.get_contact(123)
# or
  EasyHubspot::Contact.get_contact('test@gmail.com')

# Get all contacts 
# returns: parsed hubspot contacts
  EasyHubspot::Contact.get_contacts

# Delete a contact 
# required: contact_id 
# - contact_id: can be a hubspot contact_id or email
# returns: {status: 'success'}
  EasyHubspot::Contact.delete_contact(123)
# or 
  EasyHubspot::Contact.delete_contact('test@gmail.com')

# Update or Create a contact
# required: email, body 
# returns: parsed hubspot contact
  EasyHubspot::Contact.update_or_create_contact(properties: { email: '', firstname: '', lastname: '' , etc: ''})


# Parse hubspot contact example
{:id=>"701",
 :properties=>
  {:createdate=>"2023-02-08T20:10:36.858Z", 
  :email=>"amber_becker@quigley.io", 
  :firstname=>"Amber", 
  :hs_content_membership_status=>"inactive", 
  :hs_is_contact=>"true", 
  :hs_is_unworked=>"true", 
  :hs_object_id=>"701", 
  :hs_pipeline=>"contacts-lifecycle-pipeline", 
  :lastmodifieddate=>"2023-02-14T18:24:07.654Z", 
  :lastname=>"Quigley", 
  :lifecyclestage=>"lead"},
 :createdAt=>"2023-02-08T20:10:36.858Z",
 :updatedAt=>"2023-02-14T18:24:07.654Z",
 :archived=>false}

Deals

# Create a deal 
  # required: body
  # returns: parsed hubspot deal
  EasyHubspot::Deal.create_deal(properties: { dealname: '', amount: '', etc: ''})

# Update a deal
# required: deal_id, body
# - deal_id: must be a hubspot deal_id
# returns: parsed hubspot deal
  EasyHubspot::Deal.update_deal(123, properties: { dealname: '', amount: '', etc: ''})

# Get a deal
# required: deal_id
# - deal_id: must be a hubspot deal_id
# returns: parsed hubspot deal
  EasyHubspot::Deal.get_deal(123)

# Get all deals
# returns: parsed hubspot deals
  EasyHubspot::Deal.get_deals

# Delete a deal
# required: deal_id
# - deal_id: must be a hubspot deal_id
# returns: {status: 'success'}
  EasyHubspot::Deal.delete_deal(123)

Products

Please refrence the hubspot docs

# Create a product 
  # required: body
  # returns: parsed hubspot product
  EasyHubspot::Product.create_product(properties: { name: '', price: '', etc: ''})

# Update a product
# required: product_id, body
# - product_id: must be a hubspot product_id
# returns: parsed hubspot product
  EasyHubspot::Product.update_product(123, properties: { name: '', price: '', etc: ''})

# Get a product
# required: product_id
# - product_id: must be a hubspot product_id
# returns: parsed hubspot product
  EasyHubspot::Product.get_product(123)

# Get all products
# returns: parsed hubspot products
  EasyHubspot::Product.get_products

# Delete a product
# required: product_id
# - product_id: must be a hubspot product_id
# returns: {status: 'success'}
  EasyHubspot::Product.delete_product(123)

Line Items

Please refrence the hubspot docs

# Create a line item
  # required: body
  # Use hs_product_id property to base on an existing product
  # returns: parsed hubspot line item
  EasyHubspot::LineItem.create_line_item(properties: { quantity: '', hs_product_id: '', etc: ''})

# Update a line item
# required: line_item_id, body
# - line_item_id: must be a hubspot line_item_id
# returns: parsed hubspot line item
  EasyHubspot::LineItem.update_line_item(123, properties: { quantity: '', etc: ''})

# Get a line item
# required: line_item_id
# - line_item_id: must be a hubspot line_item_id
# returns: parsed hubspot line item
  EasyHubspot::LineItem.get_line_item(123)

# Get all line items
# returns: parsed hubspot line items
  EasyHubspot::LineItem.get_line_items

# Delete a line item
# required: line_item_id
# - line_item_id: must be a hubspot line_item_id
# returns: {status: 'success'}
  EasyHubspot::LineItem.delete_line_item(123)

Multiple Access Tokens

If you need to choose your access token at call time, you can pass the access token as an argument to class methods as follows:

# Finds the contact using the access token provided at call time instead of the one set during initialization
EasyHubspot::Contact.get_contact(123, different_access_token)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/oroth8/easy_hubspot.

License

The gem is available as open source under the terms of the MIT License.