pulp_hugging_face_client 0.0.1

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 (126) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/README.md +176 -0
  4. data/Rakefile +10 -0
  5. data/docs/AsyncOperationResponse.md +18 -0
  6. data/docs/ContentHuggingFaceApi.md +424 -0
  7. data/docs/ContentSummaryResponse.md +22 -0
  8. data/docs/DistributionsHuggingFaceApi.md +671 -0
  9. data/docs/HuggingFaceHuggingFaceContent.md +36 -0
  10. data/docs/HuggingFaceHuggingFaceContentResponse.md +42 -0
  11. data/docs/HuggingFaceHuggingFaceDistribution.md +32 -0
  12. data/docs/HuggingFaceHuggingFaceDistributionResponse.md +44 -0
  13. data/docs/HuggingFaceHuggingFacePublication.md +20 -0
  14. data/docs/HuggingFaceHuggingFacePublicationResponse.md +28 -0
  15. data/docs/HuggingFaceHuggingFaceRemote.md +62 -0
  16. data/docs/HuggingFaceHuggingFaceRemoteResponse.md +62 -0
  17. data/docs/HuggingFaceHuggingFaceRemoteResponseHiddenFieldsInner.md +20 -0
  18. data/docs/HuggingFaceHuggingFaceRepository.md +26 -0
  19. data/docs/HuggingFaceHuggingFaceRepositoryResponse.md +38 -0
  20. data/docs/PaginatedRepositoryVersionResponseList.md +24 -0
  21. data/docs/PaginatedhuggingFaceHuggingFaceContentResponseList.md +24 -0
  22. data/docs/PaginatedhuggingFaceHuggingFaceDistributionResponseList.md +24 -0
  23. data/docs/PaginatedhuggingFaceHuggingFacePublicationResponseList.md +24 -0
  24. data/docs/PaginatedhuggingFaceHuggingFaceRemoteResponseList.md +24 -0
  25. data/docs/PaginatedhuggingFaceHuggingFaceRepositoryResponseList.md +24 -0
  26. data/docs/PatchedhuggingFaceHuggingFaceDistribution.md +32 -0
  27. data/docs/PatchedhuggingFaceHuggingFaceRemote.md +62 -0
  28. data/docs/PatchedhuggingFaceHuggingFaceRepository.md +26 -0
  29. data/docs/PolicyEnum.md +15 -0
  30. data/docs/PublicationsHuggingFaceApi.md +350 -0
  31. data/docs/RemotesHuggingFaceApi.md +669 -0
  32. data/docs/Repair.md +18 -0
  33. data/docs/RepoTypeEnum.md +15 -0
  34. data/docs/RepositoriesHuggingFaceApi.md +831 -0
  35. data/docs/RepositoriesHuggingFaceVersionsApi.md +359 -0
  36. data/docs/RepositoryAddRemoveContent.md +22 -0
  37. data/docs/RepositorySyncURL.md +20 -0
  38. data/docs/RepositoryVersionResponse.md +32 -0
  39. data/docs/SetLabel.md +20 -0
  40. data/docs/SetLabelResponse.md +20 -0
  41. data/docs/UnsetLabel.md +18 -0
  42. data/docs/UnsetLabelResponse.md +20 -0
  43. data/lib/pulp_hugging_face_client/api/content_hugging_face_api.rb +441 -0
  44. data/lib/pulp_hugging_face_client/api/distributions_hugging_face_api.rb +684 -0
  45. data/lib/pulp_hugging_face_client/api/publications_hugging_face_api.rb +356 -0
  46. data/lib/pulp_hugging_face_client/api/remotes_hugging_face_api.rb +681 -0
  47. data/lib/pulp_hugging_face_client/api/repositories_hugging_face_api.rb +847 -0
  48. data/lib/pulp_hugging_face_client/api/repositories_hugging_face_versions_api.rb +374 -0
  49. data/lib/pulp_hugging_face_client/api_client.rb +438 -0
  50. data/lib/pulp_hugging_face_client/api_error.rb +58 -0
  51. data/lib/pulp_hugging_face_client/configuration.rb +392 -0
  52. data/lib/pulp_hugging_face_client/models/async_operation_response.rb +223 -0
  53. data/lib/pulp_hugging_face_client/models/content_summary_response.rb +260 -0
  54. data/lib/pulp_hugging_face_client/models/hugging_face_hugging_face_content.rb +428 -0
  55. data/lib/pulp_hugging_face_client/models/hugging_face_hugging_face_content_response.rb +385 -0
  56. data/lib/pulp_hugging_face_client/models/hugging_face_hugging_face_distribution.rb +345 -0
  57. data/lib/pulp_hugging_face_client/models/hugging_face_hugging_face_distribution_response.rb +366 -0
  58. data/lib/pulp_hugging_face_client/models/hugging_face_hugging_face_publication.rb +225 -0
  59. data/lib/pulp_hugging_face_client/models/hugging_face_hugging_face_publication_response.rb +264 -0
  60. data/lib/pulp_hugging_face_client/models/hugging_face_hugging_face_remote.rb +745 -0
  61. data/lib/pulp_hugging_face_client/models/hugging_face_hugging_face_remote_response.rb +564 -0
  62. data/lib/pulp_hugging_face_client/models/hugging_face_hugging_face_remote_response_hidden_fields_inner.rb +237 -0
  63. data/lib/pulp_hugging_face_client/models/hugging_face_hugging_face_repository.rb +316 -0
  64. data/lib/pulp_hugging_face_client/models/hugging_face_hugging_face_repository_response.rb +339 -0
  65. data/lib/pulp_hugging_face_client/models/paginated_repository_version_response_list.rb +259 -0
  66. data/lib/pulp_hugging_face_client/models/paginatedhugging_face_hugging_face_content_response_list.rb +259 -0
  67. data/lib/pulp_hugging_face_client/models/paginatedhugging_face_hugging_face_distribution_response_list.rb +259 -0
  68. data/lib/pulp_hugging_face_client/models/paginatedhugging_face_hugging_face_publication_response_list.rb +259 -0
  69. data/lib/pulp_hugging_face_client/models/paginatedhugging_face_hugging_face_remote_response_list.rb +259 -0
  70. data/lib/pulp_hugging_face_client/models/paginatedhugging_face_hugging_face_repository_response_list.rb +259 -0
  71. data/lib/pulp_hugging_face_client/models/patchedhugging_face_hugging_face_distribution.rb +331 -0
  72. data/lib/pulp_hugging_face_client/models/patchedhugging_face_hugging_face_remote.rb +731 -0
  73. data/lib/pulp_hugging_face_client/models/patchedhugging_face_hugging_face_repository.rb +309 -0
  74. data/lib/pulp_hugging_face_client/models/policy_enum.rb +41 -0
  75. data/lib/pulp_hugging_face_client/models/repair.rb +217 -0
  76. data/lib/pulp_hugging_face_client/models/repo_type_enum.rb +41 -0
  77. data/lib/pulp_hugging_face_client/models/repository_add_remove_content.rb +240 -0
  78. data/lib/pulp_hugging_face_client/models/repository_sync_url.rb +228 -0
  79. data/lib/pulp_hugging_face_client/models/repository_version_response.rb +283 -0
  80. data/lib/pulp_hugging_face_client/models/set_label.rb +264 -0
  81. data/lib/pulp_hugging_face_client/models/set_label_response.rb +255 -0
  82. data/lib/pulp_hugging_face_client/models/unset_label.rb +252 -0
  83. data/lib/pulp_hugging_face_client/models/unset_label_response.rb +252 -0
  84. data/lib/pulp_hugging_face_client/version.rb +15 -0
  85. data/lib/pulp_hugging_face_client.rb +77 -0
  86. data/pulp_hugging_face_client.gemspec +41 -0
  87. data/spec/api/content_hugging_face_api_spec.rb +121 -0
  88. data/spec/api/distributions_hugging_face_api_spec.rb +171 -0
  89. data/spec/api/publications_hugging_face_api_spec.rb +109 -0
  90. data/spec/api/remotes_hugging_face_api_spec.rb +170 -0
  91. data/spec/api/repositories_hugging_face_api_spec.rb +202 -0
  92. data/spec/api/repositories_hugging_face_versions_api_spec.rb +112 -0
  93. data/spec/models/async_operation_response_spec.rb +36 -0
  94. data/spec/models/content_summary_response_spec.rb +48 -0
  95. data/spec/models/hugging_face_hugging_face_content_response_spec.rb +108 -0
  96. data/spec/models/hugging_face_hugging_face_content_spec.rb +90 -0
  97. data/spec/models/hugging_face_hugging_face_distribution_response_spec.rb +114 -0
  98. data/spec/models/hugging_face_hugging_face_distribution_spec.rb +78 -0
  99. data/spec/models/hugging_face_hugging_face_publication_response_spec.rb +66 -0
  100. data/spec/models/hugging_face_hugging_face_publication_spec.rb +42 -0
  101. data/spec/models/hugging_face_hugging_face_remote_response_hidden_fields_inner_spec.rb +42 -0
  102. data/spec/models/hugging_face_hugging_face_remote_response_spec.rb +168 -0
  103. data/spec/models/hugging_face_hugging_face_remote_spec.rb +168 -0
  104. data/spec/models/hugging_face_hugging_face_repository_response_spec.rb +96 -0
  105. data/spec/models/hugging_face_hugging_face_repository_spec.rb +60 -0
  106. data/spec/models/paginated_repository_version_response_list_spec.rb +54 -0
  107. data/spec/models/paginatedhugging_face_hugging_face_content_response_list_spec.rb +54 -0
  108. data/spec/models/paginatedhugging_face_hugging_face_distribution_response_list_spec.rb +54 -0
  109. data/spec/models/paginatedhugging_face_hugging_face_publication_response_list_spec.rb +54 -0
  110. data/spec/models/paginatedhugging_face_hugging_face_remote_response_list_spec.rb +54 -0
  111. data/spec/models/paginatedhugging_face_hugging_face_repository_response_list_spec.rb +54 -0
  112. data/spec/models/patchedhugging_face_hugging_face_distribution_spec.rb +78 -0
  113. data/spec/models/patchedhugging_face_hugging_face_remote_spec.rb +168 -0
  114. data/spec/models/patchedhugging_face_hugging_face_repository_spec.rb +60 -0
  115. data/spec/models/policy_enum_spec.rb +30 -0
  116. data/spec/models/repair_spec.rb +36 -0
  117. data/spec/models/repo_type_enum_spec.rb +30 -0
  118. data/spec/models/repository_add_remove_content_spec.rb +48 -0
  119. data/spec/models/repository_sync_url_spec.rb +42 -0
  120. data/spec/models/repository_version_response_spec.rb +78 -0
  121. data/spec/models/set_label_response_spec.rb +42 -0
  122. data/spec/models/set_label_spec.rb +42 -0
  123. data/spec/models/unset_label_response_spec.rb +42 -0
  124. data/spec/models/unset_label_spec.rb +36 -0
  125. data/spec/spec_helper.rb +111 -0
  126. metadata +274 -0
@@ -0,0 +1,438 @@
1
+ =begin
2
+ #Pulp 3 API
3
+
4
+ #Fetch, Upload, Organize, and Distribute Software Packages
5
+
6
+ The version of the OpenAPI document: v3
7
+ Contact: pulp-list@redhat.com
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.10.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'json'
15
+ require 'logger'
16
+ require 'tempfile'
17
+ require 'time'
18
+ require 'faraday'
19
+ require 'faraday/multipart' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
20
+ require 'marcel'
21
+ require 'pathname'
22
+
23
+
24
+ module PulpHuggingFaceClient
25
+ class ApiClient
26
+ # The Configuration object holding settings to be used in the API client.
27
+ attr_accessor :config
28
+
29
+ # Defines the headers to be used in HTTP requests of all API calls by default.
30
+ #
31
+ # @return [Hash]
32
+ attr_accessor :default_headers
33
+
34
+ # Initializes the ApiClient
35
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
36
+ def initialize(config = Configuration.default)
37
+ @config = config
38
+ @user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
39
+ @default_headers = {
40
+ 'Content-Type' => 'application/json',
41
+ 'User-Agent' => @user_agent
42
+ }
43
+ end
44
+
45
+ def self.default
46
+ @@default ||= ApiClient.new
47
+ end
48
+
49
+ # Call an API with given options.
50
+ #
51
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
52
+ # the data deserialized from response body (could be nil), response status code and response headers.
53
+ def call_api(http_method, path, opts = {})
54
+ stream = nil
55
+ begin
56
+ response = connection(opts).public_send(http_method.to_sym.downcase) do |req|
57
+ request = build_request(http_method, path, req, opts)
58
+ stream = download_file(request) if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
59
+ end
60
+
61
+ if config.debugging
62
+ config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
63
+ end
64
+
65
+ unless response.success?
66
+ if response.status == 0 && response.respond_to?(:return_message)
67
+ # Errors from libcurl will be made visible here
68
+ fail ApiError.new(code: 0,
69
+ message: response.return_message)
70
+ else
71
+ fail ApiError.new(code: response.status,
72
+ response_headers: response.headers,
73
+ response_body: response.body),
74
+ response.reason_phrase
75
+ end
76
+ end
77
+ rescue Faraday::TimeoutError
78
+ fail ApiError.new('Connection timed out')
79
+ rescue Faraday::ConnectionFailed
80
+ fail ApiError.new('Connection failed')
81
+ end
82
+
83
+ if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
84
+ data = deserialize_file(response, stream)
85
+ elsif opts[:return_type]
86
+ data = deserialize(response, opts[:return_type])
87
+ else
88
+ data = nil
89
+ end
90
+ return data, response.status, response.headers
91
+ end
92
+
93
+ # Builds the HTTP request
94
+ #
95
+ # @param [String] http_method HTTP method/verb (e.g. POST)
96
+ # @param [String] path URL path (e.g. /account/new)
97
+ # @option opts [Hash] :header_params Header parameters
98
+ # @option opts [Hash] :query_params Query parameters
99
+ # @option opts [Hash] :form_params Query parameters
100
+ # @option opts [Object] :body HTTP body (JSON/XML)
101
+ # @return [Faraday::Request] A Faraday Request
102
+ def build_request(http_method, path, request, opts = {})
103
+ url = build_request_url(path, opts)
104
+ http_method = http_method.to_sym.downcase
105
+
106
+ header_params = @default_headers.merge(opts[:header_params] || {})
107
+ query_params = opts[:query_params] || {}
108
+ form_params = opts[:form_params] || {}
109
+
110
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
111
+
112
+ if [:post, :patch, :put, :delete].include?(http_method)
113
+ req_body = build_request_body(header_params, form_params, opts[:body])
114
+ if config.debugging
115
+ config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
116
+ end
117
+ end
118
+ request.headers = header_params
119
+ request.body = req_body
120
+
121
+ # Overload default options only if provided
122
+ request.options.params_encoder = config.params_encoder if config.params_encoder
123
+ request.options.timeout = config.timeout if config.timeout
124
+
125
+ request.url url
126
+ request.params = query_params
127
+ request
128
+ end
129
+
130
+ # Builds the HTTP request body
131
+ #
132
+ # @param [Hash] header_params Header parameters
133
+ # @param [Hash] form_params Query parameters
134
+ # @param [Object] body HTTP body (JSON/XML)
135
+ # @return [String] HTTP body data in the form of string
136
+ def build_request_body(header_params, form_params, body)
137
+ # http form
138
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
139
+ data = URI.encode_www_form(form_params)
140
+ elsif header_params['Content-Type'] == 'multipart/form-data'
141
+ data = {}
142
+ form_params.each do |key, value|
143
+ case value
144
+ when ::File, ::Tempfile
145
+ data[key] = Faraday::FilePart.new(value.path, Marcel::MimeType.for(Pathname.new(value.path)))
146
+ when ::Array, nil
147
+ # let Faraday handle Array and nil parameters
148
+ data[key] = value
149
+ else
150
+ data[key] = value.to_s
151
+ end
152
+ end
153
+ elsif body
154
+ data = body.is_a?(String) ? body : body.to_json
155
+ else
156
+ data = nil
157
+ end
158
+ data
159
+ end
160
+
161
+ def download_file(request)
162
+ stream = []
163
+
164
+ # handle streaming Responses
165
+ request.options.on_data = Proc.new do |chunk, overall_received_bytes|
166
+ stream << chunk
167
+ end
168
+
169
+ stream
170
+ end
171
+
172
+ def deserialize_file(response, stream)
173
+ body = response.body
174
+ encoding = body.encoding
175
+
176
+ # reconstruct content
177
+ content = stream.join
178
+ content = content.unpack('m').join if response.headers['Content-Transfer-Encoding'] == 'binary'
179
+ content = content.force_encoding(encoding)
180
+
181
+ # return byte stream
182
+ return content if @config.return_binary_data == true
183
+
184
+ # return file instead of binary data
185
+ content_disposition = response.headers['Content-Disposition']
186
+ if content_disposition && content_disposition =~ /filename=/i
187
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
188
+ prefix = sanitize_filename(filename)
189
+ else
190
+ prefix = 'download-'
191
+ end
192
+ prefix = prefix + '-' unless prefix.end_with?('-')
193
+
194
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
195
+ tempfile.write(content)
196
+ tempfile.close
197
+
198
+ config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
199
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
200
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
201
+ "explicitly with `tempfile.delete`"
202
+ tempfile
203
+ end
204
+
205
+ def connection(opts)
206
+ opts[:header_params]['Content-Type'] == 'multipart/form-data' ? connection_multipart : connection_regular
207
+ end
208
+
209
+ def connection_multipart
210
+ @connection_multipart ||= build_connection do |conn|
211
+ conn.request :multipart
212
+ conn.request :url_encoded
213
+ end
214
+ end
215
+
216
+ def connection_regular
217
+ @connection_regular ||= build_connection
218
+ end
219
+
220
+ def build_connection
221
+ Faraday.new(url: config.base_url, ssl: ssl_options, proxy: config.proxy) do |conn|
222
+ basic_auth(conn)
223
+ config.configure_middleware(conn)
224
+ yield(conn) if block_given?
225
+ conn.adapter(Faraday.default_adapter)
226
+ config.configure_connection(conn)
227
+ end
228
+ end
229
+
230
+ def ssl_options
231
+ {
232
+ ca_file: config.ssl_ca_file,
233
+ verify: config.ssl_verify,
234
+ verify_mode: config.ssl_verify_mode,
235
+ client_cert: config.ssl_client_cert,
236
+ client_key: config.ssl_client_key
237
+ }
238
+ end
239
+
240
+ def basic_auth(conn)
241
+ if config.username && config.password
242
+ if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
243
+ conn.request(:authorization, :basic, config.username, config.password)
244
+ else
245
+ conn.request(:basic_auth, config.username, config.password)
246
+ end
247
+ end
248
+ end
249
+
250
+ # Check if the given MIME is a JSON MIME.
251
+ # JSON MIME examples:
252
+ # application/json
253
+ # application/json; charset=UTF8
254
+ # APPLICATION/JSON
255
+ # */*
256
+ # @param [String] mime MIME
257
+ # @return [Boolean] True if the MIME is application/json
258
+ def json_mime?(mime)
259
+ (mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
260
+ end
261
+
262
+ # Deserialize the response to the given return type.
263
+ #
264
+ # @param [Response] response HTTP response
265
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
266
+ def deserialize(response, return_type)
267
+ body = response.body
268
+ return nil if body.nil? || body.empty?
269
+
270
+ # return response body directly for String return type
271
+ return body.to_s if return_type == 'String'
272
+
273
+ # ensuring a default content type
274
+ content_type = response.headers['Content-Type'] || 'application/json'
275
+
276
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
277
+
278
+ begin
279
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
280
+ rescue JSON::ParserError => e
281
+ if %w(String Date Time).include?(return_type)
282
+ data = body
283
+ else
284
+ raise e
285
+ end
286
+ end
287
+
288
+ convert_to_type data, return_type
289
+ end
290
+
291
+ # Convert data to the given return type.
292
+ # @param [Object] data Data to be converted
293
+ # @param [String] return_type Return type
294
+ # @return [Mixed] Data in a particular type
295
+ def convert_to_type(data, return_type)
296
+ return nil if data.nil?
297
+ case return_type
298
+ when 'String'
299
+ data.to_s
300
+ when 'Integer'
301
+ data.to_i
302
+ when 'Float'
303
+ data.to_f
304
+ when 'Boolean'
305
+ data == true
306
+ when 'Time'
307
+ # parse date time (expecting ISO 8601 format)
308
+ Time.parse data
309
+ when 'Date'
310
+ # parse date time (expecting ISO 8601 format)
311
+ Date.parse data
312
+ when 'Object'
313
+ # generic object (usually a Hash), return directly
314
+ data
315
+ when /\AArray<(.+)>\z/
316
+ # e.g. Array<Pet>
317
+ sub_type = $1
318
+ data.map { |item| convert_to_type(item, sub_type) }
319
+ when /\AHash\<String, (.+)\>\z/
320
+ # e.g. Hash<String, Integer>
321
+ sub_type = $1
322
+ {}.tap do |hash|
323
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
324
+ end
325
+ else
326
+ # models (e.g. Pet) or oneOf
327
+ klass = PulpHuggingFaceClient.const_get(return_type)
328
+ klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
329
+ end
330
+ end
331
+
332
+ # Sanitize filename by removing path.
333
+ # e.g. ../../sun.gif becomes sun.gif
334
+ #
335
+ # @param [String] filename the filename to be sanitized
336
+ # @return [String] the sanitized filename
337
+ def sanitize_filename(filename)
338
+ filename.split(/[\/\\]/).last
339
+ end
340
+
341
+ def build_request_url(path, opts = {})
342
+ # Add leading and trailing slashes to path
343
+ path = "/#{path}".gsub(/\/+/, '/')
344
+ @config.base_url(opts[:operation]) + path
345
+ end
346
+
347
+ # Update header and query params based on authentication settings.
348
+ #
349
+ # @param [Hash] header_params Header parameters
350
+ # @param [Hash] query_params Query parameters
351
+ # @param [String] auth_names Authentication scheme name
352
+ def update_params_for_auth!(header_params, query_params, auth_names)
353
+ Array(auth_names).each do |auth_name|
354
+ auth_setting = @config.auth_settings[auth_name]
355
+ next unless auth_setting
356
+ case auth_setting[:in]
357
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
358
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
359
+ else fail ArgumentError, 'Authentication token must be in `query` or `header`'
360
+ end
361
+ end
362
+ end
363
+
364
+ # Sets user agent in HTTP header
365
+ #
366
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
367
+ def user_agent=(user_agent)
368
+ @user_agent = user_agent
369
+ @default_headers['User-Agent'] = @user_agent
370
+ end
371
+
372
+ # Return Accept header based on an array of accepts provided.
373
+ # @param [Array] accepts array for Accept
374
+ # @return [String] the Accept header (e.g. application/json)
375
+ def select_header_accept(accepts)
376
+ return nil if accepts.nil? || accepts.empty?
377
+ # use JSON when present, otherwise use all of the provided
378
+ json_accept = accepts.find { |s| json_mime?(s) }
379
+ json_accept || accepts.join(',')
380
+ end
381
+
382
+ # Return Content-Type header based on an array of content types provided.
383
+ # @param [Array] content_types array for Content-Type
384
+ # @return [String] the Content-Type header (e.g. application/json)
385
+ def select_header_content_type(content_types)
386
+ # return nil by default
387
+ return if content_types.nil? || content_types.empty?
388
+ # use JSON when present, otherwise use the first one
389
+ json_content_type = content_types.find { |s| json_mime?(s) }
390
+ json_content_type || content_types.first
391
+ end
392
+
393
+ # Convert object (array, hash, object, etc) to JSON string.
394
+ # @param [Object] model object to be converted into JSON string
395
+ # @return [String] JSON string representation of the object
396
+ def object_to_http_body(model)
397
+ return model if model.nil? || model.is_a?(String)
398
+ local_body = nil
399
+ if model.is_a?(Array)
400
+ local_body = model.map { |m| object_to_hash(m) }
401
+ else
402
+ local_body = object_to_hash(model)
403
+ end
404
+ local_body.to_json
405
+ end
406
+
407
+ # Convert object(non-array) to hash.
408
+ # @param [Object] obj object to be converted into JSON string
409
+ # @return [String] JSON string representation of the object
410
+ def object_to_hash(obj)
411
+ if obj.respond_to?(:to_hash)
412
+ obj.to_hash
413
+ else
414
+ obj
415
+ end
416
+ end
417
+
418
+ # Build parameter value according to the given collection format.
419
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
420
+ def build_collection_param(param, collection_format)
421
+ case collection_format
422
+ when :csv
423
+ param.join(',')
424
+ when :ssv
425
+ param.join(' ')
426
+ when :tsv
427
+ param.join("\t")
428
+ when :pipes
429
+ param.join('|')
430
+ when :multi
431
+ # return the array directly as typhoeus will handle it as expected
432
+ param
433
+ else
434
+ fail "unknown collection format: #{collection_format.inspect}"
435
+ end
436
+ end
437
+ end
438
+ end
@@ -0,0 +1,58 @@
1
+ =begin
2
+ #Pulp 3 API
3
+
4
+ #Fetch, Upload, Organize, and Distribute Software Packages
5
+
6
+ The version of the OpenAPI document: v3
7
+ Contact: pulp-list@redhat.com
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.10.0
10
+
11
+ =end
12
+
13
+ module PulpHuggingFaceClient
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
+ if @message.nil?
46
+ msg = "Error message: the server returns an error"
47
+ else
48
+ msg = @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