This gem is a Rails Engine for communicating with several Hubspot API’s. Furthermore, it provides some helpers to easily integrate Hubspot in your website. This gem only uses standard ActiveResource and Net/HTTP and has been tested with unit tests and VCR for replaying HTTP requests.
Rails 3
Add hubspot to your Gemfile:
gem 'hubspot'
This gem is a Rails Engine. The gem can be configured by changing the default engine configuration. The following settings can be added to your application.rb or an initializer:
-
Hubspot.config.hubspot_site = ‘demo.app11.hubspot.com’
The domain of your Hubspot site, which is used in the javascript tracker code
-
Hubspot.config.hubspot_access_token = ‘demooooo-oooo-oooo-oooo-oooooooooooo’
The access token for authenticating to several Hubspot services
-
Hubspot.config.hubspot_key = ‘demo’
Your API key
-
Hubspot.config.hubspot_portal_id = ‘62515’
Your Portal ID
-
Hubspot.config.debug_http_output = false
Enables/disables logging of HTTP requests and response. False disables debugging, setting it to STDOUT enables logging to STDOUT. Of course you can specify any IO object you want.
Currently, the gem supports the following Hubspot API’s:
See: developers.hubspot.com/docs/endpoints#leads-api
Hubspot::Lead.find :all, :params => { :search => 'test' } Hubspot::Lead.find <GUID>
lead.firstName = 'Reinier'; lead.save! lead.update_attributes(:firstName => 'Reinier')
See: developers.hubspot.com/docs/endpoints#blog-api
Hubspot::Blog.find :all, :params => { :max => 10 } Hubspot::Blog.find <GUID>
Hubspot::Blog.find('guid').comments
Hubspot::Blog.find('guid').posts
Hubspot::Blogs::Post.find("6ca6fdc5-a81f-44db-a63b-f56ab2636c69", :params => { :blog_guid => "0d61e4ca-e395-4c1c-8766-afaa48bf68db" }).comments
See: developers.hubspot.com/docs/endpoints#keywords-api
Hubspot::Keyword.find(:all, :params => { :max => 5 }) Hubspot::Keyword.find('guid')
Hubspot::Keyword.create!({ :keyword => { :keyword => 'key' }}) Hubspot::Keyword.create({ :keyword => { :keyword => 'key' }})
See: developers.hubspot.com/docs/endpoints#events-api
Hubspot::Event.find(:all, :params => { :max => 5 })
Hubspot::Event.create!(:eventType => 'new event', :description => 'test') Hubspot::Event.create(:eventType => 'new event', :description => 'test')
See: performabledoc.hubspot.com/display/DOC/HTTP+API
event = Hubspot::Performable::Event.new('event-12345', Date.civil(2012), nil, 'http://example.com') event.custom_parameters = { :email => '[email protected]' } event.record!
Please take a look at the unit tests for examples!
For now, there is only a convenience method for getting the current user token:
hubspot_user_token # Retrieves the user token from the Hubspot 'hubspotutk' cookie (if any)
The HubspotHelper can be used to insert the Hubspot javascript tracker code to your website. First include the helper:
class ApplicationController < ActionController::Base helper HubspotHelper end
Then, you can add the javascript tracker code easily by calling the helper:
<body> ... <%= hubspot_javascript_tracker %> </body>
-
Thanks go to Josh Lane from which I took some of the code of his Hubspot API implementation (github.com/lanej/hubspot-api)
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Copyright © 2012 Reinier de Lange. See LICENSE for details.