metatron_ruby_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +140 -0
  3. data/config.json +13 -0
  4. data/docs/Asset.md +9 -0
  5. data/docs/AssetAttributes.md +8 -0
  6. data/docs/AssetData.md +10 -0
  7. data/docs/AssetMeta.md +8 -0
  8. data/docs/AssetResultSet.md +10 -0
  9. data/docs/AssetResultSetMeta.md +8 -0
  10. data/docs/DefaultApi.md +631 -0
  11. data/docs/Error.md +10 -0
  12. data/docs/Errors.md +8 -0
  13. data/docs/Item.md +9 -0
  14. data/docs/ItemData.md +8 -0
  15. data/docs/ItemResultSet.md +10 -0
  16. data/docs/Links.md +10 -0
  17. data/docs/Manifestation.md +9 -0
  18. data/docs/ManifestationAttributes.md +11 -0
  19. data/docs/ManifestationData.md +11 -0
  20. data/docs/ManifestationRelationships.md +10 -0
  21. data/docs/ManifestationResultSet.md +10 -0
  22. data/docs/Meta.md +10 -0
  23. data/docs/OneToManyRelationship.md +10 -0
  24. data/docs/OneToOneRelationship.md +10 -0
  25. data/docs/Resource.md +10 -0
  26. data/docs/ResourceData.md +11 -0
  27. data/docs/ResourceLink.md +9 -0
  28. data/docs/ResultSetMeta.md +10 -0
  29. data/docs/Work.md +9 -0
  30. data/docs/WorkAttributes.md +8 -0
  31. data/docs/WorkData.md +11 -0
  32. data/docs/WorkRelationships.md +8 -0
  33. data/docs/WorkResultSet.md +11 -0
  34. data/generate.sh +0 -0
  35. data/git_push.sh +52 -0
  36. data/lib/metatron_ruby_client/api/default_api.rb +727 -0
  37. data/lib/metatron_ruby_client/api_client.rb +361 -0
  38. data/lib/metatron_ruby_client/api_error.rb +34 -0
  39. data/lib/metatron_ruby_client/configuration.rb +170 -0
  40. data/lib/metatron_ruby_client/models/asset.rb +195 -0
  41. data/lib/metatron_ruby_client/models/asset_attributes.rb +212 -0
  42. data/lib/metatron_ruby_client/models/asset_data.rb +208 -0
  43. data/lib/metatron_ruby_client/models/asset_meta.rb +198 -0
  44. data/lib/metatron_ruby_client/models/asset_result_set.rb +202 -0
  45. data/lib/metatron_ruby_client/models/asset_result_set_meta.rb +196 -0
  46. data/lib/metatron_ruby_client/models/error.rb +208 -0
  47. data/lib/metatron_ruby_client/models/errors.rb +184 -0
  48. data/lib/metatron_ruby_client/models/item.rb +197 -0
  49. data/lib/metatron_ruby_client/models/item_data.rb +186 -0
  50. data/lib/metatron_ruby_client/models/item_result_set.rb +206 -0
  51. data/lib/metatron_ruby_client/models/links.rb +204 -0
  52. data/lib/metatron_ruby_client/models/manifestation.rb +197 -0
  53. data/lib/metatron_ruby_client/models/manifestation_attributes.rb +209 -0
  54. data/lib/metatron_ruby_client/models/manifestation_data.rb +235 -0
  55. data/lib/metatron_ruby_client/models/manifestation_relationships.rb +200 -0
  56. data/lib/metatron_ruby_client/models/manifestation_result_set.rb +214 -0
  57. data/lib/metatron_ruby_client/models/meta.rb +260 -0
  58. data/lib/metatron_ruby_client/models/one_to_many_relationship.rb +206 -0
  59. data/lib/metatron_ruby_client/models/one_to_one_relationship.rb +204 -0
  60. data/lib/metatron_ruby_client/models/resource.rb +281 -0
  61. data/lib/metatron_ruby_client/models/resource_data.rb +221 -0
  62. data/lib/metatron_ruby_client/models/resource_link.rb +199 -0
  63. data/lib/metatron_ruby_client/models/result_set_meta.rb +203 -0
  64. data/lib/metatron_ruby_client/models/work.rb +197 -0
  65. data/lib/metatron_ruby_client/models/work_attributes.rb +186 -0
  66. data/lib/metatron_ruby_client/models/work_data.rb +235 -0
  67. data/lib/metatron_ruby_client/models/work_relationships.rb +182 -0
  68. data/lib/metatron_ruby_client/models/work_result_set.rb +213 -0
  69. data/lib/metatron_ruby_client/version.rb +13 -0
  70. data/lib/metatron_ruby_client.rb +60 -0
  71. data/metatron_ruby_client.gemspec +31 -0
  72. data/spec/api/default_api_spec.rb +218 -0
  73. data/spec/models/asset_attributes_spec.rb +46 -0
  74. data/spec/models/asset_data_spec.rb +66 -0
  75. data/spec/models/asset_meta_spec.rb +46 -0
  76. data/spec/models/asset_result_set_spec.rb +66 -0
  77. data/spec/models/asset_spec.rb +56 -0
  78. data/spec/models/error_spec.rb +66 -0
  79. data/spec/models/errors_spec.rb +46 -0
  80. data/spec/models/item_data_spec.rb +46 -0
  81. data/spec/models/item_result_set_spec.rb +66 -0
  82. data/spec/models/item_spec.rb +56 -0
  83. data/spec/models/links_spec.rb +66 -0
  84. data/spec/models/manifestation_attributes_spec.rb +76 -0
  85. data/spec/models/manifestation_data_spec.rb +76 -0
  86. data/spec/models/manifestation_relationships_spec.rb +66 -0
  87. data/spec/models/manifestation_result_set_spec.rb +66 -0
  88. data/spec/models/manifestation_spec.rb +56 -0
  89. data/spec/models/meta_spec.rb +66 -0
  90. data/spec/models/one_to_many_relationship_spec.rb +66 -0
  91. data/spec/models/one_to_one_relationship_spec.rb +66 -0
  92. data/spec/models/resource_data_spec.rb +76 -0
  93. data/spec/models/resource_link_spec.rb +56 -0
  94. data/spec/models/resource_spec.rb +66 -0
  95. data/spec/models/result_set_meta_spec.rb +66 -0
  96. data/spec/models/work_attributes_spec.rb +46 -0
  97. data/spec/models/work_data_spec.rb +76 -0
  98. data/spec/models/work_relationships_spec.rb +46 -0
  99. data/spec/models/work_result_set_spec.rb +76 -0
  100. data/spec/models/work_spec.rb +56 -0
  101. data/stub-service/.swagger-codegen-ignore +23 -0
  102. data/stub-service/Gemfile +4 -0
  103. data/stub-service/Gemfile.lock +22 -0
  104. data/stub-service/LICENSE +201 -0
  105. data/stub-service/README.md +29 -0
  106. data/stub-service/api/default_api.rb +370 -0
  107. data/stub-service/config.ru +2 -0
  108. data/stub-service/lib/result_set.rb +37 -0
  109. data/stub-service/lib/swaggering.rb +163 -0
  110. data/stub-service/my_app.rb +13 -0
  111. data/stub-service/responses/works/includes/manifestations.assets.yaml +42 -0
  112. data/stub-service/responses/works/includes/manifestations.yaml +88 -0
  113. data/stub-service/responses/works/result_set.yaml +18 -0
  114. data/stub-service/swagger.yaml +756 -0
  115. data/swagger-codegen-cli.jar +0 -0
  116. metadata +369 -0
@@ -0,0 +1,361 @@
1
+ =begin
2
+ production-metatron-api
3
+
4
+ OpenAPI spec version: 2016-07-15T09:42:29Z
5
+
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+
9
+ =end
10
+
11
+ require 'date'
12
+ require 'json'
13
+ require 'logger'
14
+ require 'tempfile'
15
+ require 'typhoeus'
16
+ require 'uri'
17
+
18
+ module MetatronClient
19
+ class ApiClient
20
+ # The Configuration object holding settings to be used in the API client.
21
+ attr_accessor :config
22
+
23
+ # Defines the headers to be used in HTTP requests of all API calls by default.
24
+ #
25
+ # @return [Hash]
26
+ attr_accessor :default_headers
27
+
28
+ # Initializes the ApiClient
29
+ # @option config [Configuration] Configuraiton for initializing the object, default to Configuration.default
30
+ def initialize(config = Configuration.default)
31
+ @config = config
32
+ @user_agent = "metatron_ruby_client/#{VERSION} ruby/#{RUBY_VERSION}"
33
+ @default_headers = {
34
+ 'Content-Type' => "application/json",
35
+ 'User-Agent' => @user_agent
36
+ }
37
+ end
38
+
39
+ def self.default
40
+ @@default ||= ApiClient.new
41
+ end
42
+
43
+ # Call an API with given options.
44
+ #
45
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
46
+ # the data deserialized from response body (could be nil), response status code and response headers.
47
+ def call_api(http_method, path, opts = {})
48
+ request = build_request(http_method, path, opts)
49
+ response = request.run
50
+
51
+ if @config.debugging
52
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
53
+ end
54
+
55
+ unless response.success?
56
+ fail ApiError.new(:code => response.code,
57
+ :response_headers => response.headers,
58
+ :response_body => response.body),
59
+ response.status_message
60
+ end
61
+
62
+ if opts[:return_type]
63
+ data = deserialize(response, opts[:return_type])
64
+ else
65
+ data = nil
66
+ end
67
+ return data, response.code, response.headers
68
+ end
69
+
70
+ # Builds the HTTP request
71
+ #
72
+ # @param [String] http_method HTTP method/verb (e.g. POST)
73
+ # @param [String] path URL path (e.g. /account/new)
74
+ # @option opts [Hash] :header_params Header parameters
75
+ # @option opts [Hash] :query_params Query parameters
76
+ # @option opts [Hash] :form_params Query parameters
77
+ # @option opts [Object] :body HTTP body (JSON/XML)
78
+ # @return [Typhoeus::Request] A Typhoeus Request
79
+ def build_request(http_method, path, opts = {})
80
+ url = build_request_url(path)
81
+ http_method = http_method.to_sym.downcase
82
+
83
+ header_params = @default_headers.merge(opts[:header_params] || {})
84
+ query_params = opts[:query_params] || {}
85
+ form_params = opts[:form_params] || {}
86
+
87
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
88
+
89
+ req_opts = {
90
+ :method => http_method,
91
+ :headers => header_params,
92
+ :params => query_params,
93
+ :timeout => @config.timeout,
94
+ :ssl_verifypeer => @config.verify_ssl,
95
+ :sslcert => @config.cert_file,
96
+ :sslkey => @config.key_file,
97
+ :verbose => @config.debugging
98
+ }
99
+
100
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
101
+
102
+ if [:post, :patch, :put, :delete].include?(http_method)
103
+ req_body = build_request_body(header_params, form_params, opts[:body])
104
+ req_opts.update :body => req_body
105
+ if @config.debugging
106
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
107
+ end
108
+ end
109
+
110
+ Typhoeus::Request.new(url, req_opts)
111
+ end
112
+
113
+ # Check if the given MIME is a JSON MIME.
114
+ # JSON MIME examples:
115
+ # application/json
116
+ # application/vnd.api+json
117
+ # application/json; charset=UTF8
118
+ # APPLICATION/JSON
119
+ # @param [String] mime MIME
120
+ # @return [Boolean] True if the MIME is applicaton/json
121
+ def json_mime?(mime)
122
+ !(mime =~ /\Aapplication\/(vnd\.api\+)?json(;.*)?\z/i).nil?
123
+ end
124
+
125
+ # Deserialize the response to the given return type.
126
+ #
127
+ # @param [Response] response HTTP response
128
+ # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
129
+ def deserialize(response, return_type)
130
+ body = response.body
131
+ return nil if body.nil? || body.empty?
132
+
133
+ # return response body directly for String return type
134
+ return body if return_type == 'String'
135
+
136
+ # handle file downloading - save response body into a tmp file and return the File instance
137
+ return download_file(response) if return_type == 'File'
138
+
139
+ # ensuring a default content type
140
+ content_type = response.headers['Content-Type'] || 'application/json'
141
+
142
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
143
+
144
+ begin
145
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
146
+ rescue JSON::ParserError => e
147
+ if %w(String Date DateTime).include?(return_type)
148
+ data = body
149
+ else
150
+ raise e
151
+ end
152
+ end
153
+
154
+ convert_to_type data, return_type
155
+ end
156
+
157
+ # Convert data to the given return type.
158
+ # @param [Object] data Data to be converted
159
+ # @param [String] return_type Return type
160
+ # @return [Mixed] Data in a particular type
161
+ def convert_to_type(data, return_type)
162
+ return nil if data.nil?
163
+ case return_type
164
+ when 'String'
165
+ data.to_s
166
+ when 'Integer'
167
+ data.to_i
168
+ when 'Float'
169
+ data.to_f
170
+ when 'BOOLEAN'
171
+ data == true
172
+ when 'DateTime'
173
+ # parse date time (expecting ISO 8601 format)
174
+ DateTime.parse data
175
+ when 'Date'
176
+ # parse date time (expecting ISO 8601 format)
177
+ Date.parse data
178
+ when 'Object'
179
+ # generic object (usually a Hash), return directly
180
+ data
181
+ when /\AArray<(.+)>\z/
182
+ # e.g. Array<Pet>
183
+ sub_type = $1
184
+ data.map {|item| convert_to_type(item, sub_type) }
185
+ when /\AHash\<String, (.+)\>\z/
186
+ # e.g. Hash<String, Integer>
187
+ sub_type = $1
188
+ {}.tap do |hash|
189
+ data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
190
+ end
191
+ else
192
+ # models, e.g. Pet
193
+ MetatronClient.const_get(return_type).new.tap do |model|
194
+ model.build_from_hash data
195
+ end
196
+ end
197
+ end
198
+
199
+ # Save response body into a file in (the defined) temporary folder, using the filename
200
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
201
+ #
202
+ # @see Configuration#temp_folder_path
203
+ # @return [Tempfile] the file downloaded
204
+ def download_file(response)
205
+ content_disposition = response.headers['Content-Disposition']
206
+ if content_disposition
207
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
208
+ prefix = sanitize_filename(filename)
209
+ else
210
+ prefix = 'download-'
211
+ end
212
+ prefix = prefix + '-' unless prefix.end_with?('-')
213
+
214
+ tempfile = nil
215
+ encoding = response.body.encoding
216
+ Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) do |file|
217
+ file.write(response.body)
218
+ tempfile = file
219
+ end
220
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
221
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
222
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
223
+ "explicitly with `tempfile.delete`"
224
+ tempfile
225
+ end
226
+
227
+ # Sanitize filename by removing path.
228
+ # e.g. ../../sun.gif becomes sun.gif
229
+ #
230
+ # @param [String] filename the filename to be sanitized
231
+ # @return [String] the sanitized filename
232
+ def sanitize_filename(filename)
233
+ filename.gsub(/.*[\/\\]/, '')
234
+ end
235
+
236
+ def build_request_url(path)
237
+ # Add leading and trailing slashes to path
238
+ path = "/#{path}".gsub(/\/+/, '/')
239
+ URI.encode(@config.base_url + path)
240
+ end
241
+
242
+ # Builds the HTTP request body
243
+ #
244
+ # @param [Hash] header_params Header parameters
245
+ # @param [Hash] form_params Query parameters
246
+ # @param [Object] body HTTP body (JSON/XML)
247
+ # @return [String] HTTP body data in the form of string
248
+ def build_request_body(header_params, form_params, body)
249
+ # http form
250
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
251
+ header_params['Content-Type'] == 'multipart/form-data'
252
+ data = {}
253
+ form_params.each do |key, value|
254
+ case value
255
+ when File, Array, nil
256
+ # let typhoeus handle File, Array and nil parameters
257
+ data[key] = value
258
+ else
259
+ data[key] = value.to_s
260
+ end
261
+ end
262
+ elsif body
263
+ data = body.is_a?(String) ? body : body.to_json
264
+ else
265
+ data = nil
266
+ end
267
+ data
268
+ end
269
+
270
+ # Update hearder and query params based on authentication settings.
271
+ #
272
+ # @param [Hash] header_params Header parameters
273
+ # @param [Hash] form_params Query parameters
274
+ # @param [String] auth_names Authentication scheme name
275
+ def update_params_for_auth!(header_params, query_params, auth_names)
276
+ Array(auth_names).each do |auth_name|
277
+ auth_setting = @config.auth_settings[auth_name]
278
+ next unless auth_setting
279
+ case auth_setting[:in]
280
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
281
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
282
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
283
+ end
284
+ end
285
+ end
286
+
287
+ # Sets user agent in HTTP header
288
+ #
289
+ # @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
290
+ def user_agent=(user_agent)
291
+ @user_agent = user_agent
292
+ @default_headers['User-Agent'] = @user_agent
293
+ end
294
+
295
+ # Return Accept header based on an array of accepts provided.
296
+ # @param [Array] accepts array for Accept
297
+ # @return [String] the Accept header (e.g. application/json)
298
+ def select_header_accept(accepts)
299
+ return nil if accepts.nil? || accepts.empty?
300
+ # use JSON when present, otherwise use all of the provided
301
+ json_accept = accepts.find { |s| json_mime?(s) }
302
+ return json_accept || accepts.join(',')
303
+ end
304
+
305
+ # Return Content-Type header based on an array of content types provided.
306
+ # @param [Array] content_types array for Content-Type
307
+ # @return [String] the Content-Type header (e.g. application/json)
308
+ def select_header_content_type(content_types)
309
+ # use application/json by default
310
+ return 'application/json' if content_types.nil? || content_types.empty?
311
+ # use JSON when present, otherwise use the first one
312
+ json_content_type = content_types.find { |s| json_mime?(s) }
313
+ return json_content_type || content_types.first
314
+ end
315
+
316
+ # Convert object (array, hash, object, etc) to JSON string.
317
+ # @param [Object] model object to be converted into JSON string
318
+ # @return [String] JSON string representation of the object
319
+ def object_to_http_body(model)
320
+ return model if model.nil? || model.is_a?(String)
321
+ local_body = nil
322
+ if model.is_a?(Array)
323
+ local_body = model.map{|m| object_to_hash(m) }
324
+ else
325
+ local_body = object_to_hash(model)
326
+ end
327
+ local_body.to_json
328
+ end
329
+
330
+ # Convert object(non-array) to hash.
331
+ # @param [Object] obj object to be converted into JSON string
332
+ # @return [String] JSON string representation of the object
333
+ def object_to_hash(obj)
334
+ if obj.respond_to?(:to_hash)
335
+ obj.to_hash
336
+ else
337
+ obj
338
+ end
339
+ end
340
+
341
+ # Build parameter value according to the given collection format.
342
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
343
+ def build_collection_param(param, collection_format)
344
+ case collection_format
345
+ when :csv
346
+ param.join(',')
347
+ when :ssv
348
+ param.join(' ')
349
+ when :tsv
350
+ param.join("\t")
351
+ when :pipes
352
+ param.join('|')
353
+ when :multi
354
+ # return the array directly as typhoeus will handle it as expected
355
+ param
356
+ else
357
+ fail "unknown collection format: #{collection_format.inspect}"
358
+ end
359
+ end
360
+ end
361
+ end
@@ -0,0 +1,34 @@
1
+ =begin
2
+ production-metatron-api
3
+
4
+ OpenAPI spec version: 2016-07-15T09:42:29Z
5
+
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+
9
+ =end
10
+
11
+ module MetatronClient
12
+ class ApiError < StandardError
13
+ attr_reader :code, :response_headers, :response_body
14
+
15
+ # Usage examples:
16
+ # ApiError.new
17
+ # ApiError.new("message")
18
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
19
+ # ApiError.new(:code => 404, :message => "Not Found")
20
+ def initialize(arg = nil)
21
+ if arg.is_a? Hash
22
+ arg.each do |k, v|
23
+ if k.to_s == 'message'
24
+ super v
25
+ else
26
+ instance_variable_set "@#{k}", v
27
+ end
28
+ end
29
+ else
30
+ super arg
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,170 @@
1
+ require 'uri'
2
+
3
+ module MetatronClient
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 = 'https'
96
+ @host = 'bibliography.talis.com'
97
+ @base_path = ''
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
+ 'Authorizer' =>
161
+ {
162
+ type: 'api_key',
163
+ in: 'header',
164
+ key: 'Authorization',
165
+ value: api_key_with_prefix('Authorization')
166
+ },
167
+ }
168
+ end
169
+ end
170
+ end