hubspot-api-client 14.2.0 → 14.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4cf7152f7d94654ae7efaef840fc2232392091973642e5b6a877358d665c687
4
- data.tar.gz: 7f9b630bc30d894300a8317f170583c1179684f3915f50055821e63fe892bcb4
3
+ metadata.gz: 3229748b2d14e474894aecf5f28d60ae7ace8f5dda38d98daa34a2bbda93e033
4
+ data.tar.gz: 2867ef54025f5caa340e9ad28e7fafa940cb88bc8b11142b6f75d45df8e6829a
5
5
  SHA512:
6
- metadata.gz: 4a22483996355e355ca0efe55b88d83a66f704936920a64287c05e175a9348a1039acdf6652f3811a380a31c6aceda9be648768b25e9e807035e3e051b1699ba
7
- data.tar.gz: 4ba24e78d4f838a817c96a8bd8b3681809d50a2a886dab6b078090423239421794917b79de0eb17e8bfe91b735ac4bfa42a3e66633bef5dfeebb760d98c02cc0
6
+ metadata.gz: 13932717d618997bff59721afe32a3480b30f579d299837d55f925cd1b47f300a70143245d954fadc14b8ca408587051abe355900310d34543e243ea866129a6
7
+ data.tar.gz: 59711b28a7e2b9fe86fe610434d4bcbb1065ece4812c5448e5856ba53fa77ba275eb6df9bfd24299fae494e98858ddfc94dbd5a4f29c51412be942a86d931d8f
data/CHANGELOG.md CHANGED
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [14.4.0] - 2022-09-27
9
+ ### Changed
10
+
11
+ - handling ApiError by passing a block
12
+
13
+ ## [14.3.0] - 2022-08-31
14
+ ### Changed
15
+
16
+ - using hash instead of model object for Hubspot::Client with body param
17
+
8
18
  ## [14.2.0] - 2022-08-25
9
19
  ### Changed
10
20
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hubspot-api-client (14.2.0)
4
+ hubspot-api-client (14.4.0)
5
5
  json (~> 2.1, >= 2.1.0)
6
6
  require_all (~> 3.0.0)
7
7
  typhoeus (~> 1.4.0)
@@ -41,13 +41,13 @@ GEM
41
41
  rspec-mocks (~> 3.11.0)
42
42
  rspec-core (3.11.0)
43
43
  rspec-support (~> 3.11.0)
44
- rspec-expectations (3.11.0)
44
+ rspec-expectations (3.11.1)
45
45
  diff-lcs (>= 1.2.0, < 2.0)
46
46
  rspec-support (~> 3.11.0)
47
47
  rspec-mocks (3.11.1)
48
48
  diff-lcs (>= 1.2.0, < 2.0)
49
49
  rspec-support (~> 3.11.0)
50
- rspec-support (3.11.0)
50
+ rspec-support (3.11.1)
51
51
  typhoeus (1.4.0)
52
52
  ethon (>= 0.9.0)
53
53
  vcr (3.0.3)
data/README.md CHANGED
@@ -116,9 +116,62 @@ object_schema_egg = ::Hubspot::Crm::Schemas::ObjectSchemaEgg.new(
116
116
  api_response = api.create(object_schema_egg)
117
117
  ```
118
118
 
119
+ for new discovery classes since version 14.3
120
+ ```ruby
121
+ client = Hubspot::Client.new(access_token: 'your_oauth2_access_token')
122
+
123
+ labels = {
124
+ singular: 'My object',
125
+ plural: 'My objects'
126
+ }
127
+
128
+ option = {
129
+ label: 'Option A',
130
+ value: 'A',
131
+ description: 'Choice number one',
132
+ display_order: 1,
133
+ hidden: false
134
+ }
135
+
136
+ property = {
137
+ name: 'property001',
138
+ label: 'My object property',
139
+ group_name: 'my_object_information',
140
+ options: [option],
141
+ display_order: 2,
142
+ type: 'enumeration',
143
+ field_type: 'select'
144
+ }
145
+
146
+ body = {
147
+ labels: labels,
148
+ required_properties: ['property001'],
149
+ searchable_properties: [],
150
+ primary_display_property: 'property001',
151
+ secondary_display_properties: [],
152
+ properties: [property],
153
+ associated_objects: ['CONTACT'],
154
+ name: 'my_object'
155
+ }
156
+
157
+ api_response = client.crm.schemas.core_api.create(body: body)
158
+ ```
159
+
119
160
 
120
161
  ### Error handling
121
162
 
163
+ for new discovery classes since version 14.4
164
+
165
+ #### You can rescue an ApiError by passing a block to the method
166
+
167
+ ```ruby
168
+ require 'hubspot-api-client'
169
+
170
+ client = Hubspot::Client.new(access_token: 'your_access_token')
171
+
172
+ contacts = client.crm.contacts.basic_api.get_page { |error| error.message }
173
+ ```
174
+
122
175
  #### You can set number of retry attempts and delay in seconds before retry on specific status code of response.
123
176
 
124
177
  Available params:
@@ -1,3 +1,5 @@
1
+ require_rel '../helpers/camel_case'
2
+
1
3
  module Hubspot
2
4
  module Discovery
3
5
  module BaseApiClient
@@ -17,7 +19,7 @@ module Hubspot
17
19
  end
18
20
 
19
21
  def api_client
20
- @api_client ||= Kernel.const_get("#{self.class.name.gsub('Discovery::', '').gsub(/(.*)::.*/, '\1')}::ApiClient").new(config)
22
+ @api_client ||= Kernel.const_get("#{codegen_module_name}::ApiClient").new(config)
21
23
  end
22
24
 
23
25
  def api
@@ -42,13 +44,28 @@ module Hubspot
42
44
  self.class.name.gsub('Discovery::', '')
43
45
  end
44
46
 
47
+ def codegen_module_name
48
+ codegen_api_class.gsub(/(.*)::.*/, '\1')
49
+ end
50
+
51
+ def call_api(api_method, params_to_pass)
52
+ api.public_send(api_method, *params_to_pass)
53
+ end
54
+
55
+ def call_api_with_rescue(api_method, params_to_pass)
56
+ error = Kernel.const_get("#{codegen_module_name}::ApiError")
57
+ call_api(api_method, params_to_pass)
58
+ rescue error => e
59
+ yield(e)
60
+ end
61
+
45
62
  def define_methods
46
63
  define_api_methods
47
64
  end
48
65
 
49
66
  def define_api_methods
50
67
  api_methods.each do |api_method|
51
- self.class.define_method(api_method) do |params = {}|
68
+ self.class.define_method(api_method) do |params = {}, &block|
52
69
  params_with_defaults = params
53
70
  params_with_defaults[:opts] ||= {}
54
71
  params_with_defaults[:opts][:auth_names] = if base_params[:access_token]
@@ -65,15 +82,20 @@ module Hubspot
65
82
 
66
83
  signature_param_names = signature_params.map { |_, param| param }
67
84
  params_with_defaults.each do |param_name, param_value|
68
- params_with_defaults[:opts][param_name] = param_value unless signature_param_names.include?(param_name)
85
+ params_with_defaults[:opts][param_name] = param_value if !signature_param_names.include?(param_name) && param_name != :body
69
86
  end
70
87
 
71
88
  params_to_pass = signature_params.map do |req, param|
89
+ model_name = Hubspot::Helpers::CamelCase.new.format(param.to_s)
90
+ Kernel.const_get("#{codegen_module_name}::#{model_name}").build_from_hash(params_with_defaults[:body])
91
+ rescue NameError
72
92
  raise "Param #{param} is required for #{api.class}\##{api_method} method" if req == :req && params_with_defaults[param].nil?
93
+
73
94
  params_with_defaults[param]
74
95
  end
75
96
 
76
- api.public_send(api_method, *params_to_pass)
97
+ return call_api_with_rescue(api_method, params_to_pass, &block) unless block.nil?
98
+ call_api(api_method, params_to_pass)
77
99
  end
78
100
  end
79
101
  end
@@ -1,3 +1,3 @@
1
1
  module Hubspot
2
- VERSION = '14.2.0'
2
+ VERSION = '14.4.0'
3
3
  end
@@ -17,11 +17,18 @@ describe 'Hubspot::Discovery::BaseApiClient' do
17
17
  end
18
18
 
19
19
  def update(test_id, simple_public_object_input, opts = {})
20
- "updated test_id: #{test_id}, simple_public_object_input: #{simple_public_object_input}, opts: #{opts}"
20
+ "updated test_id: #{test_id}, name: #{simple_public_object_input.name}, email: #{simple_public_object_input.email}, opts: #{opts}"
21
21
  end
22
22
 
23
23
  def update_with_http_info
24
24
  end
25
+
26
+ def raise_error
27
+ raise Hubspot::ApiError
28
+ end
29
+
30
+ def raise_error_with_http_info
31
+ end
25
32
  end
26
33
 
27
34
  class Hubspot::ApiClient
@@ -29,8 +36,28 @@ describe 'Hubspot::Discovery::BaseApiClient' do
29
36
  end
30
37
  end
31
38
 
39
+ class Hubspot::ApiError < ::StandardError
40
+ def message
41
+ 'test error'
42
+ end
43
+ end
44
+
45
+ class Hubspot::SimplePublicObjectInput
46
+ attr_reader :name, :email
47
+
48
+ def initialize(params)
49
+ @name = params[:name]
50
+ @email = params[:email]
51
+ end
52
+
53
+ def self.build_from_hash(params)
54
+ new(params)
55
+ end
56
+ end
57
+
32
58
  subject(:client) { Hubspot::Discovery::SomeApiClass.new(access_token: 'test') }
33
59
  let(:api) { client.api }
60
+ let(:body) { {name: 'test_name', email: 'test_email'} }
34
61
 
35
62
  it { is_expected.to respond_to(:get) }
36
63
  it { is_expected.to respond_to(:update) }
@@ -51,27 +78,53 @@ describe 'Hubspot::Discovery::BaseApiClient' do
51
78
 
52
79
  it { is_expected.to eq('got test_id: test_id_value, opts: {:auth_names=>"oauth2", :limit=>5}') }
53
80
  end
81
+
82
+ context 'with error handle block' do
83
+ subject(:get) { client.get(params) { |e| e.message } }
84
+ let(:params) { {test_id: 'test_id_value', limit: 10} }
85
+
86
+ it { is_expected.to eq('got test_id: test_id_value, opts: {:auth_names=>"oauth2", :limit=>10}') }
87
+ end
54
88
  end
55
89
 
56
90
  describe '#update' do
57
91
  subject(:update) { client.update(params) }
58
92
 
59
93
  context 'with default params order' do
60
- let(:params) { {test_id: 'test_id_value', simple_public_object_input: 'simple_public_object_input_value', limit: 10} }
94
+ let(:params) { {test_id: 'test_id_value', simple_public_object_input: Hubspot::SimplePublicObjectInput.new(body), limit: 10} }
61
95
 
62
- it { is_expected.to eq('updated test_id: test_id_value, simple_public_object_input: simple_public_object_input_value, opts: {:auth_names=>"oauth2", :limit=>10}') }
96
+ it { is_expected.to eq('updated test_id: test_id_value, name: test_name, email: test_email, opts: {:auth_names=>"oauth2", :limit=>10}') }
63
97
  end
64
98
 
65
99
  context 'with reversed params order' do
66
- let(:params) { {limit: 5, simple_public_object_input: 'simple_public_object_input_value', test_id: 'test_id_value'} }
100
+ let(:params) { {limit: 5, simple_public_object_input: Hubspot::SimplePublicObjectInput.new(body), test_id: 'test_id_value'} }
67
101
 
68
- it { is_expected.to eq('updated test_id: test_id_value, simple_public_object_input: simple_public_object_input_value, opts: {:auth_names=>"oauth2", :limit=>5}') }
102
+ it { is_expected.to eq('updated test_id: test_id_value, name: test_name, email: test_email, opts: {:auth_names=>"oauth2", :limit=>5}') }
69
103
  end
70
104
 
71
105
  context 'with shuffled params order' do
72
- let(:params) { {simple_public_object_input: 'simple_public_object_input_value', limit: 7, test_id: 'test_id_value'} }
106
+ let(:params) { {simple_public_object_input: Hubspot::SimplePublicObjectInput.new(body), limit: 7, test_id: 'test_id_value'} }
73
107
 
74
- it { is_expected.to eq('updated test_id: test_id_value, simple_public_object_input: simple_public_object_input_value, opts: {:auth_names=>"oauth2", :limit=>7}') }
108
+ it { is_expected.to eq('updated test_id: test_id_value, name: test_name, email: test_email, opts: {:auth_names=>"oauth2", :limit=>7}') }
109
+ end
110
+
111
+ context 'with body' do
112
+ let(:params) { {test_id: 'test_id_value', body: body, limit: 10} }
113
+
114
+ it { is_expected.to eq('updated test_id: test_id_value, name: test_name, email: test_email, opts: {:auth_names=>"oauth2", :limit=>10}') }
75
115
  end
116
+
117
+ context 'with block' do
118
+ subject(:update) { client.update(params) { |e| e.message } }
119
+ let(:params) { {test_id: 'test_id_value', body: body, limit: 10} }
120
+
121
+ it { is_expected.to eq('updated test_id: test_id_value, name: test_name, email: test_email, opts: {:auth_names=>"oauth2", :limit=>10}') }
122
+ end
123
+ end
124
+
125
+ describe '#raise_error' do
126
+ subject(:raise_error) { client.raise_error { |e| e.message } }
127
+
128
+ it { is_expected.to eq('test error') }
76
129
  end
77
130
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hubspot-api-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 14.2.0
4
+ version: 14.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - HubSpot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-25 00:00:00.000000000 Z
11
+ date: 2022-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus