pulp_npm_client 0.1.0a1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +9 -0
- data/README.md +157 -0
- data/Rakefile +10 -0
- data/docs/AsyncOperationResponse.md +17 -0
- data/docs/ContentPackagesApi.md +208 -0
- data/docs/ContentSummary.md +21 -0
- data/docs/ContentSummaryResponse.md +21 -0
- data/docs/DistributionsNpmApi.md +364 -0
- data/docs/NpmNpmDistribution.md +25 -0
- data/docs/NpmNpmDistributionResponse.md +31 -0
- data/docs/NpmNpmRemote.md +37 -0
- data/docs/NpmNpmRemoteResponse.md +43 -0
- data/docs/NpmNpmRepository.md +21 -0
- data/docs/NpmNpmRepositoryResponse.md +29 -0
- data/docs/NpmPackage.md +27 -0
- data/docs/NpmPackageResponse.md +27 -0
- data/docs/PaginatedRepositoryVersionResponseList.md +23 -0
- data/docs/PaginatednpmNpmDistributionResponseList.md +23 -0
- data/docs/PaginatednpmNpmRemoteResponseList.md +23 -0
- data/docs/PaginatednpmNpmRepositoryResponseList.md +23 -0
- data/docs/PaginatednpmPackageResponseList.md +23 -0
- data/docs/PatchednpmNpmDistribution.md +25 -0
- data/docs/PatchednpmNpmRemote.md +37 -0
- data/docs/PatchednpmNpmRepository.md +21 -0
- data/docs/PolicyEnum.md +16 -0
- data/docs/PulpNpmPackagesApi.md +60 -0
- data/docs/RemotesNpmApi.md +368 -0
- data/docs/RepositoriesNpmApi.md +468 -0
- data/docs/RepositoriesNpmVersionsApi.md +271 -0
- data/docs/RepositoryAddRemoveContent.md +21 -0
- data/docs/RepositorySyncURL.md +19 -0
- data/docs/RepositoryVersion.md +17 -0
- data/docs/RepositoryVersionResponse.md +25 -0
- data/git_push.sh +58 -0
- data/lib/pulp_npm_client.rb +69 -0
- data/lib/pulp_npm_client/api/content_packages_api.rb +264 -0
- data/lib/pulp_npm_client/api/distributions_npm_api.rb +445 -0
- data/lib/pulp_npm_client/api/pulp_npm_packages_api.rb +86 -0
- data/lib/pulp_npm_client/api/remotes_npm_api.rb +451 -0
- data/lib/pulp_npm_client/api/repositories_npm_api.rb +573 -0
- data/lib/pulp_npm_client/api/repositories_npm_versions_api.rb +339 -0
- data/lib/pulp_npm_client/api_client.rb +402 -0
- data/lib/pulp_npm_client/api_error.rb +57 -0
- data/lib/pulp_npm_client/configuration.rb +243 -0
- data/lib/pulp_npm_client/models/async_operation_response.rb +213 -0
- data/lib/pulp_npm_client/models/content_summary.rb +240 -0
- data/lib/pulp_npm_client/models/content_summary_response.rb +240 -0
- data/lib/pulp_npm_client/models/npm_npm_distribution.rb +261 -0
- data/lib/pulp_npm_client/models/npm_npm_distribution_response.rb +290 -0
- data/lib/pulp_npm_client/models/npm_npm_remote.rb +339 -0
- data/lib/pulp_npm_client/models/npm_npm_remote_response.rb +368 -0
- data/lib/pulp_npm_client/models/npm_npm_repository.rb +234 -0
- data/lib/pulp_npm_client/models/npm_npm_repository_response.rb +271 -0
- data/lib/pulp_npm_client/models/npm_package.rb +270 -0
- data/lib/pulp_npm_client/models/npm_package_response.rb +269 -0
- data/lib/pulp_npm_client/models/paginated_repository_version_response_list.rb +237 -0
- data/lib/pulp_npm_client/models/paginatednpm_npm_distribution_response_list.rb +237 -0
- data/lib/pulp_npm_client/models/paginatednpm_npm_remote_response_list.rb +237 -0
- data/lib/pulp_npm_client/models/paginatednpm_npm_repository_response_list.rb +237 -0
- data/lib/pulp_npm_client/models/paginatednpm_package_response_list.rb +237 -0
- data/lib/pulp_npm_client/models/patchednpm_npm_distribution.rb +251 -0
- data/lib/pulp_npm_client/models/patchednpm_npm_remote.rb +329 -0
- data/lib/pulp_npm_client/models/patchednpm_npm_repository.rb +229 -0
- data/lib/pulp_npm_client/models/policy_enum.rb +37 -0
- data/lib/pulp_npm_client/models/repository_add_remove_content.rb +232 -0
- data/lib/pulp_npm_client/models/repository_sync_url.rb +220 -0
- data/lib/pulp_npm_client/models/repository_version.rb +208 -0
- data/lib/pulp_npm_client/models/repository_version_response.rb +246 -0
- data/lib/pulp_npm_client/version.rb +15 -0
- data/pulp_npm_client.gemspec +39 -0
- data/spec/api/content_packages_api_spec.rb +87 -0
- data/spec/api/distributions_npm_api_spec.rb +121 -0
- data/spec/api/pulp_npm_packages_api_spec.rb +48 -0
- data/spec/api/remotes_npm_api_spec.rb +123 -0
- data/spec/api/repositories_npm_api_spec.rb +143 -0
- data/spec/api/repositories_npm_versions_api_spec.rb +104 -0
- data/spec/api_client_spec.rb +188 -0
- data/spec/configuration_spec.rb +42 -0
- data/spec/models/async_operation_response_spec.rb +41 -0
- data/spec/models/content_summary_response_spec.rb +53 -0
- data/spec/models/content_summary_spec.rb +53 -0
- data/spec/models/npm_npm_distribution_response_spec.rb +83 -0
- data/spec/models/npm_npm_distribution_spec.rb +65 -0
- data/spec/models/npm_npm_remote_response_spec.rb +119 -0
- data/spec/models/npm_npm_remote_spec.rb +101 -0
- data/spec/models/npm_npm_repository_response_spec.rb +77 -0
- data/spec/models/npm_npm_repository_spec.rb +53 -0
- data/spec/models/npm_package_response_spec.rb +71 -0
- data/spec/models/npm_package_spec.rb +71 -0
- data/spec/models/paginated_repository_version_response_list_spec.rb +59 -0
- data/spec/models/paginatednpm_npm_distribution_response_list_spec.rb +59 -0
- data/spec/models/paginatednpm_npm_remote_response_list_spec.rb +59 -0
- data/spec/models/paginatednpm_npm_repository_response_list_spec.rb +59 -0
- data/spec/models/paginatednpm_package_response_list_spec.rb +59 -0
- data/spec/models/patchednpm_npm_distribution_spec.rb +65 -0
- data/spec/models/patchednpm_npm_remote_spec.rb +101 -0
- data/spec/models/patchednpm_npm_repository_spec.rb +53 -0
- data/spec/models/policy_enum_spec.rb +35 -0
- data/spec/models/repository_add_remove_content_spec.rb +53 -0
- data/spec/models/repository_sync_url_spec.rb +47 -0
- data/spec/models/repository_version_response_spec.rb +65 -0
- data/spec/models/repository_version_spec.rb +41 -0
- data/spec/spec_helper.rb +111 -0
- metadata +233 -0
@@ -0,0 +1,57 @@
|
|
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
|
+
OpenAPI Generator version: 4.2.3
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
module PulpNpmClient
|
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
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Override to_s to display a friendly error message
|
39
|
+
def to_s
|
40
|
+
message
|
41
|
+
end
|
42
|
+
|
43
|
+
def message
|
44
|
+
if @message.nil?
|
45
|
+
msg = "Error message: the server returns an error"
|
46
|
+
else
|
47
|
+
msg = @message
|
48
|
+
end
|
49
|
+
|
50
|
+
msg += "\nHTTP status code: #{code}" if code
|
51
|
+
msg += "\nResponse headers: #{response_headers}" if response_headers
|
52
|
+
msg += "\nResponse body: #{response_body}" if response_body
|
53
|
+
|
54
|
+
msg
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,243 @@
|
|
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
|
+
OpenAPI Generator version: 4.2.3
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
module PulpNpmClient
|
14
|
+
class Configuration
|
15
|
+
# Defines url scheme
|
16
|
+
attr_accessor :scheme
|
17
|
+
|
18
|
+
# Defines url host
|
19
|
+
attr_accessor :host
|
20
|
+
|
21
|
+
# Defines url base path
|
22
|
+
attr_accessor :base_path
|
23
|
+
|
24
|
+
# Defines API keys used with API Key authentications.
|
25
|
+
#
|
26
|
+
# @return [Hash] key: parameter name, value: parameter value (API key)
|
27
|
+
#
|
28
|
+
# @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
|
29
|
+
# config.api_key['api_key'] = 'xxx'
|
30
|
+
attr_accessor :api_key
|
31
|
+
|
32
|
+
# Defines API key prefixes used with API Key authentications.
|
33
|
+
#
|
34
|
+
# @return [Hash] key: parameter name, value: API key prefix
|
35
|
+
#
|
36
|
+
# @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
|
37
|
+
# config.api_key_prefix['api_key'] = 'Token'
|
38
|
+
attr_accessor :api_key_prefix
|
39
|
+
|
40
|
+
# Defines the username used with HTTP basic authentication.
|
41
|
+
#
|
42
|
+
# @return [String]
|
43
|
+
attr_accessor :username
|
44
|
+
|
45
|
+
# Defines the password used with HTTP basic authentication.
|
46
|
+
#
|
47
|
+
# @return [String]
|
48
|
+
attr_accessor :password
|
49
|
+
|
50
|
+
# Defines the access token (Bearer) used with OAuth2.
|
51
|
+
attr_accessor :access_token
|
52
|
+
|
53
|
+
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
54
|
+
# details will be logged with `logger.debug` (see the `logger` attribute).
|
55
|
+
# Default to false.
|
56
|
+
#
|
57
|
+
# @return [true, false]
|
58
|
+
attr_accessor :debugging
|
59
|
+
|
60
|
+
# Defines the logger used for debugging.
|
61
|
+
# Default to `Rails.logger` (when in Rails) or logging to STDOUT.
|
62
|
+
#
|
63
|
+
# @return [#debug]
|
64
|
+
attr_accessor :logger
|
65
|
+
|
66
|
+
# Defines the temporary folder to store downloaded files
|
67
|
+
# (for API endpoints that have file response).
|
68
|
+
# Default to use `Tempfile`.
|
69
|
+
#
|
70
|
+
# @return [String]
|
71
|
+
attr_accessor :temp_folder_path
|
72
|
+
|
73
|
+
# The time limit for HTTP request in seconds.
|
74
|
+
# Default to 0 (never times out).
|
75
|
+
attr_accessor :timeout
|
76
|
+
|
77
|
+
# Set this to false to skip client side validation in the operation.
|
78
|
+
# Default to true.
|
79
|
+
# @return [true, false]
|
80
|
+
attr_accessor :client_side_validation
|
81
|
+
|
82
|
+
### TLS/SSL setting
|
83
|
+
# Set this to false to skip verifying SSL certificate when calling API from https server.
|
84
|
+
# Default to true.
|
85
|
+
#
|
86
|
+
# @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
|
87
|
+
#
|
88
|
+
# @return [true, false]
|
89
|
+
attr_accessor :ssl_verify
|
90
|
+
|
91
|
+
### TLS/SSL setting
|
92
|
+
# Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
|
93
|
+
#
|
94
|
+
# @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
|
95
|
+
#
|
96
|
+
attr_accessor :ssl_verify_mode
|
97
|
+
|
98
|
+
### TLS/SSL setting
|
99
|
+
# Set this to customize the certificate file to verify the peer.
|
100
|
+
#
|
101
|
+
# @return [String] the path to the certificate file
|
102
|
+
attr_accessor :ssl_ca_file
|
103
|
+
|
104
|
+
### TLS/SSL setting
|
105
|
+
# Client certificate file (for client certificate)
|
106
|
+
attr_accessor :ssl_client_cert
|
107
|
+
|
108
|
+
### TLS/SSL setting
|
109
|
+
# Client private key file (for client certificate)
|
110
|
+
attr_accessor :ssl_client_key
|
111
|
+
|
112
|
+
# Set this to customize parameters encoding of array parameter with multi collectionFormat.
|
113
|
+
# Default to nil.
|
114
|
+
#
|
115
|
+
# @see The params_encoding option of Ethon. Related source code:
|
116
|
+
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
|
117
|
+
attr_accessor :params_encoding
|
118
|
+
|
119
|
+
attr_accessor :inject_format
|
120
|
+
|
121
|
+
attr_accessor :force_ending_format
|
122
|
+
|
123
|
+
def initialize
|
124
|
+
@scheme = 'http'
|
125
|
+
@host = 'pulp'
|
126
|
+
@base_path = ''
|
127
|
+
@api_key = {}
|
128
|
+
@api_key_prefix = {}
|
129
|
+
@timeout = 0
|
130
|
+
@client_side_validation = true
|
131
|
+
@ssl_verify = true
|
132
|
+
@ssl_verify_mode = nil
|
133
|
+
@ssl_ca_file = nil
|
134
|
+
@ssl_client_cert = nil
|
135
|
+
@ssl_client_key = nil
|
136
|
+
@debugging = false
|
137
|
+
@inject_format = false
|
138
|
+
@force_ending_format = false
|
139
|
+
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
140
|
+
|
141
|
+
yield(self) if block_given?
|
142
|
+
end
|
143
|
+
|
144
|
+
# The default Configuration object.
|
145
|
+
def self.default
|
146
|
+
@@default ||= Configuration.new
|
147
|
+
end
|
148
|
+
|
149
|
+
def configure
|
150
|
+
yield(self) if block_given?
|
151
|
+
end
|
152
|
+
|
153
|
+
def scheme=(scheme)
|
154
|
+
# remove :// from scheme
|
155
|
+
@scheme = scheme.sub(/:\/\//, '')
|
156
|
+
end
|
157
|
+
|
158
|
+
def host=(host)
|
159
|
+
# remove http(s):// and anything after a slash
|
160
|
+
@host = host.sub(/https?:\/\//, '').split('/').first
|
161
|
+
end
|
162
|
+
|
163
|
+
def base_path=(base_path)
|
164
|
+
# Add leading and trailing slashes to base_path
|
165
|
+
@base_path = "/#{base_path}".gsub(/\/+/, '/')
|
166
|
+
@base_path = '' if @base_path == '/'
|
167
|
+
end
|
168
|
+
|
169
|
+
def base_url
|
170
|
+
"#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
|
171
|
+
end
|
172
|
+
|
173
|
+
# Gets API key (with prefix if set).
|
174
|
+
# @param [String] param_name the parameter name of API key auth
|
175
|
+
def api_key_with_prefix(param_name)
|
176
|
+
if @api_key_prefix[param_name]
|
177
|
+
"#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
|
178
|
+
else
|
179
|
+
@api_key[param_name]
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
# Gets Basic Auth token string
|
184
|
+
def basic_auth_token
|
185
|
+
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
186
|
+
end
|
187
|
+
|
188
|
+
# Returns Auth Settings hash for api client.
|
189
|
+
def auth_settings
|
190
|
+
{
|
191
|
+
'basicAuth' =>
|
192
|
+
{
|
193
|
+
type: 'basic',
|
194
|
+
in: 'header',
|
195
|
+
key: 'Authorization',
|
196
|
+
value: basic_auth_token
|
197
|
+
},
|
198
|
+
}
|
199
|
+
end
|
200
|
+
|
201
|
+
# Returns an array of Server setting
|
202
|
+
def server_settings
|
203
|
+
[
|
204
|
+
{
|
205
|
+
url: "http://pulp/",
|
206
|
+
description: "No description provided",
|
207
|
+
}
|
208
|
+
]
|
209
|
+
end
|
210
|
+
|
211
|
+
# Returns URL based on server settings
|
212
|
+
#
|
213
|
+
# @param index array index of the server settings
|
214
|
+
# @param variables hash of variable and the corresponding value
|
215
|
+
def server_url(index, variables = {})
|
216
|
+
servers = server_settings
|
217
|
+
|
218
|
+
# check array index out of bound
|
219
|
+
if (index < 0 || index >= servers.size)
|
220
|
+
fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
|
221
|
+
end
|
222
|
+
|
223
|
+
server = servers[index]
|
224
|
+
url = server[:url]
|
225
|
+
|
226
|
+
# go through variable and assign a value
|
227
|
+
server[:variables].each do |name, variable|
|
228
|
+
if variables.key?(name)
|
229
|
+
if (server[:variables][name][:enum_values].include? variables[name])
|
230
|
+
url.gsub! "{" + name.to_s + "}", variables[name]
|
231
|
+
else
|
232
|
+
fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
|
233
|
+
end
|
234
|
+
else
|
235
|
+
# use default value
|
236
|
+
url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
url
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
@@ -0,0 +1,213 @@
|
|
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
|
+
OpenAPI Generator version: 4.2.3
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'date'
|
14
|
+
|
15
|
+
module PulpNpmClient
|
16
|
+
# Serializer for asynchronous operations.
|
17
|
+
class AsyncOperationResponse
|
18
|
+
# The href of the task.
|
19
|
+
attr_accessor :task
|
20
|
+
|
21
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
22
|
+
def self.attribute_map
|
23
|
+
{
|
24
|
+
:'task' => :'task'
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
# Attribute type mapping.
|
29
|
+
def self.openapi_types
|
30
|
+
{
|
31
|
+
:'task' => :'String'
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
# List of attributes with nullable: true
|
36
|
+
def self.openapi_nullable
|
37
|
+
Set.new([
|
38
|
+
])
|
39
|
+
end
|
40
|
+
|
41
|
+
# Initializes the object
|
42
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
43
|
+
def initialize(attributes = {})
|
44
|
+
if (!attributes.is_a?(Hash))
|
45
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `PulpNpmClient::AsyncOperationResponse` initialize method"
|
46
|
+
end
|
47
|
+
|
48
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
49
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
50
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
51
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `PulpNpmClient::AsyncOperationResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
52
|
+
end
|
53
|
+
h[k.to_sym] = v
|
54
|
+
}
|
55
|
+
|
56
|
+
if attributes.key?(:'task')
|
57
|
+
self.task = attributes[:'task']
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
62
|
+
# @return Array for valid properties with the reasons
|
63
|
+
def list_invalid_properties
|
64
|
+
invalid_properties = Array.new
|
65
|
+
if @task.nil?
|
66
|
+
invalid_properties.push('invalid value for "task", task cannot be nil.')
|
67
|
+
end
|
68
|
+
|
69
|
+
invalid_properties
|
70
|
+
end
|
71
|
+
|
72
|
+
# Check to see if the all the properties in the model are valid
|
73
|
+
# @return true if the model is valid
|
74
|
+
def valid?
|
75
|
+
return false if @task.nil?
|
76
|
+
true
|
77
|
+
end
|
78
|
+
|
79
|
+
# Checks equality by comparing each attribute.
|
80
|
+
# @param [Object] Object to be compared
|
81
|
+
def ==(o)
|
82
|
+
return true if self.equal?(o)
|
83
|
+
self.class == o.class &&
|
84
|
+
task == o.task
|
85
|
+
end
|
86
|
+
|
87
|
+
# @see the `==` method
|
88
|
+
# @param [Object] Object to be compared
|
89
|
+
def eql?(o)
|
90
|
+
self == o
|
91
|
+
end
|
92
|
+
|
93
|
+
# Calculates hash code according to all attributes.
|
94
|
+
# @return [Integer] Hash code
|
95
|
+
def hash
|
96
|
+
[task].hash
|
97
|
+
end
|
98
|
+
|
99
|
+
# Builds the object from hash
|
100
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
101
|
+
# @return [Object] Returns the model itself
|
102
|
+
def self.build_from_hash(attributes)
|
103
|
+
new.build_from_hash(attributes)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Builds the object from hash
|
107
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
108
|
+
# @return [Object] Returns the model itself
|
109
|
+
def build_from_hash(attributes)
|
110
|
+
return nil unless attributes.is_a?(Hash)
|
111
|
+
self.class.openapi_types.each_pair do |key, type|
|
112
|
+
if type =~ /\AArray<(.*)>/i
|
113
|
+
# check to ensure the input is an array given that the attribute
|
114
|
+
# is documented as an array but the input is not
|
115
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
116
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
117
|
+
end
|
118
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
119
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
120
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
121
|
+
end
|
122
|
+
|
123
|
+
self
|
124
|
+
end
|
125
|
+
|
126
|
+
# Deserializes the data based on type
|
127
|
+
# @param string type Data type
|
128
|
+
# @param string value Value to be deserialized
|
129
|
+
# @return [Object] Deserialized data
|
130
|
+
def _deserialize(type, value)
|
131
|
+
case type.to_sym
|
132
|
+
when :DateTime
|
133
|
+
DateTime.parse(value)
|
134
|
+
when :Date
|
135
|
+
Date.parse(value)
|
136
|
+
when :String
|
137
|
+
value.to_s
|
138
|
+
when :Integer
|
139
|
+
value.to_i
|
140
|
+
when :Float
|
141
|
+
value.to_f
|
142
|
+
when :Boolean
|
143
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
144
|
+
true
|
145
|
+
else
|
146
|
+
false
|
147
|
+
end
|
148
|
+
when :Object
|
149
|
+
# generic object (usually a Hash), return directly
|
150
|
+
value
|
151
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
152
|
+
inner_type = Regexp.last_match[:inner_type]
|
153
|
+
value.map { |v| _deserialize(inner_type, v) }
|
154
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
155
|
+
k_type = Regexp.last_match[:k_type]
|
156
|
+
v_type = Regexp.last_match[:v_type]
|
157
|
+
{}.tap do |hash|
|
158
|
+
value.each do |k, v|
|
159
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
else # model
|
163
|
+
PulpNpmClient.const_get(type).build_from_hash(value)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
# Returns the string representation of the object
|
168
|
+
# @return [String] String presentation of the object
|
169
|
+
def to_s
|
170
|
+
to_hash.to_s
|
171
|
+
end
|
172
|
+
|
173
|
+
# to_body is an alias to to_hash (backward compatibility)
|
174
|
+
# @return [Hash] Returns the object in the form of hash
|
175
|
+
def to_body
|
176
|
+
to_hash
|
177
|
+
end
|
178
|
+
|
179
|
+
# Returns the object in the form of hash
|
180
|
+
# @return [Hash] Returns the object in the form of hash
|
181
|
+
def to_hash
|
182
|
+
hash = {}
|
183
|
+
self.class.attribute_map.each_pair do |attr, param|
|
184
|
+
value = self.send(attr)
|
185
|
+
if value.nil?
|
186
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
187
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
188
|
+
end
|
189
|
+
|
190
|
+
hash[param] = _to_hash(value)
|
191
|
+
end
|
192
|
+
hash
|
193
|
+
end
|
194
|
+
|
195
|
+
# Outputs non-array value in the form of hash
|
196
|
+
# For object, use to_hash. Otherwise, just return the value
|
197
|
+
# @param [Object] value Any valid value
|
198
|
+
# @return [Hash] Returns the value in the form of hash
|
199
|
+
def _to_hash(value)
|
200
|
+
if value.is_a?(Array)
|
201
|
+
value.compact.map { |v| _to_hash(v) }
|
202
|
+
elsif value.is_a?(Hash)
|
203
|
+
{}.tap do |hash|
|
204
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
205
|
+
end
|
206
|
+
elsif value.respond_to? :to_hash
|
207
|
+
value.to_hash
|
208
|
+
else
|
209
|
+
value
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|