hubspot-api-client 9.4.0 → 9.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Gemfile.lock +1 -1
  4. data/lib/hubspot/codegen/conversations/visitor-identification/api/generate_api.rb +90 -0
  5. data/lib/hubspot/codegen/conversations/visitor-identification/api_client.rb +392 -0
  6. data/lib/hubspot/codegen/conversations/visitor-identification/api_error.rb +61 -0
  7. data/lib/hubspot/codegen/conversations/visitor-identification/configuration.rb +263 -0
  8. data/lib/hubspot/codegen/conversations/visitor-identification/models/error.rb +292 -0
  9. data/lib/hubspot/codegen/conversations/visitor-identification/models/error_detail.rb +258 -0
  10. data/lib/hubspot/codegen/conversations/visitor-identification/models/identification_token_generation_request.rb +236 -0
  11. data/lib/hubspot/codegen/conversations/visitor-identification/models/identification_token_response.rb +215 -0
  12. data/lib/hubspot/codegen/events/api/events_api.rb +105 -0
  13. data/lib/hubspot/codegen/events/api_client.rb +390 -0
  14. data/lib/hubspot/codegen/events/api_error.rb +59 -0
  15. data/lib/hubspot/codegen/events/configuration.rb +261 -0
  16. data/lib/hubspot/codegen/events/models/collection_response_external_unified_event.rb +224 -0
  17. data/lib/hubspot/codegen/events/models/error.rb +290 -0
  18. data/lib/hubspot/codegen/events/models/error_detail.rb +256 -0
  19. data/lib/hubspot/codegen/events/models/external_unified_event.rb +290 -0
  20. data/lib/hubspot/codegen/events/models/next_page.rb +222 -0
  21. data/lib/hubspot/codegen/events/models/paging.rb +208 -0
  22. data/lib/hubspot/version.rb +1 -1
  23. data/spec/codegen/conversations/visitor-identification/api/generate_api_spec.rb +47 -0
  24. data/spec/codegen/conversations/visitor-identification/models/error_detail_spec.rb +65 -0
  25. data/spec/codegen/conversations/visitor-identification/models/error_spec.rb +77 -0
  26. data/spec/codegen/conversations/visitor-identification/models/identification_token_generation_request_spec.rb +53 -0
  27. data/spec/codegen/conversations/visitor-identification/models/identification_token_response_spec.rb +41 -0
  28. data/spec/codegen/events/api/events_api_spec.rb +54 -0
  29. data/spec/codegen/events/models/collection_response_external_unified_event_spec.rb +47 -0
  30. data/spec/codegen/events/models/error_detail_spec.rb +65 -0
  31. data/spec/codegen/events/models/error_spec.rb +77 -0
  32. data/spec/codegen/events/models/external_unified_event_spec.rb +71 -0
  33. data/spec/codegen/events/models/next_page_spec.rb +47 -0
  34. data/spec/codegen/events/models/paging_spec.rb +41 -0
  35. data/spec/features/conversations/visitor-identification/generate_api_spec.rb +7 -0
  36. data/spec/features/events/events_api_spec.rb +7 -0
  37. metadata +48 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7688cee0f534e245dd6f8063c8611f9c7342c0a0b8310a5f16d705a8f323c488
4
- data.tar.gz: 0d164eacd089d3597c17c4f0f8b9ea2ca7a45cdab92414a2a6d4a96c9c794e27
3
+ metadata.gz: ccfe6fd06109ec65d90da3c0f86705f7e5be6dbcb3363ef29693d82c565cdcc3
4
+ data.tar.gz: 8178297f8490805c188951645238c9bcd14e6c9455835320f8bcf37ea424c47d
5
5
  SHA512:
6
- metadata.gz: ba12e213d7c1b0eeb3ea31f28a00a47db5240238317bee117f14b3cf708b5f02c0a75adf76ed159f6de5cdb4989b234a2d0ba2b13a9f9eaa809a7dd13531492c
7
- data.tar.gz: 20341bc9d9257af082b8ff83bc5f71d46ae5e1fcf9a69a6c2119d1d17e3aeb05659d34a332b3ea2ab6655e8547bf66b7287d49804cda71bec629fa750dd5d281
6
+ metadata.gz: a689506081f3c5f8d0039fcc3cee7020f31095288c2d27c6313535d4e8d16707172abe0b77ea40b97e5002feb22b2fe7b289c2d394b9b489d74af0b979eeadf3
7
+ data.tar.gz: 6a1dfd577ea1751b852bd4dfeff44ee4babbe6440930cdf7b35d713e9fc4181ce9fc2d93ec78c3d212838296a14524b0792df756257b48aa2d55a3c282b0249d
data/CHANGELOG.md CHANGED
@@ -5,6 +5,11 @@ 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
+ ## [9.5.0] - 2021-02-19
9
+
10
+ - added Events api module
11
+ - added Conversations::VisitorIdentification api module
12
+
8
13
  ## [9.4.0] - 2021-02-08
9
14
 
10
15
  - added Crm::Extensions::Accounting api module
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hubspot-api-client (9.4.0)
4
+ hubspot-api-client (9.5.0)
5
5
  json (~> 2.1, >= 2.1.0)
6
6
  require_all (~> 3.0.0)
7
7
  typhoeus (~> 1.4.0)
@@ -0,0 +1,90 @@
1
+ =begin
2
+ #Visitor Identification
3
+
4
+ #The Visitor Identification API allows you to pass identification information to the HubSpot chat widget for otherwise unknown visitors that were verified by your own authentication system.
5
+
6
+ The version of the OpenAPI document: v3
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.3.1
10
+
11
+ =end
12
+
13
+ require 'cgi'
14
+
15
+ module Hubspot
16
+ module Conversations
17
+ module VisitorIdentification
18
+ class GenerateApi
19
+ attr_accessor :api_client
20
+
21
+ def initialize(api_client = ApiClient.default)
22
+ @api_client = api_client
23
+ end
24
+ # Generate a token
25
+ # Generates a new visitor identification token. This token will be unique every time this endpoint is called, even if called with the same email address. This token is temporary and will expire after 12 hours
26
+ # @param identification_token_generation_request [IdentificationTokenGenerationRequest]
27
+ # @param [Hash] opts the optional parameters
28
+ # @return [IdentificationTokenResponse]
29
+ def generate_token(identification_token_generation_request, opts = {})
30
+ data, _status_code, _headers = generate_token_with_http_info(identification_token_generation_request, opts)
31
+ data
32
+ end
33
+
34
+ # Generate a token
35
+ # Generates a new visitor identification token. This token will be unique every time this endpoint is called, even if called with the same email address. This token is temporary and will expire after 12 hours
36
+ # @param identification_token_generation_request [IdentificationTokenGenerationRequest]
37
+ # @param [Hash] opts the optional parameters
38
+ # @return [Array<(IdentificationTokenResponse, Integer, Hash)>] IdentificationTokenResponse data, response status code and response headers
39
+ def generate_token_with_http_info(identification_token_generation_request, opts = {})
40
+ if @api_client.config.debugging
41
+ @api_client.config.logger.debug 'Calling API: GenerateApi.generate_token ...'
42
+ end
43
+ # verify the required parameter 'identification_token_generation_request' is set
44
+ if @api_client.config.client_side_validation && identification_token_generation_request.nil?
45
+ fail ArgumentError, "Missing the required parameter 'identification_token_generation_request' when calling GenerateApi.generate_token"
46
+ end
47
+ # resource path
48
+ local_var_path = '/conversations/v3/visitor-identification/tokens/create'
49
+
50
+ # query parameters
51
+ query_params = opts[:query_params] || {}
52
+
53
+ # header parameters
54
+ header_params = opts[:header_params] || {}
55
+ # HTTP header 'Accept' (if needed)
56
+ header_params['Accept'] = @api_client.select_header_accept(['application/json', '*/*'])
57
+ # HTTP header 'Content-Type'
58
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
59
+
60
+ # form parameters
61
+ form_params = opts[:form_params] || {}
62
+
63
+ # http body (model)
64
+ post_body = opts[:body] || @api_client.object_to_http_body(identification_token_generation_request)
65
+
66
+ # return_type
67
+ return_type = opts[:return_type] || 'IdentificationTokenResponse'
68
+
69
+ # auth_names
70
+ auth_names = opts[:auth_names] || ['hapikey', 'oauth2']
71
+
72
+ new_options = opts.merge(
73
+ :header_params => header_params,
74
+ :query_params => query_params,
75
+ :form_params => form_params,
76
+ :body => post_body,
77
+ :auth_names => auth_names,
78
+ :return_type => return_type
79
+ )
80
+
81
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
82
+ if @api_client.config.debugging
83
+ @api_client.config.logger.debug "API called: GenerateApi#generate_token\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
84
+ end
85
+ return data, status_code, headers
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,392 @@
1
+ =begin
2
+ #Visitor Identification
3
+
4
+ #The Visitor Identification API allows you to pass identification information to the HubSpot chat widget for otherwise unknown visitors that were verified by your own authentication system.
5
+
6
+ The version of the OpenAPI document: v3
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.3.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'json'
15
+ require 'logger'
16
+ require 'tempfile'
17
+ require 'typhoeus'
18
+
19
+ module Hubspot
20
+ module Conversations
21
+ module VisitorIdentification
22
+ class ApiClient
23
+ # The Configuration object holding settings to be used in the API client.
24
+ attr_accessor :config
25
+
26
+ # Defines the headers to be used in HTTP requests of all API calls by default.
27
+ #
28
+ # @return [Hash]
29
+ attr_accessor :default_headers
30
+
31
+ # Initializes the ApiClient
32
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
33
+ def initialize(config = Configuration.default)
34
+ @config = config
35
+ @user_agent = "hubspot-api-client-ruby; #{VERSION}"
36
+ @default_headers = {
37
+ 'Content-Type' => 'application/json',
38
+ 'User-Agent' => @user_agent
39
+ }
40
+ end
41
+
42
+ def self.default
43
+ @@default ||= ApiClient.new
44
+ end
45
+
46
+ # Call an API with given options.
47
+ #
48
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
49
+ # the data deserialized from response body (could be nil), response status code and response headers.
50
+ def call_api(http_method, path, opts = {})
51
+ request = build_request(http_method, path, opts)
52
+ response = request.run
53
+
54
+ if @config.debugging
55
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
56
+ end
57
+
58
+ unless response.success?
59
+ if response.timed_out?
60
+ fail ApiError.new('Connection timed out')
61
+ elsif response.code == 0
62
+ # Errors from libcurl will be made visible here
63
+ fail ApiError.new(:code => 0,
64
+ :message => response.return_message)
65
+ else
66
+ fail ApiError.new(:code => response.code,
67
+ :response_headers => response.headers,
68
+ :response_body => response.body),
69
+ response.status_message
70
+ end
71
+ end
72
+
73
+ if opts[:return_type]
74
+ data = deserialize(response, opts[:return_type])
75
+ else
76
+ data = nil
77
+ end
78
+ return data, response.code, response.headers
79
+ end
80
+
81
+ # Builds the HTTP request
82
+ #
83
+ # @param [String] http_method HTTP method/verb (e.g. POST)
84
+ # @param [String] path URL path (e.g. /account/new)
85
+ # @option opts [Hash] :header_params Header parameters
86
+ # @option opts [Hash] :query_params Query parameters
87
+ # @option opts [Hash] :form_params Query parameters
88
+ # @option opts [Object] :body HTTP body (JSON/XML)
89
+ # @return [Typhoeus::Request] A Typhoeus Request
90
+ def build_request(http_method, path, opts = {})
91
+ url = build_request_url(path)
92
+ http_method = http_method.to_sym.downcase
93
+
94
+ header_params = @default_headers.merge(opts[:header_params] || {})
95
+ query_params = opts[:query_params] || {}
96
+ form_params = opts[:form_params] || {}
97
+
98
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
99
+
100
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
101
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
102
+
103
+ req_opts = {
104
+ :method => http_method,
105
+ :headers => header_params,
106
+ :params => query_params,
107
+ :params_encoding => @config.params_encoding,
108
+ :timeout => @config.timeout,
109
+ :ssl_verifypeer => @config.verify_ssl,
110
+ :ssl_verifyhost => _verify_ssl_host,
111
+ :sslcert => @config.cert_file,
112
+ :sslkey => @config.key_file,
113
+ :verbose => @config.debugging
114
+ }
115
+
116
+ # set custom cert, if provided
117
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
118
+
119
+ if [:post, :patch, :put, :delete].include?(http_method)
120
+ req_body = build_request_body(header_params, form_params, opts[:body])
121
+ req_opts.update :body => req_body
122
+ if @config.debugging
123
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
124
+ end
125
+ end
126
+
127
+ request = Typhoeus::Request.new(url, req_opts)
128
+ download_file(request) if opts[:return_type] == 'File'
129
+ request
130
+ end
131
+
132
+ # Builds the HTTP request body
133
+ #
134
+ # @param [Hash] header_params Header parameters
135
+ # @param [Hash] form_params Query parameters
136
+ # @param [Object] body HTTP body (JSON/XML)
137
+ # @return [String] HTTP body data in the form of string
138
+ def build_request_body(header_params, form_params, body)
139
+ # http form
140
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
141
+ header_params['Content-Type'] == 'multipart/form-data'
142
+ data = {}
143
+ form_params.each do |key, value|
144
+ case value
145
+ when ::File, ::Array, nil
146
+ # let typhoeus handle File, Array and nil parameters
147
+ data[key] = value
148
+ else
149
+ data[key] = value.to_s
150
+ end
151
+ end
152
+ elsif body
153
+ data = body.is_a?(String) ? body : body.to_json
154
+ else
155
+ data = nil
156
+ end
157
+ data
158
+ end
159
+
160
+ # Check if the given MIME is a JSON MIME.
161
+ # JSON MIME examples:
162
+ # application/json
163
+ # application/json; charset=UTF8
164
+ # APPLICATION/JSON
165
+ # */*
166
+ # @param [String] mime MIME
167
+ # @return [Boolean] True if the MIME is application/json
168
+ def json_mime?(mime)
169
+ (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
170
+ end
171
+
172
+ # Deserialize the response to the given return type.
173
+ #
174
+ # @param [Response] response HTTP response
175
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
176
+ def deserialize(response, return_type)
177
+ body = response.body
178
+
179
+ # handle file downloading - return the File instance processed in request callbacks
180
+ # note that response body is empty when the file is written in chunks in request on_body callback
181
+ return @tempfile if return_type == 'File'
182
+
183
+ return nil if body.nil? || body.empty?
184
+
185
+ # return response body directly for String return type
186
+ return body if return_type == 'String'
187
+
188
+ # ensuring a default content type
189
+ content_type = response.headers['Content-Type'] || 'application/json'
190
+
191
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
192
+
193
+ begin
194
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
195
+ rescue JSON::ParserError => e
196
+ if %w(String Date DateTime).include?(return_type)
197
+ data = body
198
+ else
199
+ raise e
200
+ end
201
+ end
202
+
203
+ convert_to_type data, return_type
204
+ end
205
+
206
+ # Convert data to the given return type.
207
+ # @param [Object] data Data to be converted
208
+ # @param [String] return_type Return type
209
+ # @return [Mixed] Data in a particular type
210
+ def convert_to_type(data, return_type)
211
+ return nil if data.nil?
212
+ case return_type
213
+ when 'String'
214
+ data.to_s
215
+ when 'Integer'
216
+ data.to_i
217
+ when 'Float'
218
+ data.to_f
219
+ when 'Boolean'
220
+ data == true
221
+ when 'DateTime'
222
+ # parse date time (expecting ISO 8601 format)
223
+ DateTime.parse data
224
+ when 'Date'
225
+ # parse date time (expecting ISO 8601 format)
226
+ Date.parse data
227
+ when 'Object'
228
+ # generic object (usually a Hash), return directly
229
+ data
230
+ when /\AArray<(.+)>\z/
231
+ # e.g. Array<Pet>
232
+ sub_type = $1
233
+ data.map { |item| convert_to_type(item, sub_type) }
234
+ when /\AHash\<String, (.+)\>\z/
235
+ # e.g. Hash<String, Integer>
236
+ sub_type = $1
237
+ {}.tap do |hash|
238
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
239
+ end
240
+ else
241
+ # models, e.g. Pet
242
+ Hubspot::Conversations::VisitorIdentification.const_get(return_type).build_from_hash(data)
243
+ end
244
+ end
245
+
246
+ # Save response body into a file in (the defined) temporary folder, using the filename
247
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
248
+ # The response body is written to the file in chunks in order to handle files which
249
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
250
+ # process can use.
251
+ #
252
+ # @see Configuration#temp_folder_path
253
+ def download_file(request)
254
+ tempfile = nil
255
+ encoding = nil
256
+ request.on_headers do |response|
257
+ content_disposition = response.headers['Content-Disposition']
258
+ if content_disposition && content_disposition =~ /filename=/i
259
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
260
+ prefix = sanitize_filename(filename)
261
+ else
262
+ prefix = 'download-'
263
+ end
264
+ prefix = prefix + '-' unless prefix.end_with?('-')
265
+ encoding = response.body.encoding
266
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
267
+ @tempfile = tempfile
268
+ end
269
+ request.on_body do |chunk|
270
+ chunk.force_encoding(encoding)
271
+ tempfile.write(chunk)
272
+ end
273
+ request.on_complete do |response|
274
+ if tempfile
275
+ tempfile.close
276
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
277
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
278
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
279
+ "explicitly with `tempfile.delete`"
280
+ end
281
+ end
282
+ end
283
+
284
+ # Sanitize filename by removing path.
285
+ # e.g. ../../sun.gif becomes sun.gif
286
+ #
287
+ # @param [String] filename the filename to be sanitized
288
+ # @return [String] the sanitized filename
289
+ def sanitize_filename(filename)
290
+ filename.gsub(/.*[\/\\]/, '')
291
+ end
292
+
293
+ def build_request_url(path)
294
+ # Add leading and trailing slashes to path
295
+ path = "/#{path}".gsub(/\/+/, '/')
296
+ @config.base_url + path
297
+ end
298
+
299
+ # Update hearder and query params based on authentication settings.
300
+ #
301
+ # @param [Hash] header_params Header parameters
302
+ # @param [Hash] query_params Query parameters
303
+ # @param [String] auth_names Authentication scheme name
304
+ def update_params_for_auth!(header_params, query_params, auth_names)
305
+ Array(auth_names).each do |auth_name|
306
+ auth_setting = @config.auth_settings[auth_name]
307
+ next unless auth_setting
308
+ case auth_setting[:in]
309
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
310
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
311
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
312
+ end
313
+ end
314
+ end
315
+
316
+ # Sets user agent in HTTP header
317
+ #
318
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
319
+ def user_agent=(user_agent)
320
+ @user_agent = user_agent
321
+ @default_headers['User-Agent'] = @user_agent
322
+ end
323
+
324
+ # Return Accept header based on an array of accepts provided.
325
+ # @param [Array] accepts array for Accept
326
+ # @return [String] the Accept header (e.g. application/json)
327
+ def select_header_accept(accepts)
328
+ return nil if accepts.nil? || accepts.empty?
329
+ # use JSON when present, otherwise use all of the provided
330
+ json_accept = accepts.find { |s| json_mime?(s) }
331
+ json_accept || accepts.join(',')
332
+ end
333
+
334
+ # Return Content-Type header based on an array of content types provided.
335
+ # @param [Array] content_types array for Content-Type
336
+ # @return [String] the Content-Type header (e.g. application/json)
337
+ def select_header_content_type(content_types)
338
+ # use application/json by default
339
+ return 'application/json' if content_types.nil? || content_types.empty?
340
+ # use JSON when present, otherwise use the first one
341
+ json_content_type = content_types.find { |s| json_mime?(s) }
342
+ json_content_type || content_types.first
343
+ end
344
+
345
+ # Convert object (array, hash, object, etc) to JSON string.
346
+ # @param [Object] model object to be converted into JSON string
347
+ # @return [String] JSON string representation of the object
348
+ def object_to_http_body(model)
349
+ return model if model.nil? || model.is_a?(String)
350
+ local_body = nil
351
+ if model.is_a?(Array)
352
+ local_body = model.map { |m| object_to_hash(m) }
353
+ else
354
+ local_body = object_to_hash(model)
355
+ end
356
+ local_body.to_json
357
+ end
358
+
359
+ # Convert object(non-array) to hash.
360
+ # @param [Object] obj object to be converted into JSON string
361
+ # @return [String] JSON string representation of the object
362
+ def object_to_hash(obj)
363
+ if obj.respond_to?(:to_hash)
364
+ obj.to_hash
365
+ else
366
+ obj
367
+ end
368
+ end
369
+
370
+ # Build parameter value according to the given collection format.
371
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
372
+ def build_collection_param(param, collection_format)
373
+ case collection_format
374
+ when :csv
375
+ param.join(',')
376
+ when :ssv
377
+ param.join(' ')
378
+ when :tsv
379
+ param.join("\t")
380
+ when :pipes
381
+ param.join('|')
382
+ when :multi
383
+ # return the array directly as typhoeus will handle it as expected
384
+ param
385
+ else
386
+ fail "unknown collection format: #{collection_format.inspect}"
387
+ end
388
+ end
389
+ end
390
+ end
391
+ end
392
+ end