Giter Site home page Giter Site logo

hubspot's Introduction

Hubspot

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.

Requirements

Rails 3

Installation

Add hubspot to your Gemfile:

gem 'hubspot'

Configuration

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.

Usage

Currently, the gem supports the following Hubspot API’s:

Leads

See: developers.hubspot.com/docs/endpoints#leads-api

Finds

Hubspot::Lead.find :all, :params => { :search => 'test' }
Hubspot::Lead.find <GUID>

Updates

lead.firstName = 'Reinier'; lead.save!
lead.update_attributes(:firstName => 'Reinier')

Blogs (including posts and comments)

See: developers.hubspot.com/docs/endpoints#blog-api

Finds

Hubspot::Blog.find :all, :params => { :max => 10 }
Hubspot::Blog.find <GUID>

Comments

Hubspot::Blog.find('guid').comments

Posts

Hubspot::Blog.find('guid').posts
Post comments
Hubspot::Blogs::Post.find("6ca6fdc5-a81f-44db-a63b-f56ab2636c69", :params => { :blog_guid => "0d61e4ca-e395-4c1c-8766-afaa48bf68db" }).comments

Keywords

See: developers.hubspot.com/docs/endpoints#keywords-api

Finds

Hubspot::Keyword.find(:all, :params => { :max => 5 })
Hubspot::Keyword.find('guid')

Creates

Hubspot::Keyword.create!({ :keyword => { :keyword => 'key' }})      
Hubspot::Keyword.create({ :keyword => { :keyword => 'key' }})

Events

See: developers.hubspot.com/docs/endpoints#events-api

Finds

Hubspot::Event.find(:all, :params => { :max => 5 })

Creates

Hubspot::Event.create!(:eventType => 'new event', :description => 'test')
Hubspot::Event.create(:eventType => 'new event', :description => 'test')

Performable events

See: performabledoc.hubspot.com/display/DOC/HTTP+API

Records

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!

Action controller extensions

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)

HubspotHelper

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>

Acknowledgements

Note on Patches/Pull Requests

  • 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.

hubspot's People

Watchers

Matt Lankford avatar James Cloos avatar

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.