hubspot-api-ruby 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/Gemfile +3 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +18 -0
- data/README.md +295 -0
- data/RELEASING.md +6 -0
- data/Rakefile +32 -0
- data/hubspot-api-ruby.gemspec +42 -0
- data/lib/hubspot-api-ruby.rb +39 -0
- data/lib/hubspot/blog.rb +98 -0
- data/lib/hubspot/collection.rb +41 -0
- data/lib/hubspot/company.rb +160 -0
- data/lib/hubspot/company_properties.rb +59 -0
- data/lib/hubspot/config.rb +63 -0
- data/lib/hubspot/connection.rb +152 -0
- data/lib/hubspot/contact.rb +110 -0
- data/lib/hubspot/contact_list.rb +129 -0
- data/lib/hubspot/contact_properties.rb +59 -0
- data/lib/hubspot/deal.rb +173 -0
- data/lib/hubspot/deal_pipeline.rb +58 -0
- data/lib/hubspot/deal_properties.rb +59 -0
- data/lib/hubspot/deprecator.rb +7 -0
- data/lib/hubspot/engagement.rb +222 -0
- data/lib/hubspot/event.rb +21 -0
- data/lib/hubspot/exceptions.rb +18 -0
- data/lib/hubspot/file.rb +38 -0
- data/lib/hubspot/form.rb +95 -0
- data/lib/hubspot/oauth.rb +50 -0
- data/lib/hubspot/owner.rb +57 -0
- data/lib/hubspot/paged_collection.rb +35 -0
- data/lib/hubspot/properties.rb +123 -0
- data/lib/hubspot/railtie.rb +10 -0
- data/lib/hubspot/resource.rb +270 -0
- data/lib/hubspot/subscription.rb +37 -0
- data/lib/hubspot/topic.rb +37 -0
- data/lib/hubspot/utils.rb +127 -0
- data/lib/tasks/hubspot.rake +53 -0
- data/spec/factories/companies.rb +9 -0
- data/spec/factories/contacts.rb +10 -0
- data/spec/lib/hubspot-ruby_spec.rb +12 -0
- data/spec/lib/hubspot/blog_spec.rb +150 -0
- data/spec/lib/hubspot/company_properties_spec.rb +410 -0
- data/spec/lib/hubspot/company_spec.rb +340 -0
- data/spec/lib/hubspot/config_spec.rb +87 -0
- data/spec/lib/hubspot/connection_spec.rb +214 -0
- data/spec/lib/hubspot/contact_list_spec.rb +301 -0
- data/spec/lib/hubspot/contact_properties_spec.rb +245 -0
- data/spec/lib/hubspot/contact_spec.rb +223 -0
- data/spec/lib/hubspot/deal_pipeline_spec.rb +85 -0
- data/spec/lib/hubspot/deal_properties_spec.rb +262 -0
- data/spec/lib/hubspot/deal_spec.rb +185 -0
- data/spec/lib/hubspot/deprecator_spec.rb +15 -0
- data/spec/lib/hubspot/engagement_spec.rb +177 -0
- data/spec/lib/hubspot/event_spec.rb +33 -0
- data/spec/lib/hubspot/file_spec.rb +38 -0
- data/spec/lib/hubspot/form_spec.rb +189 -0
- data/spec/lib/hubspot/owner_spec.rb +56 -0
- data/spec/lib/hubspot/properties_spec.rb +45 -0
- data/spec/lib/hubspot/resource_spec.rb +54 -0
- data/spec/lib/hubspot/topic_spec.rb +23 -0
- data/spec/lib/hubspot/utils_spec.rb +164 -0
- data/spec/lib/tasks/hubspot_spec.rb +119 -0
- data/spec/shared_examples/saveable_resource.rb +45 -0
- data/spec/shared_examples/updateable_resource.rb +87 -0
- data/spec/spec_helper.rb +44 -0
- data/spec/support/capture_output.rb +21 -0
- data/spec/support/cassette_helper.rb +19 -0
- data/spec/support/hubspot_api_helpers.rb +13 -0
- data/spec/support/rake.rb +46 -0
- data/spec/support/tests_helper.rb +17 -0
- data/spec/support/vcr.rb +16 -0
- metadata +369 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b8c321bf08699c556e265ef8bb24a6f66ad0993ed284a66adb4dacbcc5263748
|
4
|
+
data.tar.gz: 9a9fd7fccb6ac668affde2373ed824a3f5ac95fc7ed1ca6afc90e7e523dcd83e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 872f7fc25b8acfd21ca29fa0223f36506993581ced761f90838adcb5425bad857bec190f5b804f9c466f1919988d76e80b5834004228e722ca920216b2b92406
|
7
|
+
data.tar.gz: f9608077e1a5346205baf9216259fbfdee3e6d49f1abac18ac05e5226b3c05db86b61c0ed6d0e266510c2b9cd898e899da66e12335bdf8a4b2796677bac788ff
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
end
|
9
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
2
|
+
a copy of this software and associated documentation files (the
|
3
|
+
"Software"), to deal in the Software without restriction, including
|
4
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
5
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
6
|
+
permit persons to whom the Software is furnished to do so, subject to
|
7
|
+
the following conditions:
|
8
|
+
|
9
|
+
The above copyright notice and this permission notice shall be
|
10
|
+
included in all copies or substantial portions of the Software.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
13
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
14
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
15
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
16
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
17
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
18
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,295 @@
|
|
1
|
+
# HubSpot REST API wrappers for ruby
|
2
|
+
|
3
|
+
**This is the master branch and contains unreleased and potentially breaking changes. If you are looking for the most recent stable release you want the [v0-stable branch](https://github.com/adimichele/hubspot-ruby/tree/v0-stable).**
|
4
|
+
|
5
|
+
Wraps the HubSpot REST API for convenient access from ruby applications.
|
6
|
+
|
7
|
+
Documentation for the HubSpot REST API can be found here: https://developers.hubspot.com/docs/endpoints
|
8
|
+
|
9
|
+
## Setup
|
10
|
+
|
11
|
+
gem install hubspot-api-ruby
|
12
|
+
|
13
|
+
Or with bundler,
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem "hubspot-api-ruby"
|
17
|
+
```
|
18
|
+
|
19
|
+
## Getting Started
|
20
|
+
This library can be configured to use OAuth or an API key. To find the
|
21
|
+
appropriate values for either approach, please visit the [HubSpot API
|
22
|
+
Authentication docs].
|
23
|
+
|
24
|
+
Below is a complete list of configuration options with the default values:
|
25
|
+
```ruby
|
26
|
+
Hubspot.configure({
|
27
|
+
hapikey: <HAPIKEY>,
|
28
|
+
base_url: "https://api.hubapi.com",
|
29
|
+
portal_id: <PORTAL_ID>,
|
30
|
+
logger: Logger.new(nil),
|
31
|
+
access_token: <ACCESS_TOKEN>,
|
32
|
+
client_id: <CLIENT_ID>,
|
33
|
+
client_secret: <CLIENT_SECRET>,
|
34
|
+
redirect_uri: <REDIRECT_URI>,
|
35
|
+
read_timeout: nil, # or :timeout to set read_timeout and open_timeout
|
36
|
+
open_timeout: nil,
|
37
|
+
})
|
38
|
+
```
|
39
|
+
|
40
|
+
If you're new to using the HubSpot API, visit the [HubSpot Developer Tools] to
|
41
|
+
learn about topics like "what's a portal id?" and creating a testing
|
42
|
+
environment.
|
43
|
+
|
44
|
+
[HubSpot API Authentication Docs]: https://developers.hubspot.com/docs/methods/auth/oauth-overview
|
45
|
+
[HubSpot Developer Tools]: https://developers.hubspot.com/docs/devtools
|
46
|
+
|
47
|
+
## Authentication with an API key
|
48
|
+
|
49
|
+
To set the HubSpot API key, aka `hapikey`, run the following:
|
50
|
+
```ruby
|
51
|
+
Hubspot.configure(hapikey: "YOUR_API_KEY")
|
52
|
+
```
|
53
|
+
|
54
|
+
If you have a HubSpot account, you can find your API key by logging in and
|
55
|
+
visiting: https://app.hubspot.com/keys/get
|
56
|
+
|
57
|
+
## Authentication with OAuth 2.0
|
58
|
+
|
59
|
+
Configure the library with the client ID and secret from your [HubSpot App](https://developers.hubspot.com/docs/faq/how-do-i-create-an-app-in-hubspot)
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
Hubspot.configure(
|
63
|
+
client_id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
64
|
+
client_secret: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
65
|
+
redirect_uri: "https://myapp.com/oauth")
|
66
|
+
```
|
67
|
+
|
68
|
+
To initiate an OAuth connection to your app, create a URL with the required scopes:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
Hubspot::OAuth.authorize_url(["contacts", "content"])
|
72
|
+
```
|
73
|
+
|
74
|
+
After the user accepts the scopes and installs the integration with their HubSpot account, they will be redirected to the URI requested with the query parameter `code` appended to the URL. `code` can then be passed to HubSpot to generate an access token:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
Hubspot::OAuth.create(params[:code])
|
78
|
+
```
|
79
|
+
|
80
|
+
To use the returned `access_token` string for authentication, you'll need to update the configuration:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
Hubspot.configure(
|
84
|
+
client_id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
85
|
+
client_secret: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
86
|
+
redirect_uri: "https://myapp.com/oauth",
|
87
|
+
access_token: access_token)
|
88
|
+
```
|
89
|
+
|
90
|
+
Now all requests will use the provided access token when querying the API:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
Hubspot::Contact.all
|
94
|
+
```
|
95
|
+
|
96
|
+
### Refreshing the token
|
97
|
+
|
98
|
+
When you create a HubSpot OAuth token, it will have an expiration date given by the `expires_in` field returned from the create API. If you with to continue using the token without needing to create another, you'll need to refresh the token:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
Hubspot::OAuth.refresh(refresh_token)
|
102
|
+
```
|
103
|
+
|
104
|
+
### A note on OAuth credentials
|
105
|
+
|
106
|
+
At this time, OAuth tokens are configured globally rather than on a per-connection basis.
|
107
|
+
|
108
|
+
## Usage
|
109
|
+
|
110
|
+
Classes have been created that map to Hubspot resource types and attempt to abstract away as much of the API specific details as possible. These classes generally follow the [ActiveRecord](https://en.wikipedia.org/wiki/Active_record_pattern) pattern and general Ruby conventions. Anyone familiar with [Ruby On Rails](https://rubyonrails.org/) should find this API closely maps with familiar concepts.
|
111
|
+
|
112
|
+
|
113
|
+
### Creating a new resource
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
irb(main):001:0> company = Hubspot::Company.new(name: "My Company LLC.")
|
117
|
+
=> #<Hubspot::Company:0x000055b9219cc068 @changes={"name"=>"My Company LLC."}, @properties={}, @id=nil, @persisted=false, @deleted=false>
|
118
|
+
|
119
|
+
irb(main):002:0> company.persisted?
|
120
|
+
=> false
|
121
|
+
|
122
|
+
irb(main):003:0> company.save
|
123
|
+
=> true
|
124
|
+
|
125
|
+
irb(main):004:0> company.persisted?
|
126
|
+
=> true
|
127
|
+
```
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
irb(main):001:0> company = Hubspot::Company.create(name: "Second Financial LLC.")
|
131
|
+
=> #<Hubspot::Company:0x0000557ea7119fb0 @changes={}, @properties={"hs_lastmodifieddate"=>{"value"=>"1552234087467", "timestamp"=>1552234087467, "source"=>"CALCULATED", "sourceId"=>nil, "versions"=>[{"name"=>"hs_lastmodifieddate", "value"=>"1552234087467", "timestamp"=>1552234087467, "source"=>"CALCULATED", "sourceVid"=>[], "requestId"=>"fd45773b-30d0-4d9d-b3b8-a85e01534e46"}]}, "name"=>{"value"=>"Second Financial LLC.", "timestamp"=>1552234087467, "source"=>"API", "sourceId"=>nil, "versions"=>[{"name"=>"name", "value"=>"Second Financial LLC.", "timestamp"=>1552234087467, "source"=>"API", "sourceVid"=>[], "requestId"=>"fd45773b-30d0-4d9d-b3b8-a85e01534e46"}]}, "createdate"=>{"value"=>"1552234087467", "timestamp"=>1552234087467, "source"=>"API", "sourceId"=>nil, "versions"=>[{"name"=>"createdate", "value"=>"1552234087467", "timestamp"=>1552234087467, "source"=>"API", "sourceVid"=>[], "requestId"=>"fd45773b-30d0-4d9d-b3b8-a85e01534e46"}, {"name"=>"createdate", "value"=>"1552234087467", "timestamp"=>1552234087467, "sourceId"=>"API", "source"=>"API", "sourceVid"=>[], "requestId"=>"fd45773b-30d0-4d9d-b3b8-a85e01534e46"}]}}, @id=1726317857, @persisted=true, @deleted=false, @metadata={"portalId"=>62515, "companyId"=>1726317857, "isDeleted"=>false, "additionalDomains"=>[], "stateChanges"=>[], "mergeAudits"=>[]}>
|
132
|
+
|
133
|
+
irb(main):002:0> company.persisted?
|
134
|
+
=> true
|
135
|
+
```
|
136
|
+
|
137
|
+
|
138
|
+
### Find an existing resource
|
139
|
+
|
140
|
+
**Note:** Hubspot uses a combination of different names for the "ID" property of a resource based on what type of resource it is (eg. vid for Contact). This library attempts to abstract that away and generalizes an `id` property for all resources
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
irb(main):001:0> company = Hubspot::Company.find(1726317857)
|
144
|
+
=> #<Hubspot::Company:0x0000562e4988c9a8 @changes={}, @properties={"hs_lastmodifieddate"=>{"value"=>"1552234087467", "timestamp"=>1552234087467, "source"=>"CALCULATED", "sourceId"=>nil, "versions"=>[{"name"=>"hs_lastmodifieddate", "value"=>"1552234087467", "timestamp"=>1552234087467, "source"=>"CALCULATED", "sourceVid"=>[], "requestId"=>"fd45773b-30d0-4d9d-b3b8-a85e01534e46"}]}, "name"=>{"value"=>"Second Financial LLC.", "timestamp"=>1552234087467, "source"=>"API", "sourceId"=>nil, "versions"=>[{"name"=>"name", "value"=>"Second Financial LLC.", "timestamp"=>1552234087467, "source"=>"API", "sourceVid"=>[], "requestId"=>"fd45773b-30d0-4d9d-b3b8-a85e01534e46"}]}, "createdate"=>{"value"=>"1552234087467", "timestamp"=>1552234087467, "source"=>"API", "sourceId"=>nil, "versions"=>[{"name"=>"createdate", "value"=>"1552234087467", "timestamp"=>1552234087467, "source"=>"API", "sourceVid"=>[], "requestId"=>"fd45773b-30d0-4d9d-b3b8-a85e01534e46"}]}}, @id=1726317857, @persisted=true, @deleted=false, @metadata={"portalId"=>62515, "companyId"=>1726317857, "isDeleted"=>false, "additionalDomains"=>[], "stateChanges"=>[], "mergeAudits"=>[]}>
|
145
|
+
|
146
|
+
irb(main):002:0> company = Hubspot::Company.find(1)
|
147
|
+
Traceback (most recent call last):
|
148
|
+
6: from ./hubspot-api-ruby/bin/console:20:in `<main>'
|
149
|
+
5: from (irb):2
|
150
|
+
4: from ./hubspot-api-ruby/lib/hubspot/resource.rb:17:in `find'
|
151
|
+
3: from ./hubspot-api-ruby/lib/hubspot/resource.rb:81:in `reload'
|
152
|
+
2: from ./hubspot-api-ruby/lib/hubspot/connection.rb:10:in `get_json'
|
153
|
+
1: from ./hubspot-api-ruby/lib/hubspot/connection.rb:52:in `handle_response'
|
154
|
+
Hubspot::RequestError (Response body: {"status":"error","message":"resource not found","correlationId":"7c8ba50e-16a4-4a52-a304-ff249175a8f1","requestId":"b4898274bf8992924082b4a460b90cbe"})
|
155
|
+
```
|
156
|
+
|
157
|
+
|
158
|
+
### Updating resource properties
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
irb(main):001:0> company = Hubspot::Company.find(1726317857)
|
162
|
+
=> #<Hubspot::Company:0x0000563b9f3ee230 @changes={}, @properties={"hs_lastmodifieddate"=>{"value"=>"1552234087467", "timestamp"=>1552234087467, "source"=>"CALCULATED", "sourceId"=>nil, "versions"=>[{"name"=>"hs_lastmodifieddate", "value"=>"1552234087467", "timestamp"=>1552234087467, "source"=>"CALCULATED", "sourceVid"=>[], "requestId"=>"fd45773b-30d0-4d9d-b3b8-a85e01534e46"}]}, "name"=>{"value"=>"Second Financial LLC.", "timestamp"=>1552234087467, "source"=>"API", "sourceId"=>nil, "versions"=>[{"name"=>"name", "value"=>"Second Financial LLC.", "timestamp"=>1552234087467, "source"=>"API", "sourceVid"=>[], "requestId"=>"fd45773b-30d0-4d9d-b3b8-a85e01534e46"}]}, "createdate"=>{"value"=>"1552234087467", "timestamp"=>1552234087467, "source"=>"API", "sourceId"=>nil, "versions"=>[{"name"=>"createdate", "value"=>"1552234087467", "timestamp"=>1552234087467, "source"=>"API", "sourceVid"=>[], "requestId"=>"fd45773b-30d0-4d9d-b3b8-a85e01534e46"}]}}, @id=1726317857, @persisted=true, @deleted=false, @metadata={"portalId"=>62515, "companyId"=>1726317857, "isDeleted"=>false, "additionalDomains"=>[], "stateChanges"=>[], "mergeAudits"=>[]}>
|
163
|
+
|
164
|
+
irb(main):002:0> company.name
|
165
|
+
=> "Second Financial LLC."
|
166
|
+
|
167
|
+
irb(main):003:0> company.name = "Third Financial LLC."
|
168
|
+
=> "Third Financial LLC."
|
169
|
+
|
170
|
+
irb(main):004:0> company.changed?
|
171
|
+
=> true
|
172
|
+
|
173
|
+
irb(main):005:0> company.changes
|
174
|
+
=> {:name=>"Third Financial LLC."}
|
175
|
+
|
176
|
+
irb(main):006:0> company.save
|
177
|
+
=> true
|
178
|
+
|
179
|
+
irb(main):007:0> company.changed?
|
180
|
+
=> false
|
181
|
+
|
182
|
+
irb(main):008:0> company.changes
|
183
|
+
=> {}
|
184
|
+
```
|
185
|
+
|
186
|
+
**Note:** Unlike ActiveRecord in Rails, in some cases not all properties of a resource are known. If these properties are not returned by the API then they will not have a getter method defined for them until they've been set first. This may change in the future to improve the user experience and different methods are being tested.
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
irb(main):001:0> company = Hubspot::Company.new
|
190
|
+
=> #<Hubspot::Company:0x0000561d0a8bdff8 @changes={}, @properties={}, @id=nil, @persisted=false, @deleted=false>
|
191
|
+
|
192
|
+
irb(main):002:0> company.name
|
193
|
+
Traceback (most recent call last):
|
194
|
+
3: from ./hubspot-api-ruby/bin/console:20:in `<main>'
|
195
|
+
2: from (irb):2
|
196
|
+
1: from ./hubspot-api-ruby/lib/hubspot/resource.rb:215:in `method_missing'
|
197
|
+
NoMethodError (undefined method `name' for #<Hubspot::Company:0x0000561d0a8bdff8>)
|
198
|
+
|
199
|
+
irb(main):003:0> company.name = "Foobar"
|
200
|
+
=> "Foobar"
|
201
|
+
|
202
|
+
irb(main):004:0> company.name
|
203
|
+
=> "Foobar"
|
204
|
+
```
|
205
|
+
|
206
|
+
### Collections
|
207
|
+
|
208
|
+
To make working with API endpoints that return multiple resources easier, the returned instances will be wrapped in a collection instance. Just like in Rails, the collection instance provides helper methods for limiting the number of returned resources, paging through the results, and handles passing the options each time a new API call is made. The collection exposes all Ruby Array methods so you can use things like `size()`, `first()`, `last()`, and `map()`.
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
irb(main):001:0> contacts = Hubspot::Contact.all
|
212
|
+
=> #<Hubspot::PagedCollection:0x000055ba3c2b55d8 @limit_param="limit", @limit=25, @offset_param="offset", @offset=nil, @options={}, @fetch_proc=#<Proc:0x000055ba3c2b5538@./hubspot-api-ruby/lib/hubspot/contact.rb:18>, @resources=[...snip...], @next_offset=9242374, @has_more=true>
|
213
|
+
|
214
|
+
irb(main):002:0> contacts.more?
|
215
|
+
=> true
|
216
|
+
|
217
|
+
irb(main):003:0> contacts.next_offset
|
218
|
+
=> 9242374
|
219
|
+
|
220
|
+
irb(main):004:0> contacts.size
|
221
|
+
=> 25
|
222
|
+
|
223
|
+
irb(main):005:0> contacts.first
|
224
|
+
=> #<Hubspot::Contact:0x000055ba3c29bac0 @changes={}, @properties={"firstname"=>{"value"=>"My Street X 1551971239 => My Street X 1551971267 => My Street X 1551971279"}, "lastmodifieddate"=>{"value"=>"1551971286841"}, "company"=>{"value"=>"MadKudu"}, "lastname"=>{"value"=>"Test0830181615"}}, @id=9153674, @persisted=true, @deleted=false, @metadata={"addedAt"=>1535664601481, "vid"=>9153674, "canonical-vid"=>9153674, "merged-vids"=>[], "portal-id"=>62515, "is-contact"=>true, "profile-token"=>"AO_T-mPNHk6O7jh8u8D2IlrhZn7GO91w-weZrC93_UaJvdB0U4o6Uc_PkPJ3DOpf15sUplrxMzG9weiTTpPI05Nr04zxnaNYBVcWHOlMbVlJ2Avq1KGoCBVbIoQucOy_YmCBIfOXRtcc", "profile-url"=>"https://app.hubspot.com/contacts/62515/contact/9153674", "form-submissions"=>[], "identity-profiles"=>[{"vid"=>9153674, "saved-at-timestamp"=>1535664601272, "deleted-changed-timestamp"=>0, "identities"=>[{"type"=>"EMAIL", "value"=>"test.0830181615@test.com", "timestamp"=>1535664601151, "is-primary"=>true}, {"type"=>"LEAD_GUID", "value"=>"01a107c4-3872-44e0-ab2e-47061507ffa1", "timestamp"=>1535664601259}]}], "merge-audits"=>[]}>
|
225
|
+
|
226
|
+
irb(main):006:0> contacts.next_page
|
227
|
+
=> #<Hubspot::PagedCollection:0x000055ba3c2b55d8 @limit_param="limit", @limit=25, @offset_param="offset", @offset=9242374, @options={}, @fetch_proc=#<Proc:0x000055ba3c2b5538@./hubspot-api-ruby/lib/hubspot/contact.rb:18>, @resources=[...snip...], @next_offset=9324874, @has_more=true>
|
228
|
+
```
|
229
|
+
|
230
|
+
For Hubspot resources that support batch updates for updating multiple resources, the collection provides an `update_all()` method:
|
231
|
+
|
232
|
+
```ruby
|
233
|
+
irb(main):001:0> companies = Hubspot::Company.all(limit: 5)
|
234
|
+
=> #<Hubspot::PagedCollection:0x000055d5314fe0c8 @limit_param="limit", @limit=5, @offset_param="offset", @offset=nil, @options={}, @fetch_proc=#<Proc:0x000055d5314fe028@./hubspot-api-ruby/lib/hubspot/company.rb:21>, @resources=[...snip...], @next_offset=116011506, @has_more=true>
|
235
|
+
|
236
|
+
irb(main):002:0> companies.size
|
237
|
+
=> 5
|
238
|
+
|
239
|
+
irb(main):003:0> companies.update_all(lifecyclestage: "opportunity")
|
240
|
+
=> true
|
241
|
+
|
242
|
+
irb(main):004:0> companies.refresh
|
243
|
+
=> #<Hubspot::PagedCollection:0x000055d5314fe0c8 @limit_param="limit", @limit=5, @offset_param="offset", @offset=nil, @options={}, @fetch_proc=#<Proc:0x000055d5314fe028@./hubspot-api-ruby/lib/hubspot/company.rb:21>, @resources=[...snip...], @next_offset=116011506, @has_more=true>
|
244
|
+
```
|
245
|
+
|
246
|
+
### Deleting a resource
|
247
|
+
|
248
|
+
```ruby
|
249
|
+
irb(main):001:0> contact = Hubspot::Contact.find(9324874)
|
250
|
+
=> #<Hubspot::Contact:0x000055a87c87aee0 ...snip... >
|
251
|
+
|
252
|
+
irb(main):002:0> contact.delete
|
253
|
+
=> true
|
254
|
+
```
|
255
|
+
|
256
|
+
## Resource types
|
257
|
+
|
258
|
+
**Note:** These are the currently defined classes the support the new resource API. This list will continue to grow as we update other classes. All existing classes will be updated prior to releasing v1.0.
|
259
|
+
|
260
|
+
* Contact -> Hubspot::Contact
|
261
|
+
* Company -> Hubspot::Company
|
262
|
+
|
263
|
+
## Contributing to hubspot-api-ruby
|
264
|
+
|
265
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
266
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
267
|
+
* Fork the project.
|
268
|
+
* Start a feature/bugfix branch.
|
269
|
+
* Commit and push until you are happy with your contribution.
|
270
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
271
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
272
|
+
|
273
|
+
### Testing
|
274
|
+
|
275
|
+
This project uses [VCR] to test interactions with the HubSpot API.
|
276
|
+
VCR records HTTP requests and replays them during future tests.
|
277
|
+
|
278
|
+
To run the tests, run `bundle exec rake` or `bundle exec rspec`.
|
279
|
+
|
280
|
+
By default, the VCR recording mode is set to `:none`, which allows recorded
|
281
|
+
requests to be re-played but raises for any new request. This prevents the test
|
282
|
+
suite from issuing unexpected HTTP requests.
|
283
|
+
|
284
|
+
To add a new test or update a VCR recording, run the test with the `VCR_RECORD`
|
285
|
+
environment variable:
|
286
|
+
|
287
|
+
```sh
|
288
|
+
VCR_RECORD=1 bundle exec rspec spec
|
289
|
+
```
|
290
|
+
|
291
|
+
[VCR]: https://github.com/vcr/vcr
|
292
|
+
|
293
|
+
## Disclaimer
|
294
|
+
|
295
|
+
This project and the code therein was not created by and is not supported by HubSpot, Inc or any of its affiliates.
|
data/RELEASING.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'rspec/core'
|
15
|
+
require 'rspec/core/rake_task'
|
16
|
+
|
17
|
+
RSpec::Core::RakeTask.new(:spec)
|
18
|
+
|
19
|
+
desc "Default: runs the full test suite."
|
20
|
+
task default: :spec
|
21
|
+
|
22
|
+
require 'rdoc/task'
|
23
|
+
Rake::RDocTask.new do |rdoc|
|
24
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
25
|
+
|
26
|
+
rdoc.rdoc_dir = 'rdoc'
|
27
|
+
rdoc.title = "hubspot-api-ruby #{version}"
|
28
|
+
rdoc.rdoc_files.include('README*')
|
29
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
30
|
+
end
|
31
|
+
|
32
|
+
Dir.glob('lib/tasks/*.rake').each { |r| load r }
|
@@ -0,0 +1,42 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "hubspot-api-ruby"
|
3
|
+
s.version = "0.8.0"
|
4
|
+
s.require_paths = ["lib"]
|
5
|
+
s.authors = ["Jonathan", "Juliette"]
|
6
|
+
s.email = ["jonathan@hoggo.com", "juliette@hoggo.com"]
|
7
|
+
s.description = "hubspot-api-ruby is a wrapper for the HubSpot REST API"
|
8
|
+
s.licenses = ["MIT"]
|
9
|
+
s.files = [".rspec", "Gemfile", "Guardfile", "LICENSE.txt", "README.md", "RELEASING.md", "Rakefile", "hubspot-api-ruby.gemspec"]
|
10
|
+
s.files += Dir["lib/**/*.rb"]
|
11
|
+
s.files += Dir["lib/**/*.rake"]
|
12
|
+
s.files += Dir["spec/**/*.rb"]
|
13
|
+
s.homepage = "http://github.com/lounna-sas/hubspot-api-ruby"
|
14
|
+
s.summary = "hubspot-api-ruby is a wrapper for the HubSpot REST API"
|
15
|
+
s.metadata = {
|
16
|
+
"changelog_uri" => "https://github.com/lounna-sas/hubspot-api-ruby/blob/master/History.md"
|
17
|
+
}
|
18
|
+
|
19
|
+
s.required_ruby_version = ">= 2.3"
|
20
|
+
|
21
|
+
# Add runtime dependencies here
|
22
|
+
s.add_runtime_dependency "activesupport", ">= 4.2.2"
|
23
|
+
s.add_runtime_dependency "httparty", ">= 0.10"
|
24
|
+
|
25
|
+
# Add development-only dependencies here
|
26
|
+
s.add_development_dependency("appraisal", "~> 2.2")
|
27
|
+
s.add_development_dependency("dotenv")
|
28
|
+
s.add_development_dependency("rake", "~> 11.0")
|
29
|
+
s.add_development_dependency("rspec", "~> 3.8")
|
30
|
+
s.add_development_dependency("rspec-its", "~> 1.2")
|
31
|
+
s.add_development_dependency("webmock")
|
32
|
+
s.add_development_dependency("vcr")
|
33
|
+
s.add_development_dependency("rdoc")
|
34
|
+
s.add_development_dependency("bundler")
|
35
|
+
s.add_development_dependency("simplecov")
|
36
|
+
s.add_development_dependency("awesome_print")
|
37
|
+
s.add_development_dependency("timecop")
|
38
|
+
s.add_development_dependency("guard-rspec")
|
39
|
+
s.add_development_dependency("byebug")
|
40
|
+
s.add_development_dependency("faker")
|
41
|
+
s.add_development_dependency("factory_bot")
|
42
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
require 'httparty'
|
4
|
+
require 'hubspot/exceptions'
|
5
|
+
require 'hubspot/resource'
|
6
|
+
require 'hubspot/collection'
|
7
|
+
require 'hubspot/paged_collection'
|
8
|
+
require 'hubspot/properties'
|
9
|
+
require 'hubspot/company'
|
10
|
+
require 'hubspot/company_properties'
|
11
|
+
require 'hubspot/config'
|
12
|
+
require 'hubspot/connection'
|
13
|
+
require 'hubspot/contact'
|
14
|
+
require 'hubspot/contact_properties'
|
15
|
+
require 'hubspot/contact_list'
|
16
|
+
require 'hubspot/event'
|
17
|
+
require 'hubspot/form'
|
18
|
+
require 'hubspot/blog'
|
19
|
+
require 'hubspot/topic'
|
20
|
+
require 'hubspot/deal'
|
21
|
+
require 'hubspot/deal_pipeline'
|
22
|
+
require 'hubspot/deal_properties'
|
23
|
+
require 'hubspot/deprecator'
|
24
|
+
require 'hubspot/owner'
|
25
|
+
require 'hubspot/engagement'
|
26
|
+
require 'hubspot/subscription'
|
27
|
+
require 'hubspot/oauth'
|
28
|
+
require 'hubspot/file'
|
29
|
+
|
30
|
+
module Hubspot
|
31
|
+
def self.configure(config={})
|
32
|
+
Hubspot::Config.configure(config)
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'hubspot/railtie' if defined?(Rails)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Alias the module for those looking to use the stylized name HubSpot
|
39
|
+
HubSpot = Hubspot
|