jamm 0.0.1 → 1.0.2

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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -57
  3. data/.rubocop.yml +18 -25
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +99 -0
  6. data/README.md +4 -4
  7. data/Rakefile +2 -0
  8. data/jamm.gemspec +16 -3
  9. data/lib/jamm/api/api/customer_api.rb +265 -0
  10. data/lib/jamm/api/api/healthcheck_api.rb +76 -0
  11. data/lib/jamm/api/api/payment_api.rb +203 -0
  12. data/lib/jamm/api/api_client.rb +385 -0
  13. data/lib/jamm/api/api_error.rb +58 -0
  14. data/lib/jamm/api/configuration.rb +293 -0
  15. data/lib/jamm/api/models/customer_service_update_customer_body.rb +247 -0
  16. data/lib/jamm/api/models/protobuf_any.rb +209 -0
  17. data/lib/jamm/api/models/rpc_status.rb +218 -0
  18. data/lib/jamm/api/models/v1_buyer.rb +274 -0
  19. data/lib/jamm/api/models/v1_charge.rb +233 -0
  20. data/lib/jamm/api/models/v1_contract.rb +225 -0
  21. data/lib/jamm/api/models/v1_create_contract_with_charge_request.rb +217 -0
  22. data/lib/jamm/api/models/v1_create_contract_with_charge_response.rb +222 -0
  23. data/lib/jamm/api/models/v1_create_contract_without_charge_request.rb +212 -0
  24. data/lib/jamm/api/models/v1_create_contract_without_charge_response.rb +217 -0
  25. data/lib/jamm/api/models/v1_create_customer_request.rb +207 -0
  26. data/lib/jamm/api/models/v1_create_customer_response.rb +207 -0
  27. data/lib/jamm/api/models/v1_customer.rb +223 -0
  28. data/lib/jamm/api/models/v1_delete_customer_response.rb +207 -0
  29. data/lib/jamm/api/models/v1_get_contract_response.rb +212 -0
  30. data/lib/jamm/api/models/v1_get_customer_response.rb +207 -0
  31. data/lib/jamm/api/models/v1_initial_charge.rb +225 -0
  32. data/lib/jamm/api/models/v1_merchant.rb +212 -0
  33. data/lib/jamm/api/models/v1_merchant_customer.rb +213 -0
  34. data/lib/jamm/api/models/v1_payment_link.rb +221 -0
  35. data/lib/jamm/api/models/v1_ping_response.rb +207 -0
  36. data/lib/jamm/api/models/v1_update_customer_response.rb +207 -0
  37. data/lib/jamm/api/models/v1_url.rb +216 -0
  38. data/lib/jamm/api/version.rb +15 -0
  39. data/lib/jamm/api.rb +65 -0
  40. data/lib/jamm/client.rb +14 -0
  41. data/lib/jamm/customer.rb +28 -0
  42. data/lib/jamm/errors.rb +4 -14
  43. data/lib/jamm/oauth.rb +5 -5
  44. data/lib/jamm/payment.rb +19 -11
  45. data/lib/jamm/version.rb +3 -1
  46. data/lib/jamm.rb +37 -117
  47. metadata +62 -37
  48. data/.github/workflows/build.yml +0 -23
  49. data/.github/workflows/ruby-publish.yml +0 -24
  50. data/CONTRIBUTORS +0 -1
  51. data/images/jamm_logo.png +0 -0
  52. data/lib/jamm/api_operations/create.rb +0 -16
  53. data/lib/jamm/api_operations/get.rb +0 -16
  54. data/lib/jamm/api_operations/list.rb +0 -16
  55. data/lib/jamm/api_operations/update.rb +0 -16
  56. data/lib/jamm/api_resource.rb +0 -5
  57. data/lib/jamm/charge.rb +0 -10
  58. data/lib/jamm/jamm_object.rb +0 -249
  59. data/lib/jamm/request.rb +0 -13
  60. data/lib/jamm/time_util.rb +0 -41
  61. data/lib/jamm/token.rb +0 -10
  62. data/lib/jamm/util.rb +0 -76
  63. data/test/jamm/charge_test.rb +0 -56
  64. data/test/jamm/oauth_test.rb +0 -47
  65. data/test/jamm/payment_test.rb +0 -17
  66. data/test/jamm/time_util_test.rb +0 -18
  67. data/test/jamm/token_test.rb +0 -52
  68. data/test/test_data.rb +0 -118
  69. data/test/test_helper.rb +0 -59
@@ -0,0 +1,203 @@
1
+ # frozen_string_literal: true
2
+
3
+ # #api/v1/common.proto
4
+ #
5
+ # No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6
+ #
7
+ # The version of the OpenAPI document: version not set
8
+ #
9
+ # Generated by: https://openapi-generator.tech
10
+ # Generator version: 7.9.0
11
+ #
12
+
13
+ require 'cgi'
14
+
15
+ module Api
16
+ class PaymentApi
17
+ attr_accessor :api_client
18
+
19
+ def initialize(api_client = ApiClient.default)
20
+ @api_client = api_client
21
+ end
22
+
23
+ # Create a contract with initial charge
24
+ # Create a contract with initial charge
25
+ # @param body [CreateContractWithChargeRequest]
26
+ # @param [Hash] opts the optional parameters
27
+ # @return [CreateContractWithChargeResponse]
28
+ def create_contract_with_charge(body, opts = {})
29
+ data, _status_code, _headers = create_contract_with_charge_with_http_info(body, opts)
30
+ data
31
+ end
32
+
33
+ # Create a contract with initial charge
34
+ # Create a contract with initial charge
35
+ # @param body [CreateContractWithChargeRequest]
36
+ # @param [Hash] opts the optional parameters
37
+ # @return [Array<(CreateContractWithChargeResponse, Integer, Hash)>] CreateContractWithChargeResponse data, response status code and response headers
38
+ def create_contract_with_charge_with_http_info(body, opts = {})
39
+ @api_client.config.logger.debug 'Calling API: PaymentApi.create_contract_with_charge ...' if @api_client.config.debugging
40
+ # verify the required parameter 'body' is set
41
+ raise ArgumentError, "Missing the required parameter 'body' when calling PaymentApi.create_contract_with_charge" if @api_client.config.client_side_validation && body.nil?
42
+
43
+ # resource path
44
+ local_var_path = '/v1/contract-with-charge'
45
+
46
+ # query parameters
47
+ query_params = opts[:query_params] || {}
48
+
49
+ # header parameters
50
+ header_params = opts[:header_params] || {}
51
+ # HTTP header 'Accept' (if needed)
52
+ header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
53
+ # HTTP header 'Content-Type'
54
+ content_type = @api_client.select_header_content_type(['application/json'])
55
+ header_params['Content-Type'] = content_type unless content_type.nil?
56
+
57
+ # form parameters
58
+ form_params = opts[:form_params] || {}
59
+
60
+ # http body (model)
61
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(body)
62
+
63
+ # return_type
64
+ return_type = opts[:debug_return_type] || 'CreateContractWithChargeResponse'
65
+
66
+ # auth_names
67
+ auth_names = opts[:debug_auth_names] || []
68
+
69
+ new_options = opts.merge(
70
+ :operation => :"PaymentApi.create_contract_with_charge",
71
+ :header_params => header_params,
72
+ :query_params => query_params,
73
+ :form_params => form_params,
74
+ :body => post_body,
75
+ :auth_names => auth_names,
76
+ :return_type => return_type
77
+ )
78
+
79
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
80
+ @api_client.config.logger.debug "API called: PaymentApi#create_contract_with_charge\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" if @api_client.config.debugging
81
+ [data, status_code, headers]
82
+ end
83
+
84
+ # Create a contract without initial charge (contract only)
85
+ # Create a contract without initial charge (contract only)
86
+ # @param body [CreateContractWithoutChargeRequest]
87
+ # @param [Hash] opts the optional parameters
88
+ # @return [CreateContractWithoutChargeResponse]
89
+ def create_contract_without_charge(body, opts = {})
90
+ data, _status_code, _headers = create_contract_without_charge_with_http_info(body, opts)
91
+ data
92
+ end
93
+
94
+ # Create a contract without initial charge (contract only)
95
+ # Create a contract without initial charge (contract only)
96
+ # @param body [CreateContractWithoutChargeRequest]
97
+ # @param [Hash] opts the optional parameters
98
+ # @return [Array<(CreateContractWithoutChargeResponse, Integer, Hash)>] CreateContractWithoutChargeResponse data, response status code and response headers
99
+ def create_contract_without_charge_with_http_info(body, opts = {})
100
+ @api_client.config.logger.debug 'Calling API: PaymentApi.create_contract_without_charge ...' if @api_client.config.debugging
101
+ # verify the required parameter 'body' is set
102
+ raise ArgumentError, "Missing the required parameter 'body' when calling PaymentApi.create_contract_without_charge" if @api_client.config.client_side_validation && body.nil?
103
+
104
+ # resource path
105
+ local_var_path = '/v1/contract-without-charge'
106
+
107
+ # query parameters
108
+ query_params = opts[:query_params] || {}
109
+
110
+ # header parameters
111
+ header_params = opts[:header_params] || {}
112
+ # HTTP header 'Accept' (if needed)
113
+ header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
114
+ # HTTP header 'Content-Type'
115
+ content_type = @api_client.select_header_content_type(['application/json'])
116
+ header_params['Content-Type'] = content_type unless content_type.nil?
117
+
118
+ # form parameters
119
+ form_params = opts[:form_params] || {}
120
+
121
+ # http body (model)
122
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(body)
123
+
124
+ # return_type
125
+ return_type = opts[:debug_return_type] || 'CreateContractWithoutChargeResponse'
126
+
127
+ # auth_names
128
+ auth_names = opts[:debug_auth_names] || []
129
+
130
+ new_options = opts.merge(
131
+ :operation => :"PaymentApi.create_contract_without_charge",
132
+ :header_params => header_params,
133
+ :query_params => query_params,
134
+ :form_params => form_params,
135
+ :body => post_body,
136
+ :auth_names => auth_names,
137
+ :return_type => return_type
138
+ )
139
+
140
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
141
+ @api_client.config.logger.debug "API called: PaymentApi#create_contract_without_charge\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" if @api_client.config.debugging
142
+ [data, status_code, headers]
143
+ end
144
+
145
+ # Get a contract
146
+ # Get a contract information
147
+ # @param contract [String] @gotags: validate:\&quot;required\&quot;
148
+ # @param [Hash] opts the optional parameters
149
+ # @return [GetContractResponse]
150
+ def get_contract(contract, opts = {})
151
+ data, _status_code, _headers = get_contract_with_http_info(contract, opts)
152
+ data
153
+ end
154
+
155
+ # Get a contract
156
+ # Get a contract information
157
+ # @param contract [String] @gotags: validate:\&quot;required\&quot;
158
+ # @param [Hash] opts the optional parameters
159
+ # @return [Array<(GetContractResponse, Integer, Hash)>] GetContractResponse data, response status code and response headers
160
+ def get_contract_with_http_info(contract, opts = {})
161
+ @api_client.config.logger.debug 'Calling API: PaymentApi.get_contract ...' if @api_client.config.debugging
162
+ # verify the required parameter 'contract' is set
163
+ raise ArgumentError, "Missing the required parameter 'contract' when calling PaymentApi.get_contract" if @api_client.config.client_side_validation && contract.nil?
164
+
165
+ # resource path
166
+ local_var_path = '/v1/contracts/{contract}'.sub('{contract}', CGI.escape(contract.to_s))
167
+
168
+ # query parameters
169
+ query_params = opts[:query_params] || {}
170
+
171
+ # header parameters
172
+ header_params = opts[:header_params] || {}
173
+ # HTTP header 'Accept' (if needed)
174
+ header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
175
+
176
+ # form parameters
177
+ form_params = opts[:form_params] || {}
178
+
179
+ # http body (model)
180
+ post_body = opts[:debug_body]
181
+
182
+ # return_type
183
+ return_type = opts[:debug_return_type] || 'GetContractResponse'
184
+
185
+ # auth_names
186
+ auth_names = opts[:debug_auth_names] || []
187
+
188
+ new_options = opts.merge(
189
+ :operation => :"PaymentApi.get_contract",
190
+ :header_params => header_params,
191
+ :query_params => query_params,
192
+ :form_params => form_params,
193
+ :body => post_body,
194
+ :auth_names => auth_names,
195
+ :return_type => return_type
196
+ )
197
+
198
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
199
+ @api_client.config.logger.debug "API called: PaymentApi#get_contract\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" if @api_client.config.debugging
200
+ [data, status_code, headers]
201
+ end
202
+ end
203
+ end
@@ -0,0 +1,385 @@
1
+ # frozen_string_literal: true
2
+
3
+ # #api/v1/common.proto
4
+ #
5
+ # No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6
+ #
7
+ # The version of the OpenAPI document: version not set
8
+ #
9
+ # Generated by: https://openapi-generator.tech
10
+ # Generator version: 7.9.0
11
+ #
12
+
13
+ require 'date'
14
+ require 'json'
15
+ require 'logger'
16
+ require 'tempfile'
17
+ require 'time'
18
+ require 'typhoeus'
19
+
20
+ module Api
21
+ class ApiClient
22
+ # The Configuration object holding settings to be used in the API client.
23
+ attr_accessor :config
24
+
25
+ # Defines the headers to be used in HTTP requests of all API calls by default.
26
+ #
27
+ # @return [Hash]
28
+ attr_accessor :default_headers
29
+
30
+ # Initializes the ApiClient
31
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
32
+ def initialize(config = Configuration.default)
33
+ @config = config
34
+ @user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
35
+ @default_headers = {
36
+ 'Content-Type' => 'application/json',
37
+ 'User-Agent' => @user_agent
38
+ }
39
+ end
40
+
41
+ def self.default
42
+ @@default ||= ApiClient.new
43
+ end
44
+
45
+ # Call an API with given options.
46
+ #
47
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
48
+ # the data deserialized from response body (may be a Tempfile or nil), response status code and response headers.
49
+ def call_api(http_method, path, opts = {})
50
+ request = build_request(http_method, path, opts)
51
+ tempfile = download_file(request) if opts[:return_type] == 'File'
52
+ response = request.run
53
+
54
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n" if @config.debugging
55
+
56
+ unless response.success?
57
+ if response.timed_out?
58
+ raise ApiError, 'Connection timed out'
59
+ elsif response.code.zero?
60
+ # Errors from libcurl will be made visible here
61
+ raise ApiError.new(:code => 0,
62
+ :message => response.return_message)
63
+ else
64
+ raise 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
+ data = if opts[:return_type] == 'File'
72
+ tempfile
73
+ elsif opts[:return_type]
74
+ deserialize(response, opts[:return_type])
75
+ end
76
+ [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, opts)
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
+ follow_location = opts[:follow_location] || true
96
+
97
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
98
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
99
+
100
+ req_opts = {
101
+ :method => http_method,
102
+ :headers => header_params,
103
+ :params => query_params,
104
+ :params_encoding => @config.params_encoding,
105
+ :timeout => @config.timeout,
106
+ :ssl_verifypeer => @config.verify_ssl,
107
+ :ssl_verifyhost => _verify_ssl_host,
108
+ :sslcert => @config.cert_file,
109
+ :sslkey => @config.key_file,
110
+ :verbose => @config.debugging,
111
+ :followlocation => follow_location
112
+ }
113
+
114
+ # set custom cert, if provided
115
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
116
+
117
+ if %i[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
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n" if @config.debugging
121
+ end
122
+
123
+ Typhoeus::Request.new(url, req_opts)
124
+ end
125
+
126
+ # Builds the HTTP request body
127
+ #
128
+ # @param [Hash] header_params Header parameters
129
+ # @param [Hash] form_params Query parameters
130
+ # @param [Object] body HTTP body (JSON/XML)
131
+ # @return [String] HTTP body data in the form of string
132
+ def build_request_body(header_params, form_params, body)
133
+ # http form
134
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
135
+ header_params['Content-Type'] == 'multipart/form-data'
136
+ data = {}
137
+ form_params.each do |key, value|
138
+ data[key] = case value
139
+ when ::File, ::Array, nil
140
+ # let typhoeus handle File, Array and nil parameters
141
+ value
142
+ else
143
+ value.to_s
144
+ end
145
+ end
146
+ elsif body
147
+ data = body.is_a?(String) ? body : body.to_json
148
+ else
149
+ data = nil
150
+ end
151
+ data
152
+ end
153
+
154
+ # Save response body into a file in (the defined) temporary folder, using the filename
155
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
156
+ # The response body is written to the file in chunks in order to handle files which
157
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
158
+ # process can use.
159
+ #
160
+ # @see Configuration#temp_folder_path
161
+ #
162
+ # @return [Tempfile] the tempfile generated
163
+ def download_file(request)
164
+ tempfile = nil
165
+ encoding = nil
166
+ request.on_headers do |response|
167
+ content_disposition = response.headers['Content-Disposition']
168
+ if content_disposition && content_disposition =~ /filename=/i
169
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
170
+ prefix = sanitize_filename(filename)
171
+ else
172
+ prefix = 'download-'
173
+ end
174
+ prefix += '-' unless prefix.end_with?('-')
175
+ encoding = response.body.encoding
176
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
177
+ end
178
+ request.on_body do |chunk|
179
+ chunk.force_encoding(encoding)
180
+ tempfile.write(chunk)
181
+ end
182
+ # run the request to ensure the tempfile is created successfully before returning it
183
+ request.run
184
+ raise ApiError, "Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}" unless tempfile
185
+
186
+ tempfile.close
187
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
188
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
189
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
190
+ 'explicitly with `tempfile.delete`'
191
+
192
+ tempfile
193
+ end
194
+
195
+ # Check if the given MIME is a JSON MIME.
196
+ # JSON MIME examples:
197
+ # application/json
198
+ # application/json; charset=UTF8
199
+ # APPLICATION/JSON
200
+ # */*
201
+ # @param [String] mime MIME
202
+ # @return [Boolean] True if the MIME is application/json
203
+ def json_mime?(mime)
204
+ (mime == '*/*') || !(mime =~ %r{^Application/.*json(?!p)(;.*)?}i).nil?
205
+ end
206
+
207
+ # Deserialize the response to the given return type.
208
+ #
209
+ # @param [Response] response HTTP response
210
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
211
+ def deserialize(response, return_type)
212
+ body = response.body
213
+ return nil if body.nil? || body.empty?
214
+
215
+ # return response body directly for String return type
216
+ return body.to_s if return_type == 'String'
217
+
218
+ # ensuring a default content type
219
+ content_type = response.headers['Content-Type'] || 'application/json'
220
+
221
+ raise "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
222
+
223
+ begin
224
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
225
+ rescue JSON::ParserError => e
226
+ raise e unless %w[String Date Time].include?(return_type)
227
+
228
+ data = body
229
+ end
230
+
231
+ convert_to_type data, return_type
232
+ end
233
+
234
+ # Convert data to the given return type.
235
+ # @param [Object] data Data to be converted
236
+ # @param [String] return_type Return type
237
+ # @return [Mixed] Data in a particular type
238
+ def convert_to_type(data, return_type)
239
+ return nil if data.nil?
240
+
241
+ case return_type
242
+ when 'String'
243
+ data.to_s
244
+ when 'Integer'
245
+ data.to_i
246
+ when 'Float'
247
+ data.to_f
248
+ when 'Boolean'
249
+ data == true
250
+ when 'Time'
251
+ # parse date time (expecting ISO 8601 format)
252
+ Time.parse data
253
+ when 'Date'
254
+ # parse date time (expecting ISO 8601 format)
255
+ Date.parse data
256
+ when 'Object'
257
+ # generic object (usually a Hash), return directly
258
+ data
259
+ when /\AArray<(.+)>\z/
260
+ # e.g. Array<Pet>
261
+ sub_type = ::Regexp.last_match(1)
262
+ data.map { |item| convert_to_type(item, sub_type) }
263
+ when /\AHash<String, (.+)>\z/
264
+ # e.g. Hash<String, Integer>
265
+ sub_type = ::Regexp.last_match(1)
266
+ {}.tap do |hash|
267
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
268
+ end
269
+ else
270
+ # models (e.g. Pet) or oneOf
271
+ klass = Api.const_get(return_type)
272
+ klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
273
+ end
274
+ end
275
+
276
+ # Sanitize filename by removing path.
277
+ # e.g. ../../sun.gif becomes sun.gif
278
+ #
279
+ # @param [String] filename the filename to be sanitized
280
+ # @return [String] the sanitized filename
281
+ def sanitize_filename(filename)
282
+ filename.split(%r{[/\\]}).last
283
+ end
284
+
285
+ def build_request_url(path, opts = {})
286
+ # Add leading and trailing slashes to path
287
+ path = "/#{path}".gsub(%r{/+}, '/')
288
+ @config.base_url(opts[:operation]) + path
289
+ end
290
+
291
+ # Update header and query params based on authentication settings.
292
+ #
293
+ # @param [Hash] header_params Header parameters
294
+ # @param [Hash] query_params Query parameters
295
+ # @param [String] auth_names Authentication scheme name
296
+ def update_params_for_auth!(header_params, query_params, auth_names)
297
+ Array(auth_names).each do |auth_name|
298
+ auth_setting = @config.auth_settings[auth_name]
299
+ next unless auth_setting
300
+
301
+ case auth_setting[:in]
302
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
303
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
304
+ else raise ArgumentError, 'Authentication token must be in `query` or `header`'
305
+ end
306
+ end
307
+ end
308
+
309
+ # Sets user agent in HTTP header
310
+ #
311
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
312
+ def user_agent=(user_agent)
313
+ @user_agent = user_agent
314
+ @default_headers['User-Agent'] = @user_agent
315
+ end
316
+
317
+ # Return Accept header based on an array of accepts provided.
318
+ # @param [Array] accepts array for Accept
319
+ # @return [String] the Accept header (e.g. application/json)
320
+ def select_header_accept(accepts)
321
+ return nil if accepts.nil? || accepts.empty?
322
+
323
+ # use JSON when present, otherwise use all of the provided
324
+ json_accept = accepts.find { |s| json_mime?(s) }
325
+ json_accept || accepts.join(',')
326
+ end
327
+
328
+ # Return Content-Type header based on an array of content types provided.
329
+ # @param [Array] content_types array for Content-Type
330
+ # @return [String] the Content-Type header (e.g. application/json)
331
+ def select_header_content_type(content_types)
332
+ # return nil by default
333
+ return if content_types.nil? || content_types.empty?
334
+
335
+ # use JSON when present, otherwise use the first one
336
+ json_content_type = content_types.find { |s| json_mime?(s) }
337
+ json_content_type || content_types.first
338
+ end
339
+
340
+ # Convert object (array, hash, object, etc) to JSON string.
341
+ # @param [Object] model object to be converted into JSON string
342
+ # @return [String] JSON string representation of the object
343
+ def object_to_http_body(model)
344
+ return model if model.nil? || model.is_a?(String)
345
+
346
+ local_body = if model.is_a?(Array)
347
+ model.map { |m| object_to_hash(m) }
348
+ else
349
+ object_to_hash(model)
350
+ end
351
+ local_body.to_json
352
+ end
353
+
354
+ # Convert object(non-array) to hash.
355
+ # @param [Object] obj object to be converted into JSON string
356
+ # @return [String] JSON string representation of the object
357
+ def object_to_hash(obj)
358
+ if obj.respond_to?(:to_hash)
359
+ obj.to_hash
360
+ else
361
+ obj
362
+ end
363
+ end
364
+
365
+ # Build parameter value according to the given collection format.
366
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
367
+ def build_collection_param(param, collection_format)
368
+ case collection_format
369
+ when :csv
370
+ param.join(',')
371
+ when :ssv
372
+ param.join(' ')
373
+ when :tsv
374
+ param.join("\t")
375
+ when :pipes
376
+ param.join('|')
377
+ when :multi
378
+ # return the array directly as typhoeus will handle it as expected
379
+ param
380
+ else
381
+ raise "unknown collection format: #{collection_format.inspect}"
382
+ end
383
+ end
384
+ end
385
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ # #api/v1/common.proto
4
+ #
5
+ # No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6
+ #
7
+ # The version of the OpenAPI document: version not set
8
+ #
9
+ # Generated by: https://openapi-generator.tech
10
+ # Generator version: 7.9.0
11
+ #
12
+
13
+ module Api
14
+ class ApiError < StandardError
15
+ attr_reader :code, :response_headers, :response_body
16
+
17
+ # Usage examples:
18
+ # ApiError.new
19
+ # ApiError.new("message")
20
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
21
+ # ApiError.new(:code => 404, :message => "Not Found")
22
+ def initialize(arg = nil)
23
+ if arg.is_a? Hash
24
+ if arg.key?(:message) || arg.key?('message')
25
+ super(arg[:message] || arg['message'])
26
+ else
27
+ super arg
28
+ end
29
+
30
+ arg.each do |k, v|
31
+ instance_variable_set "@#{k}", v
32
+ end
33
+ else
34
+ super arg
35
+ @message = arg
36
+ end
37
+ end
38
+
39
+ # Override to_s to display a friendly error message
40
+ def to_s
41
+ message
42
+ end
43
+
44
+ def message
45
+ msg = if @message.nil?
46
+ 'Error message: the server returns an error'
47
+ else
48
+ @message
49
+ end
50
+
51
+ msg += "\nHTTP status code: #{code}" if code
52
+ msg += "\nResponse headers: #{response_headers}" if response_headers
53
+ msg += "\nResponse body: #{response_body}" if response_body
54
+
55
+ msg
56
+ end
57
+ end
58
+ end