hubspot 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/lib/hubspot.rb +53 -4
  3. data/lib/hubspot/api/transaction_email/single_send.rb +37 -0
  4. data/lib/hubspot/delivery_method.rb +18 -0
  5. data/lib/hubspot/errors.rb +21 -0
  6. data/lib/hubspot/http_request.rb +44 -0
  7. data/lib/hubspot/http_response.rb +31 -0
  8. data/lib/hubspot/mailer.rb +18 -0
  9. data/lib/hubspot/object.rb +33 -0
  10. data/lib/hubspot/railtie.rb +13 -0
  11. data/lib/hubspot/transaction_email/delivery_method.rb +17 -0
  12. data/lib/hubspot/transaction_email/mailer.rb +12 -0
  13. data/lib/hubspot/version.rb +1 -1
  14. metadata +245 -158
  15. data/MIT-LICENSE +0 -20
  16. data/README.rdoc +0 -158
  17. data/Rakefile +0 -38
  18. data/app/helpers/hubspot_helper.rb +0 -17
  19. data/app/models/hubspot/base.rb +0 -40
  20. data/app/models/hubspot/blog.rb +0 -35
  21. data/app/models/hubspot/blogs/blog_association.rb +0 -35
  22. data/app/models/hubspot/blogs/comment.rb +0 -5
  23. data/app/models/hubspot/blogs/post.rb +0 -12
  24. data/app/models/hubspot/blogs/posts/comment.rb +0 -23
  25. data/app/models/hubspot/connection.rb +0 -46
  26. data/app/models/hubspot/event.rb +0 -39
  27. data/app/models/hubspot/keyword.rb +0 -49
  28. data/app/models/hubspot/lead.rb +0 -26
  29. data/app/models/hubspot/performable/event.rb +0 -67
  30. data/lib/hubspot/action_controller_extensions.rb +0 -15
  31. data/lib/hubspot/engine.rb +0 -30
  32. data/lib/tasks/hubspot_tasks.rake +0 -4
  33. data/test/dummy/README.rdoc +0 -261
  34. data/test/dummy/Rakefile +0 -7
  35. data/test/dummy/app/assets/javascripts/application.js +0 -15
  36. data/test/dummy/app/assets/stylesheets/application.css +0 -13
  37. data/test/dummy/app/controllers/application_controller.rb +0 -3
  38. data/test/dummy/app/helpers/application_helper.rb +0 -2
  39. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  40. data/test/dummy/config.ru +0 -4
  41. data/test/dummy/config/application.rb +0 -56
  42. data/test/dummy/config/boot.rb +0 -10
  43. data/test/dummy/config/database.yml +0 -25
  44. data/test/dummy/config/environment.rb +0 -5
  45. data/test/dummy/config/environments/development.rb +0 -37
  46. data/test/dummy/config/environments/production.rb +0 -67
  47. data/test/dummy/config/environments/test.rb +0 -37
  48. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  49. data/test/dummy/config/initializers/inflections.rb +0 -15
  50. data/test/dummy/config/initializers/mime_types.rb +0 -5
  51. data/test/dummy/config/initializers/secret_token.rb +0 -7
  52. data/test/dummy/config/initializers/session_store.rb +0 -8
  53. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  54. data/test/dummy/config/locales/en.yml +0 -5
  55. data/test/dummy/config/routes.rb +0 -58
  56. data/test/dummy/db/test.sqlite3 +0 -0
  57. data/test/dummy/log/test.log +0 -2326
  58. data/test/dummy/public/404.html +0 -26
  59. data/test/dummy/public/422.html +0 -26
  60. data/test/dummy/public/500.html +0 -25
  61. data/test/dummy/public/favicon.ico +0 -0
  62. data/test/dummy/script/rails +0 -6
  63. data/test/fixtures/vcr_cassettes/blog-comments.yml +0 -74
  64. data/test/fixtures/vcr_cassettes/blog-find.yml +0 -36
  65. data/test/fixtures/vcr_cassettes/blog-posts.yml +0 -75
  66. data/test/fixtures/vcr_cassettes/blogs-list.yml +0 -39
  67. data/test/fixtures/vcr_cassettes/event-create.yml +0 -36
  68. data/test/fixtures/vcr_cassettes/event-record.yml +0 -47
  69. data/test/fixtures/vcr_cassettes/events-list.yml +0 -41
  70. data/test/fixtures/vcr_cassettes/keyword-create.yml +0 -36
  71. data/test/fixtures/vcr_cassettes/keywords-list.yml +0 -385
  72. data/test/fixtures/vcr_cassettes/lead-find.yml +0 -103
  73. data/test/fixtures/vcr_cassettes/lead-update.yml +0 -239
  74. data/test/fixtures/vcr_cassettes/leads-list.yml +0 -190
  75. data/test/fixtures/vcr_cassettes/post-comments.yml +0 -72
  76. data/test/fixtures/vcr_cassettes/post-find.yml +0 -39
  77. data/test/hubspot_test.rb +0 -5
  78. data/test/test_helper.rb +0 -22
  79. data/test/unit/blog_test.rb +0 -37
  80. data/test/unit/event_test.rb +0 -21
  81. data/test/unit/keyword_test.rb +0 -22
  82. data/test/unit/lead_test.rb +0 -31
  83. data/test/unit/performable_event_test.rb +0 -22
  84. data/test/unit/post_test.rb +0 -20
@@ -1,20 +0,0 @@
1
- Copyright 2012 Reinier de Lange
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,158 +0,0 @@
1
- = Hubspot
2
-
3
- This gem is a Rails Engine for communicating with several Hubspot API's. Furthermore, it provides some helpers
4
- to easily integrate Hubspot in your website. This gem only uses standard ActiveResource and Net/HTTP and has been
5
- tested with unit tests and VCR for replaying HTTP requests.
6
-
7
- == Requirements
8
-
9
- Rails 3
10
-
11
- == Installation
12
-
13
- Add hubspot to your Gemfile:
14
-
15
- gem 'hubspot'
16
-
17
- == Configuration
18
-
19
- This gem is a Rails Engine. The gem can be configured by changing the default engine configuration. The following settings
20
- can be added to your application.rb or an initializer:
21
-
22
- * *Hubspot.config.hubspot_site* = 'demo.app11.hubspot.com'
23
-
24
- The domain of your Hubspot site, which is used in the javascript tracker code
25
-
26
- * *Hubspot.config.hubspot_access_token* = 'demooooo-oooo-oooo-oooo-oooooooooooo'
27
-
28
- The access token for authenticating to several Hubspot services
29
-
30
- * *Hubspot.config.hubspot_key* = 'demo'
31
-
32
- Your API key
33
-
34
- * *Hubspot.config.hubspot_portal_id* = '62515'
35
-
36
- Your Portal ID
37
-
38
- * *Hubspot.config.debug_http_output* = false
39
-
40
- 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.
41
-
42
- == Usage
43
-
44
- Currently, the gem supports the following Hubspot API's:
45
-
46
- === Leads
47
-
48
- See: http://developers.hubspot.com/docs/endpoints#leads-api
49
-
50
- ==== Finds
51
-
52
- Hubspot::Lead.find :all, :params => { :search => 'test' }
53
- Hubspot::Lead.find <GUID>
54
-
55
- ==== Updates
56
-
57
- lead.firstName = 'Reinier'; lead.save!
58
- lead.update_attributes(:firstName => 'Reinier')
59
-
60
- === Blogs (including posts and comments)
61
-
62
- See: http://developers.hubspot.com/docs/endpoints#blog-api
63
-
64
- ==== Finds
65
-
66
- Hubspot::Blog.find :all, :params => { :max => 10 }
67
- Hubspot::Blog.find <GUID>
68
-
69
- ==== Comments
70
-
71
- Hubspot::Blog.find('guid').comments
72
-
73
- ==== Posts
74
-
75
- Hubspot::Blog.find('guid').posts
76
-
77
- ===== Post comments
78
-
79
- Hubspot::Blogs::Post.find("6ca6fdc5-a81f-44db-a63b-f56ab2636c69", :params => { :blog_guid => "0d61e4ca-e395-4c1c-8766-afaa48bf68db" }).comments
80
-
81
- === Keywords
82
-
83
- See: http://developers.hubspot.com/docs/endpoints#keywords-api
84
-
85
- ==== Finds
86
-
87
- Hubspot::Keyword.find(:all, :params => { :max => 5 })
88
- Hubspot::Keyword.find('guid')
89
-
90
- ==== Creates
91
-
92
- Hubspot::Keyword.create!({ :keyword => { :keyword => 'key' }})
93
- Hubspot::Keyword.create({ :keyword => { :keyword => 'key' }})
94
-
95
- === Events
96
-
97
- See: http://developers.hubspot.com/docs/endpoints#events-api
98
-
99
- ==== Finds
100
-
101
- Hubspot::Event.find(:all, :params => { :max => 5 })
102
-
103
- ==== Creates
104
-
105
- Hubspot::Event.create!(:eventType => 'new event', :description => 'test')
106
- Hubspot::Event.create(:eventType => 'new event', :description => 'test')
107
-
108
- === Performable events
109
-
110
- See: http://performabledoc.hubspot.com/display/DOC/HTTP+API
111
-
112
- ==== Records
113
-
114
- event = Hubspot::Performable::Event.new('event-12345', Date.civil(2012), nil, 'http://example.com')
115
- event.custom_parameters = { :email => 'test@example.com' }
116
- event.record!
117
-
118
- Please take a look at the unit tests for examples!
119
-
120
- == Action controller extensions
121
-
122
- For now, there is only a convenience method for getting the current user token:
123
-
124
- hubspot_user_token # Retrieves the user token from the Hubspot 'hubspotutk' cookie (if any)
125
-
126
- == HubspotHelper
127
-
128
- The HubspotHelper can be used to insert the Hubspot javascript tracker code to your website. First include the helper:
129
-
130
- class ApplicationController < ActionController::Base
131
- helper HubspotHelper
132
- end
133
-
134
- Then, you can add the javascript tracker code easily by calling the helper:
135
-
136
- <body>
137
- ...
138
- <%= hubspot_javascript_tracker %>
139
- </body>
140
-
141
- == Acknowledgements
142
-
143
- * Thanks go to Josh Lane from which I took some of the code of his Hubspot API implementation (https://github.com/lanej/hubspot-api)
144
-
145
- == Note on Patches/Pull Requests
146
-
147
- * Fork the project.
148
- * Make your feature addition or bug fix.
149
- * Add tests for it. This is important so I don't break it in a
150
- future version unintentionally.
151
- * Commit, do not mess with rakefile, version, or history.
152
- (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)
153
- * Send me a pull request. Bonus points for topic branches.
154
-
155
- == Copyright
156
-
157
- Copyright (c) 2012 Reinier de Lange. See LICENSE for details.
158
-
data/Rakefile DELETED
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env rake
2
- begin
3
- require 'bundler/setup'
4
- rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
- end
7
- begin
8
- require 'rdoc/task'
9
- rescue LoadError
10
- require 'rdoc/rdoc'
11
- require 'rake/rdoctask'
12
- RDoc::Task = Rake::RDocTask
13
- end
14
-
15
- RDoc::Task.new(:rdoc) do |rdoc|
16
- rdoc.rdoc_dir = 'rdoc'
17
- rdoc.title = 'Hubspot'
18
- rdoc.options << '--line-numbers'
19
- rdoc.rdoc_files.include('README.rdoc')
20
- rdoc.rdoc_files.include('lib/**/*.rb')
21
- end
22
-
23
-
24
-
25
-
26
- Bundler::GemHelper.install_tasks
27
-
28
- require 'rake/testtask'
29
-
30
- Rake::TestTask.new(:test) do |t|
31
- t.libs << 'lib'
32
- t.libs << 'test'
33
- t.pattern = 'test/**/*_test.rb'
34
- t.verbose = false
35
- end
36
-
37
-
38
- task :default => :test
@@ -1,17 +0,0 @@
1
- module HubspotHelper
2
-
3
- # Should be included at the bottom of any HTML page (before </body>) you want to track
4
- def hubspot_javascript_tracker
5
- raw <<-EOS
6
- <!-- Start of HubSpot Logging Code -->
7
- <script type="text/javascript" language="javascript">
8
- var hs_portalid=#{Hubspot.config.hubspot_portal_id};
9
- var hs_salog_version = "2.00";
10
- var hs_ppa = "#{Hubspot.config.hubspot_site}";
11
- document.write(unescape("%3Cscript src='" + document.location.protocol + "//" + hs_ppa + "/salog.js.aspx' type='text/javascript'%3E%3C/script%3E"));
12
- </script>
13
- <!-- End of HubSpot Logging Code -->
14
- EOS
15
- end
16
-
17
- end
@@ -1,40 +0,0 @@
1
- require "active_resource"
2
-
3
- # Hubspot::Base initializes ActiveResource to use JSON and to use our own Connection class that adds authentication
4
- # information to each request. Moreover, as Hubspot's API paths are very inconsistent, it provides the most common
5
- # paths to object collections and members. This can be overridden if necessary
6
- module Hubspot
7
-
8
- class Base < ActiveResource::Base
9
- self.format = ActiveResource::Formats::JsonFormat
10
-
11
- # Only serialize the attributes listed in the schema. Leads can contain much more information than can be passed
12
- # back to Hubspot, therefore we need to ensure they are not serialized on save.
13
- def to_json(options={})
14
- super(options.reverse_merge(:root => nil, :only => schema.keys))
15
- end
16
-
17
- class << self
18
-
19
- # Use our own connection class
20
- def connection(refresh = false)
21
- @connection = Hubspot::Connection.new(site, format) if @connection.nil? || refresh
22
- return @connection
23
- end
24
-
25
- # ==== Set paths ====
26
-
27
- def element_path(id, prefix_options = {}, query_options = nil)
28
- prefix_options, query_options = split_options(prefix_options) if query_options.nil?
29
- "#{prefix(prefix_options)}#{collection_name.singularize}/#{URI.escape id.to_s}.#{format.extension}#{query_string(query_options)}"
30
- end
31
-
32
- def collection_path(prefix_options = {}, query_options = nil)
33
- prefix_options, query_options = split_options(prefix_options) if query_options.nil?
34
- "#{prefix(prefix_options)}list.#{format.extension}#{query_string(query_options)}"
35
- end
36
-
37
- end
38
- end
39
-
40
- end
@@ -1,35 +0,0 @@
1
- module Hubspot
2
-
3
- # Finds blogs
4
- #
5
- # Finds:
6
- # Hubspot::Blog.find :all, :params => { :max => 10 }
7
- # Hubspot::Blog.find <GUID>
8
- class Blog < Hubspot::Base
9
- self.site = 'https://api.hubapi.com/blog/v1'
10
-
11
- schema do
12
- string 'guid', 'blogTitle', 'feedUrl', 'jsonUrl', 'webUrl'
13
- end
14
-
15
- alias_attribute :id, :guid
16
-
17
- # Convenience methods for retrieving a blog's posts and comments
18
-
19
- def comments(params = {})
20
- Hubspot::Blogs::Comment.find :all, :params => params.merge(:blog_guid => guid)
21
- end
22
-
23
- def posts(params = {})
24
- Hubspot::Blogs::Post.find :all, :params => params.merge(:blog_guid => guid)
25
- end
26
-
27
- # Explicitly set element path
28
- def self.element_path(id, prefix_options = {}, query_options = nil)
29
- prefix_options, query_options = split_options(prefix_options) if query_options.nil?
30
- "#{prefix(prefix_options)}#{URI.escape id.to_s}.#{format.extension}#{query_string(query_options)}"
31
- end
32
-
33
- end
34
-
35
- end
@@ -1,35 +0,0 @@
1
- module Hubspot
2
- module Blogs
3
-
4
- # Define an assocation base class from which blog child associations should inherit
5
- class BlogAssociation < Hubspot::Base
6
- self.site = Hubspot::Blog.site
7
-
8
- alias_attribute :id, :guid
9
-
10
- class << self
11
- def element_path(id, prefix_options = {}, query_options = nil)
12
- prefix_options, query_options = split_options(prefix_options) if query_options.nil?
13
- "#{prefix(prefix_options)}#{collection_name}/#{URI.escape id.to_s}.#{format.extension}#{query_string(query_options)}"
14
- end
15
-
16
- def collection_path(prefix_options = {}, query_options = nil)
17
- prefix_options, query_options = split_options(prefix_options) if query_options.nil?
18
- raise(ActiveResource::MissingPrefixParam, ":blog_guid prefix_option is missing") unless prefix_options[:blog_guid] && defined?(ActiveResource::MissingPrefixParam)
19
- "#{prefix(prefix_options)}#{prefix_options[:blog_guid].to_s}/#{collection_name}.#{format.extension}#{query_string(query_options)}"
20
- end
21
-
22
- private
23
-
24
- def prefix_parameters
25
- @prefix_parameters ||= begin
26
- params = super
27
- params << :blog_guid
28
- params
29
- end
30
- end
31
- end
32
- end
33
-
34
- end
35
- end
@@ -1,5 +0,0 @@
1
- module Hubspot
2
- module Blogs
3
- class Comment < Hubspot::Blogs::BlogAssociation; end
4
- end
5
- end
@@ -1,12 +0,0 @@
1
- module Hubspot
2
- module Blogs
3
- class Post < Hubspot::Blogs::BlogAssociation
4
-
5
- # Convenience method for retrieving a post's comments
6
- def comments(params = {})
7
- Hubspot::Blogs::Posts::Comment.find :all, :params => params.merge(:post_guid => guid)
8
- end
9
-
10
- end
11
- end
12
- end
@@ -1,23 +0,0 @@
1
- module Hubspot
2
- module Blogs
3
- module Posts
4
-
5
- # This type of Comment will be instantiated when finding comments that belong to Posts
6
- class Comment < Hubspot::Base
7
- self.site = 'https://api.hubapi.com/blog/v1/posts/:post_guid'
8
-
9
- alias_attribute :id, :guid
10
-
11
- class << self
12
-
13
- def collection_path(prefix_options = {}, query_options = nil)
14
- prefix_options, query_options = split_options(prefix_options) if query_options.nil?
15
- "#{prefix(prefix_options)}comments.#{format.extension}#{query_string(query_options)}"
16
- end
17
-
18
- end
19
- end
20
-
21
- end
22
- end
23
- end
@@ -1,46 +0,0 @@
1
- module Hubspot
2
-
3
- class Connection < ActiveResource::Connection
4
-
5
- # Set default parameters to send along with each request
6
- def self.default_parameters
7
- @default_parameters ||= begin
8
- default_parameter_hash = {}
9
- default_parameter_hash['portalId'] = Hubspot.config.hubspot_portal_id
10
-
11
- if Hubspot.config.hubspot_access_token.present?
12
- default_parameter_hash['access_token'] = Hubspot.config.hubspot_access_token
13
- else
14
- default_parameter_hash['hapikey'] = Hubspot.config.hubspot_key
15
- end
16
-
17
- default_parameter_hash
18
- end
19
- end
20
-
21
- # Override to support debug output
22
- def configure_http(http)
23
- http.set_debug_output(Hubspot.config.debug_http_output) if Hubspot.config.debug_http_output
24
- super
25
- end
26
-
27
- private
28
-
29
- # Makes a request to the remote service and appends the default parameters
30
- def request(method, path, *arguments)
31
- uri = URI.parse(path)
32
-
33
- Hubspot::Connection.default_parameters.to_param.tap do |default_parameters|
34
- if uri.query.present?
35
- uri.query += '&' + default_parameters
36
- else
37
- uri.query = default_parameters
38
- end
39
- end
40
-
41
- super(method, uri.to_s, *arguments)
42
- end
43
-
44
- end
45
-
46
- end
@@ -1,39 +0,0 @@
1
- module Hubspot
2
-
3
- # Finds and updates events
4
- #
5
- # Finds:
6
- # Hubspot::Event.find :all, :params => { :max => 5 }
7
- #
8
- # Creates:
9
- # Hubspot::Event.create(:eventType => 'new event', :description => 'test', :url => 'http://dev.hubspot.com', :createDate => '1323272544000' )
10
- class Event < Hubspot::Base
11
- self.site = 'https://api.hubapi.com/events/v1'
12
-
13
- schema do
14
- string 'description', 'eventType', 'url', 'createDate'
15
- end
16
-
17
- class << self
18
- def create attributes
19
- create!(attributes) #rescue false
20
- end
21
-
22
- def create! attributes
23
- return Hubspot::Event.post('events', attributes).code.to_i
24
- end
25
-
26
- def custom_method_collection_url(method_name, options = {})
27
- prefix_options, query_options = split_options(options)
28
- "#{prefix(prefix_options)}#{method_name}#{query_string(query_options)}"
29
- end
30
-
31
- def collection_path(prefix_options = {}, query_options = nil)
32
- prefix_options, query_options = split_options(prefix_options) if query_options.nil?
33
- "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
34
- end
35
- end
36
-
37
- end
38
-
39
- end