package-test-ruby 1.0.3

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 (43) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +28 -0
  3. data/README.md +174 -0
  4. data/bin/console +15 -0
  5. data/lib/swagger_petstore_open_api30/api_helper.rb +10 -0
  6. data/lib/swagger_petstore_open_api30/client.rb +90 -0
  7. data/lib/swagger_petstore_open_api30/configuration.rb +173 -0
  8. data/lib/swagger_petstore_open_api30/controllers/base_controller.rb +60 -0
  9. data/lib/swagger_petstore_open_api30/controllers/pet_controller.rb +271 -0
  10. data/lib/swagger_petstore_open_api30/controllers/store_controller.rb +125 -0
  11. data/lib/swagger_petstore_open_api30/controllers/user_controller.rb +223 -0
  12. data/lib/swagger_petstore_open_api30/exceptions/api_exception.rb +21 -0
  13. data/lib/swagger_petstore_open_api30/exceptions/o_auth_provider_exception.rb +64 -0
  14. data/lib/swagger_petstore_open_api30/http/auth/api_key.rb +52 -0
  15. data/lib/swagger_petstore_open_api30/http/auth/petstore_auth.rb +113 -0
  16. data/lib/swagger_petstore_open_api30/http/http_call_back.rb +10 -0
  17. data/lib/swagger_petstore_open_api30/http/http_method_enum.rb +10 -0
  18. data/lib/swagger_petstore_open_api30/http/http_request.rb +10 -0
  19. data/lib/swagger_petstore_open_api30/http/http_response.rb +10 -0
  20. data/lib/swagger_petstore_open_api30/http/proxy_settings.rb +22 -0
  21. data/lib/swagger_petstore_open_api30/models/api_response.rb +101 -0
  22. data/lib/swagger_petstore_open_api30/models/base_model.rb +110 -0
  23. data/lib/swagger_petstore_open_api30/models/category.rb +88 -0
  24. data/lib/swagger_petstore_open_api30/models/o_auth_provider_error_enum.rb +62 -0
  25. data/lib/swagger_petstore_open_api30/models/o_auth_scope_petstore_auth_enum.rb +36 -0
  26. data/lib/swagger_petstore_open_api30/models/o_auth_token.rb +125 -0
  27. data/lib/swagger_petstore_open_api30/models/order.rb +151 -0
  28. data/lib/swagger_petstore_open_api30/models/pet.rb +151 -0
  29. data/lib/swagger_petstore_open_api30/models/status1_enum.rb +40 -0
  30. data/lib/swagger_petstore_open_api30/models/status2_enum.rb +40 -0
  31. data/lib/swagger_petstore_open_api30/models/status_enum.rb +40 -0
  32. data/lib/swagger_petstore_open_api30/models/tag.rb +88 -0
  33. data/lib/swagger_petstore_open_api30/models/user.rb +167 -0
  34. data/lib/swagger_petstore_open_api30/utilities/date_time_helper.rb +11 -0
  35. data/lib/swagger_petstore_open_api30/utilities/file_wrapper.rb +28 -0
  36. data/lib/swagger_petstore_open_api30/utilities/xml_utilities.rb +12 -0
  37. data/lib/swagger_petstore_open_api30.rb +59 -0
  38. data/test/controllers/controller_test_base.rb +28 -0
  39. data/test/controllers/test_pet_controller.rb +50 -0
  40. data/test/controllers/test_store_controller.rb +55 -0
  41. data/test/controllers/test_user_controller.rb +156 -0
  42. data/test/http_response_catcher.rb +19 -0
  43. metadata +153 -0
@@ -0,0 +1,64 @@
1
+ # swagger_petstore_open_api30
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module SwaggerPetstoreOpenApi30
7
+ # OAuth 2 Authorization endpoint exception.
8
+ class OAuthProviderException < APIException
9
+ SKIP = Object.new
10
+ private_constant :SKIP
11
+
12
+ # Gets or sets error code.
13
+ # @return [OAuthProviderErrorEnum]
14
+ attr_accessor :error
15
+
16
+ # Gets or sets human-readable text providing additional information on
17
+ # error.
18
+ # Used to assist the client developer in understanding the error that
19
+ # occurred.
20
+ # @return [String]
21
+ attr_accessor :error_description
22
+
23
+ # Gets or sets a URI identifying a human-readable web page with information
24
+ # about the error, used to provide the client developer with additional
25
+ # information about the error.
26
+ # @return [String]
27
+ attr_accessor :error_uri
28
+
29
+ # The constructor.
30
+ # @param [String] reason The reason for raising an exception.
31
+ # @param [HttpResponse] response The HttpReponse of the API call.
32
+ def initialize(reason, response)
33
+ super(reason, response)
34
+ hash = APIHelper.json_deserialize(@response.raw_body)
35
+ unbox(hash)
36
+ end
37
+
38
+ # Populates this object by extracting properties from a hash.
39
+ # @param [Hash] hash The deserialized response sent by the server in the
40
+ # response body.
41
+ def unbox(hash)
42
+ return nil unless hash
43
+
44
+ @error = hash.key?('error') ? hash['error'] : nil
45
+ @error_description =
46
+ hash.key?('error_description') ? hash['error_description'] : SKIP
47
+ @error_uri = hash.key?('error_uri') ? hash['error_uri'] : SKIP
48
+ end
49
+
50
+ # Provides a human-readable string representation of the object.
51
+ def to_s
52
+ class_name = self.class.name.split('::').last
53
+ "<#{class_name} error: #{@error}, error_description: #{@error_description}, error_uri:"\
54
+ " #{@error_uri}>"
55
+ end
56
+
57
+ # Provides a debugging-friendly string with detailed object information.
58
+ def inspect
59
+ class_name = self.class.name.split('::').last
60
+ "<#{class_name} error: #{@error.inspect}, error_description: #{@error_description.inspect},"\
61
+ " error_uri: #{@error_uri.inspect}>"
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,52 @@
1
+ # swagger_petstore_open_api30
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module SwaggerPetstoreOpenApi30
7
+ # Utility class for custom header authorization.
8
+ class ApiKey < CoreLibrary::HeaderAuth
9
+ # Display error message on occurrence of authentication failure.
10
+ # @returns [String] The oAuth error message.
11
+ def error_message
12
+ 'ApiKey: api_key is undefined.'
13
+ end
14
+
15
+ # Initialization constructor.
16
+ def initialize(api_key_credentials)
17
+ auth_params = {}
18
+ auth_params['api_key'] = api_key_credentials.api_key unless
19
+ api_key_credentials.nil? || api_key_credentials.api_key.nil?
20
+
21
+ super auth_params
22
+ end
23
+ end
24
+
25
+ # Data class for ApiKeyCredentials.
26
+ # Data class for ApiKeyCredentials.
27
+ class ApiKeyCredentials
28
+ attr_reader :api_key
29
+
30
+ def initialize(api_key:)
31
+ raise ArgumentError, 'api_key cannot be nil' if api_key.nil?
32
+
33
+ @api_key = api_key
34
+ end
35
+
36
+ def self.from_env
37
+ api_key = ENV['API_KEY_API_KEY']
38
+ all_nil = [
39
+ api_key
40
+ ].all?(&:nil?)
41
+ return nil if all_nil
42
+
43
+ new(api_key: api_key)
44
+ end
45
+
46
+ def clone_with(api_key: nil)
47
+ api_key ||= self.api_key
48
+
49
+ ApiKeyCredentials.new(api_key: api_key)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,113 @@
1
+ # swagger_petstore_open_api30
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module SwaggerPetstoreOpenApi30
7
+ # Utility class for OAuth 2 authorization and token management.
8
+ class PetstoreAuth < CoreLibrary::HeaderAuth
9
+ include CoreLibrary
10
+ # Display error message on occurrence of authentication failure.
11
+ # @returns [String] The oAuth error message.
12
+ def error_message
13
+ 'PetstoreAuth: OAuthToken is undefined or expired.'
14
+ end
15
+
16
+ # Initialization constructor.
17
+ def initialize(petstore_auth_credentials, config)
18
+ auth_params = {}
19
+ @_o_auth_client_id = petstore_auth_credentials.o_auth_client_id unless
20
+ petstore_auth_credentials.nil? || petstore_auth_credentials.o_auth_client_id.nil?
21
+ @_o_auth_redirect_uri = petstore_auth_credentials.o_auth_redirect_uri unless
22
+ petstore_auth_credentials.nil? || petstore_auth_credentials.o_auth_redirect_uri.nil?
23
+ @_o_auth_token = petstore_auth_credentials.o_auth_token unless
24
+ petstore_auth_credentials.nil? || petstore_auth_credentials.o_auth_token.nil?
25
+ @_o_auth_scopes = petstore_auth_credentials.o_auth_scopes unless
26
+ petstore_auth_credentials.nil? || petstore_auth_credentials.o_auth_scopes.nil?
27
+ @_o_auth_api = OAuthAuthorizationController.new(config)
28
+ auth_params[:Authorization] = "Bearer #{@_o_auth_token.access_token}" unless @_o_auth_token.nil?
29
+
30
+ super auth_params
31
+ end
32
+
33
+ # Validates the oAuth token.
34
+ # @return [Boolean] true if the token is present and not expired.
35
+ def valid
36
+ !@_o_auth_token.nil? && !token_expired?(@_o_auth_token)
37
+ end
38
+
39
+ # Builds and returns an authorization URL.
40
+ # The user is expected to obtain an authorization code from this URL and then call the
41
+ # fetch token function with that authorization code.
42
+ # @param [String] state An opaque state string.
43
+ # @param [Hash] additional_params Any additional query parameters to be added to the URL.
44
+ # @return [String] The authorization URL.
45
+ def get_authorization_url(state: nil, additional_params: nil)
46
+ auth_url = @_config.get_base_uri_executor.call(Server::AUTH_SERVER)
47
+ auth_url += '/authorize'
48
+ query_params = {
49
+ 'response_type' => 'code',
50
+ 'client_id' => @_o_auth_client_id,
51
+ 'redirect_uri' => @_o_auth_redirect_uri
52
+ }
53
+ query_params['scope'] = Array(@_o_auth_scopes).compact.join(' ') if @_o_auth_scopes
54
+ query_params['state'] = state if state
55
+ query_params.merge!(additional_params) if additional_params
56
+ auth_url = APIHelper.append_url_with_query_parameters(auth_url,
57
+ query_params)
58
+ APIHelper.clean_url(auth_url)
59
+ end
60
+
61
+ # Checks if OAuth token has expired.
62
+ # @param [OAuthToken] token The oAuth token instance.
63
+ # @return [Boolean] true if the token is present and not expired.
64
+ def token_expired?(token)
65
+ token.respond_to?('expiry') && AuthHelper.token_expired?(token.expiry)
66
+ end
67
+ end
68
+
69
+ # Data class for PetstoreAuthCredentials.
70
+ class PetstoreAuthCredentials
71
+ attr_reader :o_auth_client_id, :o_auth_redirect_uri, :o_auth_token,
72
+ :o_auth_scopes
73
+
74
+ def initialize(o_auth_client_id:, o_auth_redirect_uri:, o_auth_token: nil,
75
+ o_auth_scopes: nil)
76
+ raise ArgumentError, 'o_auth_client_id cannot be nil' if o_auth_client_id.nil?
77
+ raise ArgumentError, 'o_auth_redirect_uri cannot be nil' if o_auth_redirect_uri.nil?
78
+
79
+ @o_auth_client_id = o_auth_client_id
80
+ @o_auth_redirect_uri = o_auth_redirect_uri
81
+ @o_auth_token = o_auth_token
82
+ @o_auth_scopes = o_auth_scopes
83
+ end
84
+
85
+ def self.from_env
86
+ o_auth_client_id = ENV['PETSTORE_AUTH_O_AUTH_CLIENT_ID']
87
+ o_auth_redirect_uri = ENV['PETSTORE_AUTH_O_AUTH_REDIRECT_URI']
88
+ o_auth_scopes = ENV['PETSTORE_AUTH_O_AUTH_SCOPES']
89
+ all_nil = [
90
+ o_auth_client_id,
91
+ o_auth_redirect_uri
92
+ ].all?(&:nil?)
93
+ return nil if all_nil
94
+
95
+ new(o_auth_client_id: o_auth_client_id,
96
+ o_auth_redirect_uri: o_auth_redirect_uri,
97
+ o_auth_scopes: o_auth_scopes)
98
+ end
99
+
100
+ def clone_with(o_auth_client_id: nil, o_auth_redirect_uri: nil,
101
+ o_auth_token: nil, o_auth_scopes: nil)
102
+ o_auth_client_id ||= self.o_auth_client_id
103
+ o_auth_redirect_uri ||= self.o_auth_redirect_uri
104
+ o_auth_token ||= self.o_auth_token
105
+ o_auth_scopes ||= self.o_auth_scopes
106
+
107
+ PetstoreAuthCredentials.new(o_auth_client_id: o_auth_client_id,
108
+ o_auth_redirect_uri: o_auth_redirect_uri,
109
+ o_auth_token: o_auth_token,
110
+ o_auth_scopes: o_auth_scopes)
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,10 @@
1
+ # swagger_petstore_open_api30
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module SwaggerPetstoreOpenApi30
7
+ # HttpCallBack allows defining callables for pre and post API calls.
8
+ class HttpCallBack < CoreLibrary::HttpCallback
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # swagger_petstore_open_api30
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module SwaggerPetstoreOpenApi30
7
+ # HTTP Methods Enumeration.
8
+ class HttpMethodEnum < CoreLibrary::HttpMethod
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # swagger_petstore_open_api30
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module SwaggerPetstoreOpenApi30
7
+ # Represents a single Http Request.
8
+ class HttpRequest < CoreLibrary::HttpRequest
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # swagger_petstore_open_api30
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module SwaggerPetstoreOpenApi30
7
+ # Http response received.
8
+ class HttpResponse < CoreLibrary::HttpResponse
9
+ end
10
+ end
@@ -0,0 +1,22 @@
1
+ # swagger_petstore_open_api30
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module SwaggerPetstoreOpenApi30
7
+ ##
8
+ # ProxySettings encapsulates HTTP proxy configuration for Faraday,
9
+ # including optional basic authentication.
10
+ #
11
+ class ProxySettings < CoreLibrary::ProxySettings
12
+ def self.from_env
13
+ address = ENV['PROXY_ADDRESS']
14
+ port = ENV['PROXY_PORT']
15
+ username = ENV['PROXY_USERNAME']
16
+ password = ENV['PROXY_PASSWORD']
17
+ return nil if address.nil? || address.strip.empty?
18
+
19
+ new(address: address, port: port, username: username, password: password)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,101 @@
1
+ # swagger_petstore_open_api30
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module SwaggerPetstoreOpenApi30
7
+ # ApiResponse Model.
8
+ class ApiResponse < BaseModel
9
+ SKIP = Object.new
10
+ private_constant :SKIP
11
+
12
+ # TODO: Write general description for this method
13
+ # @return [Integer]
14
+ attr_accessor :code
15
+
16
+ # TODO: Write general description for this method
17
+ # @return [String]
18
+ attr_accessor :type
19
+
20
+ # TODO: Write general description for this method
21
+ # @return [String]
22
+ attr_accessor :message
23
+
24
+ # A mapping from model property names to API property names.
25
+ def self.names
26
+ @_hash = {} if @_hash.nil?
27
+ @_hash['code'] = 'code'
28
+ @_hash['type'] = 'type'
29
+ @_hash['message'] = 'message'
30
+ @_hash
31
+ end
32
+
33
+ # An array for optional fields
34
+ def self.optionals
35
+ %w[
36
+ code
37
+ type
38
+ message
39
+ ]
40
+ end
41
+
42
+ # An array for nullable fields
43
+ def self.nullables
44
+ []
45
+ end
46
+
47
+ def initialize(code = SKIP, type = SKIP, message = SKIP)
48
+ @code = code unless code == SKIP
49
+ @type = type unless type == SKIP
50
+ @message = message unless message == SKIP
51
+ end
52
+
53
+ # Creates an instance of the object from a hash.
54
+ def self.from_hash(hash)
55
+ return nil unless hash
56
+
57
+ # Extract variables from the hash.
58
+ code = hash.key?('code') ? hash['code'] : SKIP
59
+ type = hash.key?('type') ? hash['type'] : SKIP
60
+ message = hash.key?('message') ? hash['message'] : SKIP
61
+
62
+ # Create object from extracted values.
63
+ ApiResponse.new(code,
64
+ type,
65
+ message)
66
+ end
67
+
68
+ def self.from_element(root)
69
+ code = XmlUtilities.from_element(root, 'code', Integer)
70
+ type = XmlUtilities.from_element(root, 'type', String)
71
+ message = XmlUtilities.from_element(root, 'message', String)
72
+
73
+ new(code,
74
+ type,
75
+ message)
76
+ end
77
+
78
+ def to_xml_element(doc, root_name)
79
+ root = doc.create_element(root_name)
80
+
81
+ XmlUtilities.add_as_subelement(doc, root, 'code', code)
82
+ XmlUtilities.add_as_subelement(doc, root, 'type', type)
83
+ XmlUtilities.add_as_subelement(doc, root, 'message', message)
84
+
85
+ root
86
+ end
87
+
88
+ # Provides a human-readable string representation of the object.
89
+ def to_s
90
+ class_name = self.class.name.split('::').last
91
+ "<#{class_name} code: #{@code}, type: #{@type}, message: #{@message}>"
92
+ end
93
+
94
+ # Provides a debugging-friendly string with detailed object information.
95
+ def inspect
96
+ class_name = self.class.name.split('::').last
97
+ "<#{class_name} code: #{@code.inspect}, type: #{@type.inspect}, message:"\
98
+ " #{@message.inspect}>"
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,110 @@
1
+ # swagger_petstore_open_api30
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module SwaggerPetstoreOpenApi30
7
+ # Base model.
8
+ # rubocop:disable all
9
+ class BaseModel < CoreLibrary::BaseModel
10
+ # Returns a Hash representation of the current object.
11
+ def to_hash
12
+ # validating the model being serialized
13
+ self.class.validate(self) if self.class.respond_to?(:validate)
14
+
15
+ hash = {}
16
+ instance_variables.each do |name|
17
+ value = instance_variable_get(name)
18
+ name = name[1..]
19
+ if name == 'additional_properties'
20
+ additional_properties = process_additional_properties(value, self.class.names)
21
+ hash.merge!(additional_properties)
22
+ else
23
+ key = self.class.names.key?(name) ? self.class.names[name] : name
24
+ optional_fields = self.class.optionals
25
+ nullable_fields = self.class.nullables
26
+ if value.nil?
27
+ next unless nullable_fields.include?(name)
28
+
29
+ if !optional_fields.include?(name) && !nullable_fields.include?(name)
30
+ raise ArgumentError,
31
+ "`#{name}` cannot be nil in `#{self.class}`. Please specify a valid value."
32
+ end
33
+ end
34
+
35
+ hash[key] = nil
36
+ unless value.nil?
37
+ if respond_to?("to_custom_#{name}")
38
+ if (value.instance_of? Array) || (value.instance_of? Hash)
39
+ params = [hash, key]
40
+ hash[key] = send("to_custom_#{name}", *params)
41
+ else
42
+ hash[key] = send("to_custom_#{name}")
43
+ end
44
+ elsif respond_to?("to_union_type_#{name}")
45
+ hash[key] = send("to_union_type_#{name}")
46
+ elsif value.instance_of? Array
47
+ hash[key] = value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
48
+ elsif value.instance_of? Hash
49
+ hash[key] = {}
50
+ value.each do |k, v|
51
+ hash[key][k] = v.is_a?(BaseModel) ? v.to_hash : v
52
+ end
53
+ else
54
+ hash[key] = value.is_a?(BaseModel) ? value.to_hash : value
55
+ end
56
+ end
57
+ end
58
+ end
59
+ hash
60
+ end
61
+
62
+ # Processes additional properties, ensuring no conflicts with existing properties.
63
+ def process_additional_properties(additional_properties, existing_prop_names)
64
+ hash = {}
65
+ additional_properties.each do |name, value|
66
+ check_for_conflict(name, existing_prop_names)
67
+
68
+ hash[name] = if value.is_a?(Array)
69
+ process_array(value)
70
+ elsif value.is_a?(Hash)
71
+ process_hash(value)
72
+ else
73
+ process_basic_value(value)
74
+ end
75
+ end
76
+ hash
77
+ end
78
+
79
+ # Checks if an additional property conflicts with a model's existing property.
80
+ def check_for_conflict(name, existing_prop_names)
81
+ return unless existing_prop_names.key?(name)
82
+
83
+ raise ArgumentError, "An additional property key, '#{name}' conflicts with one of the model's properties"
84
+ end
85
+
86
+ # Processes an array of values, recursively calling `to_hash` on BaseModel objects.
87
+ def process_array(value)
88
+ value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
89
+ end
90
+
91
+ # Processes a hash of values, recursively calling `to_hash` on BaseModel objects.
92
+ def process_hash(value)
93
+ value.transform_values do |v|
94
+ v.is_a?(BaseModel) ? v.to_hash : v
95
+ end
96
+ end
97
+
98
+ # Processes a basic value (non-array, non-hash).
99
+ def process_basic_value(value)
100
+ value.is_a?(BaseModel) ? value.to_hash : value
101
+ end
102
+
103
+ # Returns a JSON representation of the curent object.
104
+ def to_json(options = {})
105
+ hash = to_hash
106
+ hash.to_json(options)
107
+ end
108
+ end
109
+ # rubocop:enable all
110
+ end
@@ -0,0 +1,88 @@
1
+ # swagger_petstore_open_api30
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module SwaggerPetstoreOpenApi30
7
+ # Category Model.
8
+ class Category < BaseModel
9
+ SKIP = Object.new
10
+ private_constant :SKIP
11
+
12
+ # TODO: Write general description for this method
13
+ # @return [Integer]
14
+ attr_accessor :id
15
+
16
+ # TODO: Write general description for this method
17
+ # @return [String]
18
+ attr_accessor :name
19
+
20
+ # A mapping from model property names to API property names.
21
+ def self.names
22
+ @_hash = {} if @_hash.nil?
23
+ @_hash['id'] = 'id'
24
+ @_hash['name'] = 'name'
25
+ @_hash
26
+ end
27
+
28
+ # An array for optional fields
29
+ def self.optionals
30
+ %w[
31
+ id
32
+ name
33
+ ]
34
+ end
35
+
36
+ # An array for nullable fields
37
+ def self.nullables
38
+ []
39
+ end
40
+
41
+ def initialize(id = SKIP, name = SKIP)
42
+ @id = id unless id == SKIP
43
+ @name = name unless name == SKIP
44
+ end
45
+
46
+ # Creates an instance of the object from a hash.
47
+ def self.from_hash(hash)
48
+ return nil unless hash
49
+
50
+ # Extract variables from the hash.
51
+ id = hash.key?('id') ? hash['id'] : SKIP
52
+ name = hash.key?('name') ? hash['name'] : SKIP
53
+
54
+ # Create object from extracted values.
55
+ Category.new(id,
56
+ name)
57
+ end
58
+
59
+ def self.from_element(root)
60
+ id = XmlUtilities.from_element(root, 'id', Integer)
61
+ name = XmlUtilities.from_element(root, 'name', String)
62
+
63
+ new(id,
64
+ name)
65
+ end
66
+
67
+ def to_xml_element(doc, root_name)
68
+ root = doc.create_element(root_name)
69
+
70
+ XmlUtilities.add_as_subelement(doc, root, 'id', id)
71
+ XmlUtilities.add_as_subelement(doc, root, 'name', name)
72
+
73
+ root
74
+ end
75
+
76
+ # Provides a human-readable string representation of the object.
77
+ def to_s
78
+ class_name = self.class.name.split('::').last
79
+ "<#{class_name} id: #{@id}, name: #{@name}>"
80
+ end
81
+
82
+ # Provides a debugging-friendly string with detailed object information.
83
+ def inspect
84
+ class_name = self.class.name.split('::').last
85
+ "<#{class_name} id: #{@id.inspect}, name: #{@name.inspect}>"
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,62 @@
1
+ # swagger_petstore_open_api30
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v3.0 ( https://www.apimatic.io ).
5
+
6
+ module SwaggerPetstoreOpenApi30
7
+ # OAuth 2 Authorization error codes
8
+ class OAuthProviderErrorEnum
9
+ O_AUTH_PROVIDER_ERROR_ENUM = [
10
+ # The request is missing a required parameter, includes an unsupported
11
+ # parameter value (other than grant type), repeats a parameter, includes
12
+ # multiple credentials, utilizes more than one mechanism for
13
+ # authenticating the client, or is otherwise malformed.
14
+ INVALID_REQUEST = 'invalid_request'.freeze,
15
+
16
+ # Client authentication failed (e.g., unknown client, no client
17
+ # authentication included, or unsupported authentication method).
18
+ INVALID_CLIENT = 'invalid_client'.freeze,
19
+
20
+ # The provided authorization grant (e.g., authorization code, resource
21
+ # owner credentials) or refresh token is invalid, expired, revoked, does
22
+ # not match the redirection URI used in the authorization request, or was
23
+ # issued to another client.
24
+ INVALID_GRANT = 'invalid_grant'.freeze,
25
+
26
+ # The authenticated client is not authorized to use this authorization
27
+ # grant type.
28
+ UNAUTHORIZED_CLIENT = 'unauthorized_client'.freeze,
29
+
30
+ # The authorization grant type is not supported by the authorization
31
+ # server.
32
+ UNSUPPORTED_GRANT_TYPE = 'unsupported_grant_type'.freeze,
33
+
34
+ # The requested scope is invalid, unknown, malformed, or exceeds the scope
35
+ # granted by the resource owner.
36
+ INVALID_SCOPE = 'invalid_scope'.freeze
37
+ ].freeze
38
+
39
+ def self.validate(value)
40
+ return false if value.nil?
41
+
42
+ O_AUTH_PROVIDER_ERROR_ENUM.include?(value)
43
+ end
44
+
45
+ def self.from_value(value, default_value = INVALID_REQUEST)
46
+ return default_value if value.nil?
47
+
48
+ str = value.to_s.strip
49
+
50
+ case str.downcase
51
+ when 'invalid_request' then INVALID_REQUEST
52
+ when 'invalid_client' then INVALID_CLIENT
53
+ when 'invalid_grant' then INVALID_GRANT
54
+ when 'unauthorized_client' then UNAUTHORIZED_CLIENT
55
+ when 'unsupported_grant_type' then UNSUPPORTED_GRANT_TYPE
56
+ when 'invalid_scope' then INVALID_SCOPE
57
+ else
58
+ default_value
59
+ end
60
+ end
61
+ end
62
+ end