hubspot_v3 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +9 -5
- data/lib/hubspot_v3/version.rb +1 -1
- data/lib/hubspot_v3.rb +29 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0d20f6a8537ba36435a57682fc297817d8172bc6918e94a114ef8d8f0e5f1cc
|
4
|
+
data.tar.gz: 7c2d6829f3d59310be90b89b5393318865c8723c129f27e71431f855903ceede
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bca4bf7caba1c559c41cfeba769b2c163d80f160661b5e69064c764f88496431cdd0f0397f8571653619b09355da12b4e40502f2898190e57835641a7366b3b4
|
7
|
+
data.tar.gz: 53359b29589e94b29d1dde13a0d6da7c716df63c0020910c32e187a403f0812f9506db43ac58b2bb7c40382cab116a517f1cba181bcb5bbcd37633151803c51d
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hubspot_v3 (
|
4
|
+
hubspot_v3 (1.0.0)
|
5
5
|
httparty (~> 0.2)
|
6
6
|
|
7
7
|
GEM
|
@@ -11,9 +11,9 @@ GEM
|
|
11
11
|
httparty (0.20.0)
|
12
12
|
mime-types (~> 3.0)
|
13
13
|
multi_xml (>= 0.5.2)
|
14
|
-
mime-types (3.
|
14
|
+
mime-types (3.4.1)
|
15
15
|
mime-types-data (~> 3.2015)
|
16
|
-
mime-types-data (3.
|
16
|
+
mime-types-data (3.2022.0105)
|
17
17
|
multi_xml (0.6.0)
|
18
18
|
rake (13.0.6)
|
19
19
|
rspec (3.10.0)
|
data/README.md
CHANGED
@@ -28,9 +28,11 @@ It's possible to use our gem along with any of these two gems.
|
|
28
28
|
Add this line to your application's Gemfile:
|
29
29
|
|
30
30
|
```ruby
|
31
|
-
gem 'hubspot_v3',
|
31
|
+
gem 'hubspot_v3', '~> 1.0'
|
32
32
|
```
|
33
33
|
|
34
|
+
[![Gem Version](https://badge.fury.io/rb/hubspot_v3.svg)](https://badge.fury.io/rb/hubspot_v3)
|
35
|
+
|
34
36
|
And then execute:
|
35
37
|
|
36
38
|
$ bundle install
|
@@ -321,13 +323,15 @@ require 'hubspot_v3/mock_contract'
|
|
321
323
|
HubspotV3::MockContract.contacts_search_by_emails(["hello@pobble.com", "notfound@pobble.com", "info@pobble.com"])
|
322
324
|
# [
|
323
325
|
# {
|
324
|
-
# "id" => 1589,
|
326
|
+
# "id" => 1589,
|
327
|
+
# "properties" => {
|
325
328
|
# "email"=>"hello@pobble.com",
|
326
329
|
# ...
|
327
330
|
# }
|
328
331
|
# },
|
329
|
-
|
330
|
-
# "id" => 1485,
|
332
|
+
# {
|
333
|
+
# "id" => 1485,
|
334
|
+
# "properties" => {
|
331
335
|
# "email"=>"info@pobble.com",
|
332
336
|
# ...
|
333
337
|
# }
|
@@ -338,7 +342,7 @@ HubspotV3::MockContract.contacts_search_by_emails_mapped(["hello@pobble.com", "n
|
|
338
342
|
# => ["hello@pobble.com", "info@pobble.com"]
|
339
343
|
```
|
340
344
|
|
341
|
-
`id` field of test Contact contracts is calculated as `'info@pobble.com'.bytes.sum == 1485
|
345
|
+
`id` field of test Contact contracts is calculated as `'info@pobble.com'.bytes.sum == 1485` ([source](https://github.com/Pobble/hubspot_v3/blob/master/lib/hubspot_v3/mock_contract.rb#L181)), create contacts will be `'info@pobble.com'.bytes.sum + 1_000_000 == 1001485` ([source](https://github.com/Pobble/hubspot_v3/blob/master/lib/hubspot_v3/mock_contract.rb#L29))
|
342
346
|
|
343
347
|
> More info on how to use [Contract tests](https://blog.eq8.eu/article/explicit-contracts-for-rails-http-api-usecase.html)
|
344
348
|
|
data/lib/hubspot_v3/version.rb
CHANGED
data/lib/hubspot_v3.rb
CHANGED
@@ -15,6 +15,8 @@ module HubspotV3
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
HubspotRequestLimitReached = Class.new(RequestFailedError)
|
19
|
+
|
18
20
|
API_URL='https://api.hubapi.com'
|
19
21
|
CONTACTS_SEARCH='/crm/v3/objects/contacts/search'
|
20
22
|
CONTACTS_CREATE='/crm/v3/objects/contacts/batch/create'
|
@@ -90,15 +92,26 @@ module HubspotV3
|
|
90
92
|
end
|
91
93
|
|
92
94
|
def self.post(path, bodyhash)
|
93
|
-
|
95
|
+
httparty_response = HTTParty.post(url(path), {
|
94
96
|
body: bodyhash.to_json,
|
95
97
|
headers: headers
|
96
98
|
})
|
97
|
-
case
|
99
|
+
case httparty_response.code
|
98
100
|
when 200, 201
|
99
|
-
|
101
|
+
httparty_response.parsed_response['results']
|
102
|
+
when 429
|
103
|
+
# Hubspot error 429 - You have reached your secondly limit.
|
104
|
+
raise _hubspot_request_limit_reached_error(httparty_response)
|
105
|
+
when 500
|
106
|
+
if httparty_response.parsed_response["category"] == "RATE_LIMITS"
|
107
|
+
# e.g.: {"status":"error","message":"You have reached your secondly limit.","category":"RATE_LIMITS"}
|
108
|
+
# Yes, Hubspot will sometimes give 429 or 500 when limit reached
|
109
|
+
raise _hubspot_request_limit_reached_error(httparty_response)
|
110
|
+
else
|
111
|
+
raise _hubspot_request_failed_error(httparty_response)
|
112
|
+
end
|
100
113
|
else
|
101
|
-
raise
|
114
|
+
raise _hubspot_request_failed_error(httparty_response)
|
102
115
|
end
|
103
116
|
end
|
104
117
|
|
@@ -108,4 +121,16 @@ module HubspotV3
|
|
108
121
|
'Authorization': "Bearer #{config.token}"
|
109
122
|
}
|
110
123
|
end
|
124
|
+
|
125
|
+
def self._hubspot_request_limit_reached_error(httparty_response)
|
126
|
+
code = httparty_response.code
|
127
|
+
message = httparty_response.parsed_response['message']
|
128
|
+
HubspotV3::HubspotRequestLimitReached.new("#{code} - #{message}", httparty_response)
|
129
|
+
end
|
130
|
+
|
131
|
+
def self._hubspot_request_failed_error(httparty_response)
|
132
|
+
code = httparty_response.code
|
133
|
+
message = httparty_response.parsed_response['message']
|
134
|
+
HubspotV3::RequestFailedError.new("#{code} - #{message}", httparty_response)
|
135
|
+
end
|
111
136
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hubspot_v3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Valent
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|