hubspot_v3 1.0.0 → 1.1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 831c706b12ca929919b9521451a44350194678d709e200fa5be2344142248fbd
4
- data.tar.gz: acc7373fdf69e5d5265c4b5288187920f3cddbc4fd4014be1ad846dcd331ce75
3
+ metadata.gz: fa96d005917fcc2fac310755d0986e91214f65d0a255241aee766357200ae628
4
+ data.tar.gz: 77c75a7d0db6271e1495c0408face4920d34ba19689c2a5cbf478b6d832c8121
5
5
  SHA512:
6
- metadata.gz: c44773f8b1eb6f67e7013692c0ba301ff350426c30e339ef6eb36d441d7f54176a9a5487ff3432e21bc2652758ef8a85001e96daa45a70d2b3363d7c196edc35
7
- data.tar.gz: cfe059ca979b2b6153ee18c793a8fd440b714c8be7a68c8811e6ff3ce3cb77c668d61dd59d3f20c3d0370f39bac9fea816ea6c9364d5eced63f28ebb2521b1a5
6
+ metadata.gz: 5c5f35449494040503f10355f1dc159996b9b28fa91165a94677f2c2d9b947d4382b18fcc5960fc109df287f68508e0c2ec271236ffadbcbceaa5e9e5c03ae47
7
+ data.tar.gz: 50645a7ace7c184269dea68367d35851406da22c26f6abb683436f0bc7cab98cf3e15dfd74dec1c6989b8d14932d9c34926013ce42275b4362e3d2a0d5f3eed2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hubspot_v3 (0.1.0)
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.3.1)
14
+ mime-types (3.4.1)
15
15
  mime-types-data (~> 3.2015)
16
- mime-types-data (3.2021.0901)
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', github: 'Pobble/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, "properties" => {
326
+ # "id" => 1589,
327
+ # "properties" => {
325
328
  # "email"=>"hello@pobble.com",
326
329
  # ...
327
330
  # }
328
331
  # },
329
- {
330
- # "id" => 1485, "properties" => {
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`, create contacts will be `'info@pobble.com'.bytes.sum + 1_000_000 == 1001485`
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/hubspot_v3.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
6
6
  spec.name = "hubspot_v3"
7
7
  spec.version = HubspotV3::VERSION
8
8
  spec.authors = ["Tomas Valent"]
9
- spec.email = ["tomas.valent@gmail.com"]
9
+ spec.email = ["equivalent@eq8.eu"]
10
10
 
11
11
  spec.summary = "Hubspot CRM API (v3) Ruby gem"
12
12
  spec.description = "Ruby wrapper around Hubspot CRM API v3 with simple implementation around batch endpoints and private apps token support"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HubspotV3
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0.1"
5
5
  end
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
- res = HTTParty.post(url(path), {
95
+ httparty_response = HTTParty.post(url(path), {
94
96
  body: bodyhash.to_json,
95
97
  headers: headers
96
98
  })
97
- case res.code
99
+ case httparty_response.code
98
100
  when 200, 201
99
- res.parsed_response['results']
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 HubspotV3::RequestFailedError.new("#{res.code} - #{res.parsed_response['message']}", res)
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.0.0
4
+ version: 1.1.0.1
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-28 00:00:00.000000000 Z
11
+ date: 2022-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -27,7 +27,7 @@ dependencies:
27
27
  description: Ruby wrapper around Hubspot CRM API v3 with simple implementation around
28
28
  batch endpoints and private apps token support
29
29
  email:
30
- - tomas.valent@gmail.com
30
+ - equivalent@eq8.eu
31
31
  executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []