Coder Social home page Coder Social logo

easy_hubspot's Introduction

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

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('[email protected]')

# 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('[email protected]')

# 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=>"[email protected]", 
  :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)

Error Handling

def call
  begin
    EasyHubspot::Contact.create_contact(body)
  rescue EasyHubspot::HubspotApiError => e
    # handle error code
    # e.message = 'Contact already exists. Existing ID: 801'
    Rails.logger.info(e.message)
  end
end

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.

easy_hubspot's People

Contributors

dependabot[bot] avatar oroth8 avatar zrlstone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

easy_hubspot's Issues

`create_contact` example from docs fails : properties should be serialized to JSON

Upon installation and with the last version of the API :

/home/******/Dev/********/.bundle/ruby/3.1.0/gems/easy_hubspot-1.0.0/lib/easy_hubspot/client.rb:39:in `parse_response': Invalid input JSON on line 1, column 12: Unrecognized token 'properties': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false') (EasyHubspot::HubspotApiError)   

This works : EasyHubspot::Contact.create_contact({ properties: { email: '', firstname: '', lastname: '' , etc: ''}}.to_json)

The same applies to update (update_contact(@hubspot_id, { properties: properties }.to_json))

I got really mad trying to use the official gem, so it would be nice to have a maintained gem with a clean and friendly API like yours :)

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.