smooch-api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +7 -0
  3. data/README.md +181 -0
  4. data/Rakefile +8 -0
  5. data/docs/Action.md +16 -0
  6. data/docs/App.md +10 -0
  7. data/docs/AppApi.md +609 -0
  8. data/docs/AppCreate.md +8 -0
  9. data/docs/AppResponse.md +8 -0
  10. data/docs/AppUser.md +18 -0
  11. data/docs/AppUserApi.md +561 -0
  12. data/docs/AppUserLink.md +9 -0
  13. data/docs/AppUserPreCreate.md +14 -0
  14. data/docs/AppUserResponse.md +8 -0
  15. data/docs/AppUserUpdate.md +12 -0
  16. data/docs/Client.md +14 -0
  17. data/docs/ClientInfo.md +15 -0
  18. data/docs/Conversation.md +9 -0
  19. data/docs/ConversationApi.md +282 -0
  20. data/docs/Destination.md +9 -0
  21. data/docs/DeviceInit.md +12 -0
  22. data/docs/DeviceResponse.md +8 -0
  23. data/docs/DeviceUpdate.md +10 -0
  24. data/docs/DisplaySettings.md +8 -0
  25. data/docs/Event.md +8 -0
  26. data/docs/GetMessagesResponse.md +10 -0
  27. data/docs/Init.md +9 -0
  28. data/docs/InitApi.md +61 -0
  29. data/docs/InitResponse.md +9 -0
  30. data/docs/Integration.md +24 -0
  31. data/docs/IntegrationApi.md +121 -0
  32. data/docs/IntegrationCreate.md +23 -0
  33. data/docs/IntegrationResponse.md +8 -0
  34. data/docs/JwtResponse.md +8 -0
  35. data/docs/ListAppsResponse.md +10 -0
  36. data/docs/ListIntegrationsResponse.md +8 -0
  37. data/docs/ListSecretKeysResponse.md +8 -0
  38. data/docs/ListWebhooksResponse.md +8 -0
  39. data/docs/Menu.md +9 -0
  40. data/docs/MenuApi.md +155 -0
  41. data/docs/MenuItem.md +11 -0
  42. data/docs/MenuResponse.md +8 -0
  43. data/docs/Message.md +23 -0
  44. data/docs/MessageItem.md +13 -0
  45. data/docs/MessagePost.md +20 -0
  46. data/docs/MessageResponse.md +9 -0
  47. data/docs/PostMessagesResponse.md +9 -0
  48. data/docs/SecretKey.md +10 -0
  49. data/docs/SecretKeyCreate.md +8 -0
  50. data/docs/SecretKeyResponse.md +8 -0
  51. data/docs/TrackEventResponse.md +8 -0
  52. data/docs/TypingActivityTrigger.md +11 -0
  53. data/docs/Webhook.md +11 -0
  54. data/docs/WebhookApi.md +287 -0
  55. data/docs/WebhookCreate.md +9 -0
  56. data/docs/WebhookResponse.md +8 -0
  57. data/docs/WebhookUpdate.md +9 -0
  58. data/git_push.sh +55 -0
  59. data/lib/smooch-api.rb +91 -0
  60. data/lib/smooch-api/api/app_api.rb +628 -0
  61. data/lib/smooch-api/api/app_user_api.rb +585 -0
  62. data/lib/smooch-api/api/conversation_api.rb +298 -0
  63. data/lib/smooch-api/api/init_api.rb +75 -0
  64. data/lib/smooch-api/api/integration_api.rb +135 -0
  65. data/lib/smooch-api/api/menu_api.rb +173 -0
  66. data/lib/smooch-api/api/webhook_api.rb +306 -0
  67. data/lib/smooch-api/api_client.rb +376 -0
  68. data/lib/smooch-api/api_error.rb +37 -0
  69. data/lib/smooch-api/configuration.rb +202 -0
  70. data/lib/smooch-api/models/action.rb +311 -0
  71. data/lib/smooch-api/models/app.rb +223 -0
  72. data/lib/smooch-api/models/app_create.rb +193 -0
  73. data/lib/smooch-api/models/app_response.rb +188 -0
  74. data/lib/smooch-api/models/app_user.rb +307 -0
  75. data/lib/smooch-api/models/app_user_link.rb +236 -0
  76. data/lib/smooch-api/models/app_user_pre_create.rb +253 -0
  77. data/lib/smooch-api/models/app_user_response.rb +193 -0
  78. data/lib/smooch-api/models/app_user_update.rb +228 -0
  79. data/lib/smooch-api/models/client.rb +290 -0
  80. data/lib/smooch-api/models/client_info.rb +258 -0
  81. data/lib/smooch-api/models/conversation.rb +208 -0
  82. data/lib/smooch-api/models/destination.rb +208 -0
  83. data/lib/smooch-api/models/device_init.rb +270 -0
  84. data/lib/smooch-api/models/device_response.rb +188 -0
  85. data/lib/smooch-api/models/device_update.rb +207 -0
  86. data/lib/smooch-api/models/display_settings.rb +188 -0
  87. data/lib/smooch-api/models/event.rb +193 -0
  88. data/lib/smooch-api/models/get_messages_response.rb +210 -0
  89. data/lib/smooch-api/models/init.rb +202 -0
  90. data/lib/smooch-api/models/init_response.rb +208 -0
  91. data/lib/smooch-api/models/integration.rb +358 -0
  92. data/lib/smooch-api/models/integration_create.rb +343 -0
  93. data/lib/smooch-api/models/integration_response.rb +188 -0
  94. data/lib/smooch-api/models/jwt_response.rb +188 -0
  95. data/lib/smooch-api/models/list_apps_response.rb +210 -0
  96. data/lib/smooch-api/models/list_integrations_response.rb +190 -0
  97. data/lib/smooch-api/models/list_secret_keys_response.rb +190 -0
  98. data/lib/smooch-api/models/list_webhooks_response.rb +195 -0
  99. data/lib/smooch-api/models/menu.rb +205 -0
  100. data/lib/smooch-api/models/menu_item.rb +228 -0
  101. data/lib/smooch-api/models/menu_response.rb +193 -0
  102. data/lib/smooch-api/models/message.rb +415 -0
  103. data/lib/smooch-api/models/message_item.rb +250 -0
  104. data/lib/smooch-api/models/message_post.rb +355 -0
  105. data/lib/smooch-api/models/message_response.rb +208 -0
  106. data/lib/smooch-api/models/post_messages_response.rb +200 -0
  107. data/lib/smooch-api/models/secret_key.rb +223 -0
  108. data/lib/smooch-api/models/secret_key_create.rb +193 -0
  109. data/lib/smooch-api/models/secret_key_response.rb +188 -0
  110. data/lib/smooch-api/models/track_event_response.rb +188 -0
  111. data/lib/smooch-api/models/typing_activity_trigger.rb +228 -0
  112. data/lib/smooch-api/models/webhook.rb +261 -0
  113. data/lib/smooch-api/models/webhook_create.rb +226 -0
  114. data/lib/smooch-api/models/webhook_response.rb +193 -0
  115. data/lib/smooch-api/models/webhook_update.rb +221 -0
  116. data/lib/smooch-api/version.rb +14 -0
  117. data/smooch-api.gemspec +44 -0
  118. data/spec/api_client_spec.rb +225 -0
  119. data/spec/configuration_spec.rb +41 -0
  120. data/spec/spec_helper.rb +110 -0
  121. metadata +349 -0
@@ -0,0 +1,376 @@
1
+ =begin
2
+ #Smooch
3
+
4
+ #The Smooch API is a unified interface for powering messaging in your customer experiences across every channel. Our API speeds access to new markets, reduces time to ship, eliminates complexity, and helps you build the best experiences for your customers. For more information, visit our [official documentation](https://docs.smooch.io).
5
+
6
+ OpenAPI spec version: 1
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+
10
+ =end
11
+
12
+ require 'date'
13
+ require 'json'
14
+ require 'logger'
15
+ require 'tempfile'
16
+ require 'typhoeus'
17
+ require 'uri'
18
+
19
+ module SmoochApi
20
+ class ApiClient
21
+ # The Configuration object holding settings to be used in the API client.
22
+ attr_accessor :config
23
+
24
+ # Defines the headers to be used in HTTP requests of all API calls by default.
25
+ #
26
+ # @return [Hash]
27
+ attr_accessor :default_headers
28
+
29
+ # Initializes the ApiClient
30
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
31
+ def initialize(config = Configuration.default)
32
+ @config = config
33
+ @user_agent = "Swagger-Codegen/#{VERSION}/ruby"
34
+ @default_headers = {
35
+ 'Content-Type' => "application/json",
36
+ 'User-Agent' => @user_agent
37
+ }
38
+ end
39
+
40
+ def self.default
41
+ @@default ||= ApiClient.new
42
+ end
43
+
44
+ # Call an API with given options.
45
+ #
46
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
47
+ # the data deserialized from response body (could be nil), response status code and response headers.
48
+ def call_api(http_method, path, opts = {})
49
+ request = build_request(http_method, path, opts)
50
+ response = request.run
51
+
52
+ if @config.debugging
53
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
54
+ end
55
+
56
+ unless response.success?
57
+ if response.timed_out?
58
+ fail ApiError.new('Connection timed out')
59
+ elsif response.code == 0
60
+ # Errors from libcurl will be made visible here
61
+ fail ApiError.new(:code => 0,
62
+ :message => response.return_message)
63
+ else
64
+ fail ApiError.new(:code => response.code,
65
+ :response_headers => response.headers,
66
+ :response_body => response.body),
67
+ response.status_message
68
+ end
69
+ end
70
+
71
+ if opts[:return_type]
72
+ data = deserialize(response, opts[:return_type])
73
+ else
74
+ data = nil
75
+ end
76
+ return data, response.code, response.headers
77
+ end
78
+
79
+ # Builds the HTTP request
80
+ #
81
+ # @param [String] http_method HTTP method/verb (e.g. POST)
82
+ # @param [String] path URL path (e.g. /account/new)
83
+ # @option opts [Hash] :header_params Header parameters
84
+ # @option opts [Hash] :query_params Query parameters
85
+ # @option opts [Hash] :form_params Query parameters
86
+ # @option opts [Object] :body HTTP body (JSON/XML)
87
+ # @return [Typhoeus::Request] A Typhoeus Request
88
+ def build_request(http_method, path, opts = {})
89
+ url = build_request_url(path)
90
+ http_method = http_method.to_sym.downcase
91
+
92
+ header_params = @default_headers.merge(opts[:header_params] || {})
93
+ query_params = opts[:query_params] || {}
94
+ form_params = opts[:form_params] || {}
95
+
96
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
97
+
98
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
99
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
100
+
101
+ req_opts = {
102
+ :method => http_method,
103
+ :headers => header_params,
104
+ :params => query_params,
105
+ :params_encoding => @config.params_encoding,
106
+ :timeout => @config.timeout,
107
+ :ssl_verifypeer => @config.verify_ssl,
108
+ :ssl_verifyhost => _verify_ssl_host,
109
+ :sslcert => @config.cert_file,
110
+ :sslkey => @config.key_file,
111
+ :verbose => @config.debugging
112
+ }
113
+
114
+ # set custom cert, if provided
115
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
116
+
117
+ if [:post, :patch, :put, :delete].include?(http_method)
118
+ req_body = build_request_body(header_params, form_params, opts[:body])
119
+ req_opts.update :body => req_body
120
+ if @config.debugging
121
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
122
+ end
123
+ end
124
+
125
+ Typhoeus::Request.new(url, req_opts)
126
+ end
127
+
128
+ # Check if the given MIME is a JSON MIME.
129
+ # JSON MIME examples:
130
+ # application/json
131
+ # application/json; charset=UTF8
132
+ # APPLICATION/JSON
133
+ # */*
134
+ # @param [String] mime MIME
135
+ # @return [Boolean] True if the MIME is application/json
136
+ def json_mime?(mime)
137
+ (mime == "*/*") || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
138
+ end
139
+
140
+ # Deserialize the response to the given return type.
141
+ #
142
+ # @param [Response] response HTTP response
143
+ # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
144
+ def deserialize(response, return_type)
145
+ body = response.body
146
+ return nil if body.nil? || body.empty?
147
+
148
+ # return response body directly for String return type
149
+ return body if return_type == 'String'
150
+
151
+ # handle file downloading - save response body into a tmp file and return the File instance
152
+ return download_file(response) if return_type == 'File'
153
+
154
+ # ensuring a default content type
155
+ content_type = response.headers['Content-Type'] || 'application/json'
156
+
157
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
158
+
159
+ begin
160
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
161
+ rescue JSON::ParserError => e
162
+ if %w(String Date DateTime).include?(return_type)
163
+ data = body
164
+ else
165
+ raise e
166
+ end
167
+ end
168
+
169
+ convert_to_type data, return_type
170
+ end
171
+
172
+ # Convert data to the given return type.
173
+ # @param [Object] data Data to be converted
174
+ # @param [String] return_type Return type
175
+ # @return [Mixed] Data in a particular type
176
+ def convert_to_type(data, return_type)
177
+ return nil if data.nil?
178
+ case return_type
179
+ when 'String'
180
+ data.to_s
181
+ when 'Integer'
182
+ data.to_i
183
+ when 'Float'
184
+ data.to_f
185
+ when 'BOOLEAN'
186
+ data == true
187
+ when 'DateTime'
188
+ # parse date time (expecting ISO 8601 format)
189
+ DateTime.parse data
190
+ when 'Date'
191
+ # parse date time (expecting ISO 8601 format)
192
+ Date.parse data
193
+ when 'Object'
194
+ # generic object (usually a Hash), return directly
195
+ data
196
+ when /\AArray<(.+)>\z/
197
+ # e.g. Array<Pet>
198
+ sub_type = $1
199
+ data.map {|item| convert_to_type(item, sub_type) }
200
+ when /\AHash\<String, (.+)\>\z/
201
+ # e.g. Hash<String, Integer>
202
+ sub_type = $1
203
+ {}.tap do |hash|
204
+ data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
205
+ end
206
+ else
207
+ # models, e.g. Pet
208
+ SmoochApi.const_get(return_type).new.tap do |model|
209
+ model.build_from_hash data
210
+ end
211
+ end
212
+ end
213
+
214
+ # Save response body into a file in (the defined) temporary folder, using the filename
215
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
216
+ #
217
+ # @see Configuration#temp_folder_path
218
+ # @return [Tempfile] the file downloaded
219
+ def download_file(response)
220
+ content_disposition = response.headers['Content-Disposition']
221
+ if content_disposition and content_disposition =~ /filename=/i
222
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
223
+ prefix = sanitize_filename(filename)
224
+ else
225
+ prefix = 'download-'
226
+ end
227
+ prefix = prefix + '-' unless prefix.end_with?('-')
228
+
229
+ tempfile = nil
230
+ encoding = response.body.encoding
231
+ Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) do |file|
232
+ file.write(response.body)
233
+ tempfile = file
234
+ end
235
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
236
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
237
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
238
+ "explicitly with `tempfile.delete`"
239
+ tempfile
240
+ end
241
+
242
+ # Sanitize filename by removing path.
243
+ # e.g. ../../sun.gif becomes sun.gif
244
+ #
245
+ # @param [String] filename the filename to be sanitized
246
+ # @return [String] the sanitized filename
247
+ def sanitize_filename(filename)
248
+ filename.gsub(/.*[\/\\]/, '')
249
+ end
250
+
251
+ def build_request_url(path)
252
+ # Add leading and trailing slashes to path
253
+ path = "/#{path}".gsub(/\/+/, '/')
254
+ URI.encode(@config.base_url + path)
255
+ end
256
+
257
+ # Builds the HTTP request body
258
+ #
259
+ # @param [Hash] header_params Header parameters
260
+ # @param [Hash] form_params Query parameters
261
+ # @param [Object] body HTTP body (JSON/XML)
262
+ # @return [String] HTTP body data in the form of string
263
+ def build_request_body(header_params, form_params, body)
264
+ # http form
265
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
266
+ header_params['Content-Type'] == 'multipart/form-data'
267
+ data = {}
268
+ form_params.each do |key, value|
269
+ case value
270
+ when File, Array, nil
271
+ # let typhoeus handle File, Array and nil parameters
272
+ data[key] = value
273
+ else
274
+ data[key] = value.to_s
275
+ end
276
+ end
277
+ elsif body
278
+ data = body.is_a?(String) ? body : body.to_json
279
+ else
280
+ data = nil
281
+ end
282
+ data
283
+ end
284
+
285
+ # Update hearder and query params based on authentication settings.
286
+ #
287
+ # @param [Hash] header_params Header parameters
288
+ # @param [Hash] query_params Query parameters
289
+ # @param [String] auth_names Authentication scheme name
290
+ def update_params_for_auth!(header_params, query_params, auth_names)
291
+ Array(auth_names).each do |auth_name|
292
+ auth_setting = @config.auth_settings[auth_name]
293
+ next unless auth_setting
294
+ case auth_setting[:in]
295
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
296
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
297
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
298
+ end
299
+ end
300
+ end
301
+
302
+ # Sets user agent in HTTP header
303
+ #
304
+ # @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
305
+ def user_agent=(user_agent)
306
+ @user_agent = user_agent
307
+ @default_headers['User-Agent'] = @user_agent
308
+ end
309
+
310
+ # Return Accept header based on an array of accepts provided.
311
+ # @param [Array] accepts array for Accept
312
+ # @return [String] the Accept header (e.g. application/json)
313
+ def select_header_accept(accepts)
314
+ return nil if accepts.nil? || accepts.empty?
315
+ # use JSON when present, otherwise use all of the provided
316
+ json_accept = accepts.find { |s| json_mime?(s) }
317
+ return json_accept || accepts.join(',')
318
+ end
319
+
320
+ # Return Content-Type header based on an array of content types provided.
321
+ # @param [Array] content_types array for Content-Type
322
+ # @return [String] the Content-Type header (e.g. application/json)
323
+ def select_header_content_type(content_types)
324
+ # use application/json by default
325
+ return 'application/json' if content_types.nil? || content_types.empty?
326
+ # use JSON when present, otherwise use the first one
327
+ json_content_type = content_types.find { |s| json_mime?(s) }
328
+ return json_content_type || content_types.first
329
+ end
330
+
331
+ # Convert object (array, hash, object, etc) to JSON string.
332
+ # @param [Object] model object to be converted into JSON string
333
+ # @return [String] JSON string representation of the object
334
+ def object_to_http_body(model)
335
+ return model if model.nil? || model.is_a?(String)
336
+ local_body = nil
337
+ if model.is_a?(Array)
338
+ local_body = model.map{|m| object_to_hash(m) }
339
+ else
340
+ local_body = object_to_hash(model)
341
+ end
342
+ local_body.to_json
343
+ end
344
+
345
+ # Convert object(non-array) to hash.
346
+ # @param [Object] obj object to be converted into JSON string
347
+ # @return [String] JSON string representation of the object
348
+ def object_to_hash(obj)
349
+ if obj.respond_to?(:to_hash)
350
+ obj.to_hash
351
+ else
352
+ obj
353
+ end
354
+ end
355
+
356
+ # Build parameter value according to the given collection format.
357
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
358
+ def build_collection_param(param, collection_format)
359
+ case collection_format
360
+ when :csv
361
+ param.join(',')
362
+ when :ssv
363
+ param.join(' ')
364
+ when :tsv
365
+ param.join("\t")
366
+ when :pipes
367
+ param.join('|')
368
+ when :multi
369
+ # return the array directly as typhoeus will handle it as expected
370
+ param
371
+ else
372
+ fail "unknown collection format: #{collection_format.inspect}"
373
+ end
374
+ end
375
+ end
376
+ end
@@ -0,0 +1,37 @@
1
+ =begin
2
+ #Smooch
3
+
4
+ #The Smooch API is a unified interface for powering messaging in your customer experiences across every channel. Our API speeds access to new markets, reduces time to ship, eliminates complexity, and helps you build the best experiences for your customers. For more information, visit our [official documentation](https://docs.smooch.io).
5
+
6
+ OpenAPI spec version: 1
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+
10
+ =end
11
+
12
+ module SmoochApi
13
+ class ApiError < StandardError
14
+ attr_reader :code, :response_headers, :response_body
15
+
16
+ # Usage examples:
17
+ # ApiError.new
18
+ # ApiError.new("message")
19
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
20
+ # ApiError.new(:code => 404, :message => "Not Found")
21
+ def initialize(arg = nil)
22
+ if arg.is_a? Hash
23
+ if arg.key?(:message) || arg.key?('message')
24
+ super(arg[:message] || arg['message'])
25
+ else
26
+ super arg
27
+ end
28
+
29
+ arg.each do |k, v|
30
+ instance_variable_set "@#{k}", v
31
+ end
32
+ else
33
+ super arg
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,202 @@
1
+ =begin
2
+ #Smooch
3
+
4
+ #The Smooch API is a unified interface for powering messaging in your customer experiences across every channel. Our API speeds access to new markets, reduces time to ship, eliminates complexity, and helps you build the best experiences for your customers. For more information, visit our [official documentation](https://docs.smooch.io).
5
+
6
+ OpenAPI spec version: 1
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+
10
+ =end
11
+
12
+ require 'uri'
13
+
14
+ module SmoochApi
15
+ class Configuration
16
+ # Defines url scheme
17
+ attr_accessor :scheme
18
+
19
+ # Defines url host
20
+ attr_accessor :host
21
+
22
+ # Defines url base path
23
+ attr_accessor :base_path
24
+
25
+ # Defines API keys used with API Key authentications.
26
+ #
27
+ # @return [Hash] key: parameter name, value: parameter value (API key)
28
+ #
29
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
30
+ # config.api_key['api_key'] = 'xxx'
31
+ attr_accessor :api_key
32
+
33
+ # Defines API key prefixes used with API Key authentications.
34
+ #
35
+ # @return [Hash] key: parameter name, value: API key prefix
36
+ #
37
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
38
+ # config.api_key_prefix['api_key'] = 'Token'
39
+ attr_accessor :api_key_prefix
40
+
41
+ # Defines the username used with HTTP basic authentication.
42
+ #
43
+ # @return [String]
44
+ attr_accessor :username
45
+
46
+ # Defines the password used with HTTP basic authentication.
47
+ #
48
+ # @return [String]
49
+ attr_accessor :password
50
+
51
+ # Defines the access token (Bearer) used with OAuth2.
52
+ attr_accessor :access_token
53
+
54
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
55
+ # details will be logged with `logger.debug` (see the `logger` attribute).
56
+ # Default to false.
57
+ #
58
+ # @return [true, false]
59
+ attr_accessor :debugging
60
+
61
+ # Defines the logger used for debugging.
62
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
63
+ #
64
+ # @return [#debug]
65
+ attr_accessor :logger
66
+
67
+ # Defines the temporary folder to store downloaded files
68
+ # (for API endpoints that have file response).
69
+ # Default to use `Tempfile`.
70
+ #
71
+ # @return [String]
72
+ attr_accessor :temp_folder_path
73
+
74
+ # The time limit for HTTP request in seconds.
75
+ # Default to 0 (never times out).
76
+ attr_accessor :timeout
77
+
78
+ ### TLS/SSL setting
79
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
80
+ # Default to true.
81
+ #
82
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
83
+ #
84
+ # @return [true, false]
85
+ attr_accessor :verify_ssl
86
+
87
+ ### TLS/SSL setting
88
+ # Set this to false to skip verifying SSL host name
89
+ # Default to true.
90
+ #
91
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
92
+ #
93
+ # @return [true, false]
94
+ attr_accessor :verify_ssl_host
95
+
96
+ ### TLS/SSL setting
97
+ # Set this to customize the certificate file to verify the peer.
98
+ #
99
+ # @return [String] the path to the certificate file
100
+ #
101
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
102
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
103
+ attr_accessor :ssl_ca_cert
104
+
105
+ ### TLS/SSL setting
106
+ # Client certificate file (for client certificate)
107
+ attr_accessor :cert_file
108
+
109
+ ### TLS/SSL setting
110
+ # Client private key file (for client certificate)
111
+ attr_accessor :key_file
112
+
113
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
114
+ # Default to nil.
115
+ #
116
+ # @see The params_encoding option of Ethon. Related source code:
117
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
118
+ attr_accessor :params_encoding
119
+
120
+ attr_accessor :inject_format
121
+
122
+ attr_accessor :force_ending_format
123
+
124
+ def initialize
125
+ @scheme = 'https'
126
+ @host = 'api.smooch.io'
127
+ @base_path = '/v1'
128
+ @api_key = {}
129
+ @api_key_prefix = {}
130
+ @timeout = 0
131
+ @verify_ssl = true
132
+ @verify_ssl_host = true
133
+ @params_encoding = nil
134
+ @cert_file = nil
135
+ @key_file = nil
136
+ @debugging = false
137
+ @inject_format = false
138
+ @force_ending_format = false
139
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
140
+
141
+ yield(self) if block_given?
142
+ end
143
+
144
+ # The default Configuration object.
145
+ def self.default
146
+ @@default ||= Configuration.new
147
+ end
148
+
149
+ def configure
150
+ yield(self) if block_given?
151
+ end
152
+
153
+ def scheme=(scheme)
154
+ # remove :// from scheme
155
+ @scheme = scheme.sub(/:\/\//, '')
156
+ end
157
+
158
+ def host=(host)
159
+ # remove http(s):// and anything after a slash
160
+ @host = host.sub(/https?:\/\//, '').split('/').first
161
+ end
162
+
163
+ def base_path=(base_path)
164
+ # Add leading and trailing slashes to base_path
165
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
166
+ @base_path = "" if @base_path == "/"
167
+ end
168
+
169
+ def base_url
170
+ url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
171
+ URI.encode(url)
172
+ end
173
+
174
+ # Gets API key (with prefix if set).
175
+ # @param [String] param_name the parameter name of API key auth
176
+ def api_key_with_prefix(param_name)
177
+ if @api_key_prefix[param_name]
178
+ "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
179
+ else
180
+ @api_key[param_name]
181
+ end
182
+ end
183
+
184
+ # Gets Basic Auth token string
185
+ def basic_auth_token
186
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
187
+ end
188
+
189
+ # Returns Auth Settings hash for api client.
190
+ def auth_settings
191
+ {
192
+ 'jwt' =>
193
+ {
194
+ type: 'api_key',
195
+ in: 'header',
196
+ key: 'Authorization',
197
+ value: api_key_with_prefix('Authorization')
198
+ },
199
+ }
200
+ end
201
+ end
202
+ end