blueprint_ruby_client 0.1.0

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 (83) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +65 -0
  4. data/README.md +152 -0
  5. data/blueprint_ruby_client.gemspec +31 -0
  6. data/config.json +13 -0
  7. data/docs/Asset.md +9 -0
  8. data/docs/AssetBody.md +9 -0
  9. data/docs/AssetResultSet.md +9 -0
  10. data/docs/AssetsApi.md +376 -0
  11. data/docs/Error.md +10 -0
  12. data/docs/Errors.md +8 -0
  13. data/docs/HierarchyApi.md +745 -0
  14. data/docs/Links.md +10 -0
  15. data/docs/Meta.md +10 -0
  16. data/docs/Namespace.md +9 -0
  17. data/docs/NamespaceRelationship.md +8 -0
  18. data/docs/Node.md +11 -0
  19. data/docs/NodeAttributes.md +13 -0
  20. data/docs/NodeBody.md +9 -0
  21. data/docs/NodeRelationship.md +10 -0
  22. data/docs/NodeRelationships.md +10 -0
  23. data/docs/NodeResultSet.md +10 -0
  24. data/generate.sh +7 -0
  25. data/git_push.sh +52 -0
  26. data/lib/blueprint_ruby_client/api/assets_api.rb +598 -0
  27. data/lib/blueprint_ruby_client/api/hierarchy_api.rb +1174 -0
  28. data/lib/blueprint_ruby_client/api_client.rb +365 -0
  29. data/lib/blueprint_ruby_client/api_error.rb +36 -0
  30. data/lib/blueprint_ruby_client/configuration.rb +170 -0
  31. data/lib/blueprint_ruby_client/models/asset.rb +242 -0
  32. data/lib/blueprint_ruby_client/models/asset_body.rb +237 -0
  33. data/lib/blueprint_ruby_client/models/asset_result_set.rb +234 -0
  34. data/lib/blueprint_ruby_client/models/error.rb +267 -0
  35. data/lib/blueprint_ruby_client/models/errors.rb +209 -0
  36. data/lib/blueprint_ruby_client/models/links.rb +257 -0
  37. data/lib/blueprint_ruby_client/models/meta.rb +260 -0
  38. data/lib/blueprint_ruby_client/models/namespace.rb +242 -0
  39. data/lib/blueprint_ruby_client/models/namespace_relationship.rb +207 -0
  40. data/lib/blueprint_ruby_client/models/node.rb +293 -0
  41. data/lib/blueprint_ruby_client/models/node_attributes.rb +338 -0
  42. data/lib/blueprint_ruby_client/models/node_body.rb +237 -0
  43. data/lib/blueprint_ruby_client/models/node_relationship.rb +259 -0
  44. data/lib/blueprint_ruby_client/models/node_relationships.rb +257 -0
  45. data/lib/blueprint_ruby_client/models/node_result_set.rb +261 -0
  46. data/lib/blueprint_ruby_client/version.rb +15 -0
  47. data/lib/blueprint_ruby_client.rb +56 -0
  48. data/spec/api/assets_api_spec.rb +150 -0
  49. data/spec/api/hierarchy_api_spec.rb +266 -0
  50. data/spec/models/asset_body_spec.rb +56 -0
  51. data/spec/models/asset_result_set_spec.rb +56 -0
  52. data/spec/models/asset_spec.rb +56 -0
  53. data/spec/models/error_spec.rb +66 -0
  54. data/spec/models/errors_spec.rb +46 -0
  55. data/spec/models/links_spec.rb +66 -0
  56. data/spec/models/meta_spec.rb +66 -0
  57. data/spec/models/namespace_relationship_spec.rb +46 -0
  58. data/spec/models/namespace_spec.rb +56 -0
  59. data/spec/models/node_attributes_spec.rb +96 -0
  60. data/spec/models/node_body_spec.rb +56 -0
  61. data/spec/models/node_relationship_spec.rb +66 -0
  62. data/spec/models/node_relationships_spec.rb +66 -0
  63. data/spec/models/node_result_set_spec.rb +66 -0
  64. data/spec/models/node_spec.rb +76 -0
  65. data/swagger-codegen-cli.jar +0 -0
  66. data/templates/Gemfile.mustache +4 -0
  67. data/templates/README.mustache +139 -0
  68. data/templates/api.mustache +135 -0
  69. data/templates/api_client.mustache +357 -0
  70. data/templates/api_doc.mustache +79 -0
  71. data/templates/api_error.mustache +28 -0
  72. data/templates/api_info.mustache +18 -0
  73. data/templates/api_test.mustache +47 -0
  74. data/templates/base_object.mustache +103 -0
  75. data/templates/configuration.mustache +192 -0
  76. data/templates/gem.mustache +40 -0
  77. data/templates/gemspec.mustache +31 -0
  78. data/templates/gitignore.mustache +40 -0
  79. data/templates/model.mustache +242 -0
  80. data/templates/model_doc.mustache +9 -0
  81. data/templates/model_test.mustache +40 -0
  82. data/templates/version.mustache +7 -0
  83. metadata +322 -0
@@ -0,0 +1,365 @@
1
+ =begin
2
+ Talis Blueprint API
3
+
4
+ This is the API documentation for [Blueprint](https://github.com/talis/blueprint-server), a primitive for institutional structure and time periods
5
+
6
+ OpenAPI spec version: 1.0.0
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'json'
15
+ require 'logger'
16
+ require 'tempfile'
17
+ require 'typhoeus'
18
+ require 'uri'
19
+
20
+ module BlueprintClient
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] Configuraiton for initializing the object, default to Configuration.default
32
+ def initialize(config = Configuration.default)
33
+ @config = config
34
+ @user_agent = "talis-blueprint-client/#{VERSION} ruby/#{RUBY_VERSION}"
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, Fixnum, Hash)>] an array of 3 elements:
48
+ # the data deserialized from response body (could be nil), response status code and response headers.
49
+ def call_api(http_method, path, opts = {})
50
+ request = build_request(http_method, path, opts)
51
+ response = request.run
52
+
53
+ if @config.debugging
54
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
55
+ end
56
+
57
+ unless response.success?
58
+ fail ApiError.new(:code => response.code,
59
+ :response_headers => response.headers,
60
+ :response_body => response.body),
61
+ response.status_message
62
+ end
63
+
64
+ if opts[:return_type]
65
+ data = deserialize(response, opts[:return_type])
66
+ else
67
+ data = nil
68
+ end
69
+ return data, response.code, response.headers
70
+ end
71
+
72
+ # Builds the HTTP request
73
+ #
74
+ # @param [String] http_method HTTP method/verb (e.g. POST)
75
+ # @param [String] path URL path (e.g. /account/new)
76
+ # @option opts [Hash] :header_params Header parameters
77
+ # @option opts [Hash] :query_params Query parameters
78
+ # @option opts [Hash] :form_params Query parameters
79
+ # @option opts [Object] :body HTTP body (JSON/XML)
80
+ # @return [Typhoeus::Request] A Typhoeus Request
81
+ def build_request(http_method, path, opts = {})
82
+ url = build_request_url(path)
83
+ http_method = http_method.to_sym.downcase
84
+
85
+ header_params = @default_headers.merge(opts[:header_params] || {})
86
+ query_params = opts[:query_params] || {}
87
+ form_params = opts[:form_params] || {}
88
+
89
+
90
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
91
+
92
+
93
+ req_opts = {
94
+ :method => http_method,
95
+ :headers => header_params,
96
+ :params => query_params,
97
+ :timeout => @config.timeout,
98
+ :ssl_verifypeer => @config.verify_ssl,
99
+ :sslcert => @config.cert_file,
100
+ :sslkey => @config.key_file,
101
+ :verbose => @config.debugging
102
+ }
103
+
104
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
105
+
106
+ if [:post, :patch, :put, :delete].include?(http_method)
107
+ req_body = build_request_body(header_params, form_params, opts[:body])
108
+ req_opts.update :body => req_body
109
+ if @config.debugging
110
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
111
+ end
112
+ end
113
+
114
+ Typhoeus::Request.new(url, req_opts)
115
+ end
116
+
117
+ # Check if the given MIME is a JSON MIME.
118
+ # JSON MIME examples:
119
+ # application/json
120
+ # application/vnd.api+json
121
+ # application/json; charset=UTF8
122
+ # APPLICATION/JSON
123
+ # @param [String] mime MIME
124
+ # @return [Boolean] True if the MIME is applicaton/json
125
+ def json_mime?(mime)
126
+ !(mime =~ /\Aapplication\/(vnd\.api\+)?json(;.*)?\z/i).nil?
127
+ end
128
+
129
+ # Deserialize the response to the given return type.
130
+ #
131
+ # @param [Response] response HTTP response
132
+ # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
133
+ def deserialize(response, return_type)
134
+ body = response.body
135
+ return nil if body.nil? || body.empty?
136
+
137
+ # return response body directly for String return type
138
+ return body if return_type == 'String'
139
+
140
+ # handle file downloading - save response body into a tmp file and return the File instance
141
+ return download_file(response) if return_type == 'File'
142
+
143
+ # ensuring a default content type
144
+ content_type = response.headers['Content-Type'] || 'application/json'
145
+
146
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
147
+
148
+ begin
149
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
150
+ rescue JSON::ParserError => e
151
+ if %w(String Date DateTime).include?(return_type)
152
+ data = body
153
+ else
154
+ raise e
155
+ end
156
+ end
157
+
158
+ convert_to_type data, return_type
159
+ end
160
+
161
+ # Convert data to the given return type.
162
+ # @param [Object] data Data to be converted
163
+ # @param [String] return_type Return type
164
+ # @return [Mixed] Data in a particular type
165
+ def convert_to_type(data, return_type)
166
+ return nil if data.nil?
167
+ case return_type
168
+ when 'String'
169
+ data.to_s
170
+ when 'Integer'
171
+ data.to_i
172
+ when 'Float'
173
+ data.to_f
174
+ when 'BOOLEAN'
175
+ data == true
176
+ when 'DateTime'
177
+ # parse date time (expecting ISO 8601 format)
178
+ DateTime.parse data
179
+ when 'Date'
180
+ # parse date time (expecting ISO 8601 format)
181
+ Date.parse data
182
+ when 'Object'
183
+ # generic object (usually a Hash), return directly
184
+ data
185
+ when /\AArray<(.+)>\z/
186
+ # e.g. Array<Pet>
187
+ sub_type = $1
188
+ data.map {|item| convert_to_type(item, sub_type) }
189
+ when /\AHash\<String, (.+)\>\z/
190
+ # e.g. Hash<String, Integer>
191
+ sub_type = $1
192
+ {}.tap do |hash|
193
+ data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
194
+ end
195
+ else
196
+ # models, e.g. Pet
197
+ BlueprintClient.const_get(return_type).new.tap do |model|
198
+ model.build_from_hash data
199
+ end
200
+ end
201
+ end
202
+
203
+ # Save response body into a file in (the defined) temporary folder, using the filename
204
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
205
+ #
206
+ # @see Configuration#temp_folder_path
207
+ # @return [Tempfile] the file downloaded
208
+ def download_file(response)
209
+ content_disposition = response.headers['Content-Disposition']
210
+ if content_disposition
211
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
212
+ prefix = sanitize_filename(filename)
213
+ else
214
+ prefix = 'download-'
215
+ end
216
+ prefix = prefix + '-' unless prefix.end_with?('-')
217
+
218
+ tempfile = nil
219
+ encoding = response.body.encoding
220
+ Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) do |file|
221
+ file.write(response.body)
222
+ tempfile = file
223
+ end
224
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
225
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
226
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
227
+ "explicitly with `tempfile.delete`"
228
+ tempfile
229
+ end
230
+
231
+ # Sanitize filename by removing path.
232
+ # e.g. ../../sun.gif becomes sun.gif
233
+ #
234
+ # @param [String] filename the filename to be sanitized
235
+ # @return [String] the sanitized filename
236
+ def sanitize_filename(filename)
237
+ filename.gsub(/.*[\/\\]/, '')
238
+ end
239
+
240
+ def build_request_url(path)
241
+ # Add leading and trailing slashes to path
242
+ path = "/#{path}".gsub(/\/+/, '/')
243
+ URI.encode(@config.base_url + path)
244
+ end
245
+
246
+ # Builds the HTTP request body
247
+ #
248
+ # @param [Hash] header_params Header parameters
249
+ # @param [Hash] form_params Query parameters
250
+ # @param [Object] body HTTP body (JSON/XML)
251
+ # @return [String] HTTP body data in the form of string
252
+ def build_request_body(header_params, form_params, body)
253
+ # http form
254
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
255
+ header_params['Content-Type'] == 'multipart/form-data'
256
+ data = {}
257
+ form_params.each do |key, value|
258
+ case value
259
+ when File, Array, nil
260
+ # let typhoeus handle File, Array and nil parameters
261
+ data[key] = value
262
+ else
263
+ data[key] = value.to_s
264
+ end
265
+ end
266
+ elsif body
267
+ data = body.is_a?(String) ? body : body.to_json
268
+ else
269
+ data = nil
270
+ end
271
+ data
272
+ end
273
+
274
+ # Update hearder and query params based on authentication settings.
275
+ #
276
+ # @param [Hash] header_params Header parameters
277
+ # @param [Hash] form_params Query parameters
278
+ # @param [String] auth_names Authentication scheme name
279
+ def update_params_for_auth!(header_params, query_params, auth_names)
280
+ Array(auth_names).each do |auth_name|
281
+ auth_setting = @config.auth_settings[auth_name]
282
+ next unless auth_setting
283
+ case auth_setting[:in]
284
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
285
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
286
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
287
+ end
288
+ end
289
+ end
290
+
291
+ # Sets user agent in HTTP header
292
+ #
293
+ # @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
294
+ def user_agent=(user_agent)
295
+ @user_agent = user_agent
296
+ @default_headers['User-Agent'] = @user_agent
297
+ end
298
+
299
+ # Return Accept header based on an array of accepts provided.
300
+ # @param [Array] accepts array for Accept
301
+ # @return [String] the Accept header (e.g. application/json)
302
+ def select_header_accept(accepts)
303
+ return nil if accepts.nil? || accepts.empty?
304
+ # use JSON when present, otherwise use all of the provided
305
+ json_accept = accepts.find { |s| json_mime?(s) }
306
+ return json_accept || accepts.join(',')
307
+ end
308
+
309
+ # Return Content-Type header based on an array of content types provided.
310
+ # @param [Array] content_types array for Content-Type
311
+ # @return [String] the Content-Type header (e.g. application/json)
312
+ def select_header_content_type(content_types)
313
+ # use application/json by default
314
+ return 'application/json' if content_types.nil? || content_types.empty?
315
+ # use JSON when present, otherwise use the first one
316
+ json_content_type = content_types.find { |s| json_mime?(s) }
317
+ return json_content_type || content_types.first
318
+ end
319
+
320
+ # Convert object (array, hash, object, etc) to JSON string.
321
+ # @param [Object] model object to be converted into JSON string
322
+ # @return [String] JSON string representation of the object
323
+ def object_to_http_body(model)
324
+ return model if model.nil? || model.is_a?(String)
325
+ local_body = nil
326
+ if model.is_a?(Array)
327
+ local_body = model.map{|m| object_to_hash(m) }
328
+ else
329
+ local_body = object_to_hash(model)
330
+ end
331
+ local_body.to_json
332
+ end
333
+
334
+ # Convert object(non-array) to hash.
335
+ # @param [Object] obj object to be converted into JSON string
336
+ # @return [String] JSON string representation of the object
337
+ def object_to_hash(obj)
338
+ if obj.respond_to?(:to_hash)
339
+ obj.to_hash
340
+ else
341
+ obj
342
+ end
343
+ end
344
+
345
+ # Build parameter value according to the given collection format.
346
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
347
+ def build_collection_param(param, collection_format)
348
+ case collection_format
349
+ when :csv
350
+ param.join(',')
351
+ when :ssv
352
+ param.join(' ')
353
+ when :tsv
354
+ param.join("\t")
355
+ when :pipes
356
+ param.join('|')
357
+ when :multi
358
+ # return the array directly as typhoeus will handle it as expected
359
+ param
360
+ else
361
+ fail "unknown collection format: #{collection_format.inspect}"
362
+ end
363
+ end
364
+ end
365
+ end
@@ -0,0 +1,36 @@
1
+ =begin
2
+ Talis Blueprint API
3
+
4
+ This is the API documentation for [Blueprint](https://github.com/talis/blueprint-server), a primitive for institutional structure and time periods
5
+
6
+ OpenAPI spec version: 1.0.0
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+
10
+
11
+ =end
12
+
13
+ module BlueprintClient
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
+ arg.each do |k, v|
25
+ if k.to_s == 'message'
26
+ super v
27
+ else
28
+ instance_variable_set "@#{k}", v
29
+ end
30
+ end
31
+ else
32
+ super arg
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,170 @@
1
+ require 'uri'
2
+
3
+ module BlueprintClient
4
+ class Configuration
5
+ # Defines url scheme
6
+ attr_accessor :scheme
7
+
8
+ # Defines url host
9
+ attr_accessor :host
10
+
11
+ # Defines url base path
12
+ attr_accessor :base_path
13
+
14
+ # Defines API keys used with API Key authentications.
15
+ #
16
+ # @return [Hash] key: parameter name, value: parameter value (API key)
17
+ #
18
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
19
+ # config.api_key['api_key'] = 'xxx'
20
+ attr_accessor :api_key
21
+
22
+ # Defines API key prefixes used with API Key authentications.
23
+ #
24
+ # @return [Hash] key: parameter name, value: API key prefix
25
+ #
26
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
27
+ # config.api_key_prefix['api_key'] = 'Token'
28
+ attr_accessor :api_key_prefix
29
+
30
+ # Defines the username used with HTTP basic authentication.
31
+ #
32
+ # @return [String]
33
+ attr_accessor :username
34
+
35
+ # Defines the password used with HTTP basic authentication.
36
+ #
37
+ # @return [String]
38
+ attr_accessor :password
39
+
40
+ # Defines the access token (Bearer) used with OAuth2.
41
+ attr_accessor :access_token
42
+
43
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
44
+ # details will be logged with `logger.debug` (see the `logger` attribute).
45
+ # Default to false.
46
+ #
47
+ # @return [true, false]
48
+ attr_accessor :debugging
49
+
50
+ # Defines the logger used for debugging.
51
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
52
+ #
53
+ # @return [#debug]
54
+ attr_accessor :logger
55
+
56
+ # Defines the temporary folder to store downloaded files
57
+ # (for API endpoints that have file response).
58
+ # Default to use `Tempfile`.
59
+ #
60
+ # @return [String]
61
+ attr_accessor :temp_folder_path
62
+
63
+ # The time limit for HTTP request in seconds.
64
+ # Default to 0 (never times out).
65
+ attr_accessor :timeout
66
+
67
+ ### TLS/SSL
68
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
69
+ # Default to true.
70
+ #
71
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
72
+ #
73
+ # @return [true, false]
74
+ attr_accessor :verify_ssl
75
+
76
+ # Set this to customize the certificate file to verify the peer.
77
+ #
78
+ # @return [String] the path to the certificate file
79
+ #
80
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
81
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
82
+ attr_accessor :ssl_ca_cert
83
+
84
+ # Client certificate file (for client certificate)
85
+ attr_accessor :cert_file
86
+
87
+ # Client private key file (for client certificate)
88
+ attr_accessor :key_file
89
+
90
+ attr_accessor :inject_format
91
+
92
+ attr_accessor :force_ending_format
93
+
94
+ def initialize
95
+ @scheme = 'http'
96
+ @host = 'localhost:10010'
97
+ @base_path = '/1'
98
+ @api_key = {}
99
+ @api_key_prefix = {}
100
+ @timeout = 0
101
+ @verify_ssl = true
102
+ @cert_file = nil
103
+ @key_file = nil
104
+ @debugging = false
105
+ @inject_format = false
106
+ @force_ending_format = false
107
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
108
+
109
+ yield(self) if block_given?
110
+ end
111
+
112
+ # The default Configuration object.
113
+ def self.default
114
+ @@default ||= Configuration.new
115
+ end
116
+
117
+ def configure
118
+ yield(self) if block_given?
119
+ end
120
+
121
+ def scheme=(scheme)
122
+ # remove :// from scheme
123
+ @scheme = scheme.sub(/:\/\//, '')
124
+ end
125
+
126
+ def host=(host)
127
+ # remove http(s):// and anything after a slash
128
+ @host = host.sub(/https?:\/\//, '').split('/').first
129
+ end
130
+
131
+ def base_path=(base_path)
132
+ # Add leading and trailing slashes to base_path
133
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
134
+ @base_path = "" if @base_path == "/"
135
+ end
136
+
137
+ def base_url
138
+ url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
139
+ URI.encode(url)
140
+ end
141
+
142
+ # Gets API key (with prefix if set).
143
+ # @param [String] param_name the parameter name of API key auth
144
+ def api_key_with_prefix(param_name)
145
+ if @api_key_prefix[param_name]
146
+ "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
147
+ else
148
+ @api_key[param_name]
149
+ end
150
+ end
151
+
152
+ # Gets Basic Auth token string
153
+ def basic_auth_token
154
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
155
+ end
156
+
157
+ # Returns Auth Settings hash for api client.
158
+ def auth_settings
159
+ {
160
+ 'oauth2' =>
161
+ {
162
+ type: 'oauth2',
163
+ in: 'header',
164
+ key: 'Authorization',
165
+ value: "Bearer #{access_token}"
166
+ },
167
+ }
168
+ end
169
+ end
170
+ end