jamm 0.0.1 → 1.0.2

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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -57
  3. data/.rubocop.yml +18 -25
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +99 -0
  6. data/README.md +4 -4
  7. data/Rakefile +2 -0
  8. data/jamm.gemspec +16 -3
  9. data/lib/jamm/api/api/customer_api.rb +265 -0
  10. data/lib/jamm/api/api/healthcheck_api.rb +76 -0
  11. data/lib/jamm/api/api/payment_api.rb +203 -0
  12. data/lib/jamm/api/api_client.rb +385 -0
  13. data/lib/jamm/api/api_error.rb +58 -0
  14. data/lib/jamm/api/configuration.rb +293 -0
  15. data/lib/jamm/api/models/customer_service_update_customer_body.rb +247 -0
  16. data/lib/jamm/api/models/protobuf_any.rb +209 -0
  17. data/lib/jamm/api/models/rpc_status.rb +218 -0
  18. data/lib/jamm/api/models/v1_buyer.rb +274 -0
  19. data/lib/jamm/api/models/v1_charge.rb +233 -0
  20. data/lib/jamm/api/models/v1_contract.rb +225 -0
  21. data/lib/jamm/api/models/v1_create_contract_with_charge_request.rb +217 -0
  22. data/lib/jamm/api/models/v1_create_contract_with_charge_response.rb +222 -0
  23. data/lib/jamm/api/models/v1_create_contract_without_charge_request.rb +212 -0
  24. data/lib/jamm/api/models/v1_create_contract_without_charge_response.rb +217 -0
  25. data/lib/jamm/api/models/v1_create_customer_request.rb +207 -0
  26. data/lib/jamm/api/models/v1_create_customer_response.rb +207 -0
  27. data/lib/jamm/api/models/v1_customer.rb +223 -0
  28. data/lib/jamm/api/models/v1_delete_customer_response.rb +207 -0
  29. data/lib/jamm/api/models/v1_get_contract_response.rb +212 -0
  30. data/lib/jamm/api/models/v1_get_customer_response.rb +207 -0
  31. data/lib/jamm/api/models/v1_initial_charge.rb +225 -0
  32. data/lib/jamm/api/models/v1_merchant.rb +212 -0
  33. data/lib/jamm/api/models/v1_merchant_customer.rb +213 -0
  34. data/lib/jamm/api/models/v1_payment_link.rb +221 -0
  35. data/lib/jamm/api/models/v1_ping_response.rb +207 -0
  36. data/lib/jamm/api/models/v1_update_customer_response.rb +207 -0
  37. data/lib/jamm/api/models/v1_url.rb +216 -0
  38. data/lib/jamm/api/version.rb +15 -0
  39. data/lib/jamm/api.rb +65 -0
  40. data/lib/jamm/client.rb +14 -0
  41. data/lib/jamm/customer.rb +28 -0
  42. data/lib/jamm/errors.rb +4 -14
  43. data/lib/jamm/oauth.rb +5 -5
  44. data/lib/jamm/payment.rb +19 -11
  45. data/lib/jamm/version.rb +3 -1
  46. data/lib/jamm.rb +37 -117
  47. metadata +62 -37
  48. data/.github/workflows/build.yml +0 -23
  49. data/.github/workflows/ruby-publish.yml +0 -24
  50. data/CONTRIBUTORS +0 -1
  51. data/images/jamm_logo.png +0 -0
  52. data/lib/jamm/api_operations/create.rb +0 -16
  53. data/lib/jamm/api_operations/get.rb +0 -16
  54. data/lib/jamm/api_operations/list.rb +0 -16
  55. data/lib/jamm/api_operations/update.rb +0 -16
  56. data/lib/jamm/api_resource.rb +0 -5
  57. data/lib/jamm/charge.rb +0 -10
  58. data/lib/jamm/jamm_object.rb +0 -249
  59. data/lib/jamm/request.rb +0 -13
  60. data/lib/jamm/time_util.rb +0 -41
  61. data/lib/jamm/token.rb +0 -10
  62. data/lib/jamm/util.rb +0 -76
  63. data/test/jamm/charge_test.rb +0 -56
  64. data/test/jamm/oauth_test.rb +0 -47
  65. data/test/jamm/payment_test.rb +0 -17
  66. data/test/jamm/time_util_test.rb +0 -18
  67. data/test/jamm/token_test.rb +0 -52
  68. data/test/test_data.rb +0 -118
  69. data/test/test_helper.rb +0 -59
@@ -0,0 +1,225 @@
1
+ # frozen_string_literal: true
2
+
3
+ # #api/v1/common.proto
4
+ #
5
+ # No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6
+ #
7
+ # The version of the OpenAPI document: version not set
8
+ #
9
+ # Generated by: https://openapi-generator.tech
10
+ # Generator version: 7.9.0
11
+ #
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Api
17
+ # InitialCharge is a charge object without id. Intended to be used when creating a contract with initial charge.
18
+ class InitialCharge
19
+ # Amount of the charge in Japanese Yen. The amount must be the total price of the product/service including tax. 決済金額。日本円で指定してください。 金額は商品/サービスの合計金額 (税込) を指定してください。 @gotags: validate:\"gte=1,lte=500000\"
20
+ attr_accessor :price
21
+
22
+ # Description is an arbitrary string for merchant to track the charge. This information is displayed on Merchant Dashboard. 決済の説明。ショップが決済を追跡するための任意の文字列です。 @gotags: validate:\"required\"
23
+ attr_accessor :description
24
+
25
+ # Merchant can optionally set the expiry date for the payment. Defaults to 90 minutes if not specified. 決済の有効期限。未指定の場合は90分後に自動失効します。
26
+ attr_accessor :expires_at
27
+
28
+ # Attribute mapping from ruby-style variable name to JSON key.
29
+ def self.attribute_map
30
+ {
31
+ :price => :price,
32
+ :description => :description,
33
+ :expires_at => :expiresAt
34
+ }
35
+ end
36
+
37
+ # Returns all the JSON keys this model knows about
38
+ def self.acceptable_attributes
39
+ attribute_map.values
40
+ end
41
+
42
+ # Attribute type mapping.
43
+ def self.openapi_types
44
+ {
45
+ :price => :Integer,
46
+ :description => :String,
47
+ :expires_at => :Time
48
+ }
49
+ end
50
+
51
+ # List of attributes with nullable: true
52
+ def self.openapi_nullable
53
+ Set.new([])
54
+ end
55
+
56
+ # Initializes the object
57
+ # @param [Hash] attributes Model attributes in the form of hash
58
+ def initialize(attributes = {})
59
+ raise ArgumentError, 'The input argument (attributes) must be a hash in `Api::InitialCharge` initialize method' unless attributes.is_a?(Hash)
60
+
61
+ # check to see if the attribute exists and convert string to symbol for hash key
62
+ attributes = attributes.each_with_object({}) do |(k, v), h|
63
+ raise ArgumentError, "`#{k}` is not a valid attribute in `Api::InitialCharge`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect unless self.class.attribute_map.key?(k.to_sym)
64
+
65
+ h[k.to_sym] = v
66
+ end
67
+
68
+ self.price = attributes[:price] if attributes.key?(:price)
69
+
70
+ self.description = attributes[:description] if attributes.key?(:description)
71
+
72
+ return unless attributes.key?(:expires_at)
73
+
74
+ self.expires_at = attributes[:expires_at]
75
+ end
76
+
77
+ # Show invalid properties with the reasons. Usually used together with valid?
78
+ # @return Array for valid properties with the reasons
79
+ def list_invalid_properties
80
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
81
+ []
82
+ end
83
+
84
+ # Check to see if the all the properties in the model are valid
85
+ # @return true if the model is valid
86
+ def valid?
87
+ warn '[DEPRECATED] the `valid?` method is obsolete'
88
+ true
89
+ end
90
+
91
+ # Checks equality by comparing each attribute.
92
+ # @param [Object] Object to be compared
93
+ def ==(other)
94
+ return true if equal?(other)
95
+
96
+ self.class == other.class &&
97
+ price == other.price &&
98
+ description == other.description &&
99
+ expires_at == other.expires_at
100
+ end
101
+
102
+ # @see the `==` method
103
+ # @param [Object] Object to be compared
104
+ def eql?(other)
105
+ self == other
106
+ end
107
+
108
+ # Calculates hash code according to all attributes.
109
+ # @return [Integer] Hash code
110
+ def hash
111
+ [price, description, expires_at].hash
112
+ end
113
+
114
+ # Builds the object from hash
115
+ # @param [Hash] attributes Model attributes in the form of hash
116
+ # @return [Object] Returns the model itself
117
+ def self.build_from_hash(attributes)
118
+ return nil unless attributes.is_a?(Hash)
119
+
120
+ attributes = attributes.transform_keys(&:to_sym)
121
+ transformed_hash = {}
122
+ openapi_types.each_pair do |key, type|
123
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
124
+ transformed_hash[key.to_s] = nil
125
+ elsif type =~ /\AArray<(.*)>/i
126
+ # check to ensure the input is an array given that the attribute
127
+ # is documented as an array but the input is not
128
+ transformed_hash[key.to_s] = attributes[attribute_map[key]].map { |v| _deserialize(::Regexp.last_match(1), v) } if attributes[attribute_map[key]].is_a?(Array)
129
+ elsif !attributes[attribute_map[key]].nil?
130
+ transformed_hash[key.to_s] = _deserialize(type, attributes[attribute_map[key]])
131
+ end
132
+ end
133
+ new(transformed_hash)
134
+ end
135
+
136
+ # Deserializes the data based on type
137
+ # @param string type Data type
138
+ # @param string value Value to be deserialized
139
+ # @return [Object] Deserialized data
140
+ def self._deserialize(type, value)
141
+ case type.to_sym
142
+ when :Time
143
+ Time.parse(value)
144
+ when :Date
145
+ Date.parse(value)
146
+ when :String
147
+ value.to_s
148
+ when :Integer
149
+ value.to_i
150
+ when :Float
151
+ value.to_f
152
+ when :Boolean
153
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
154
+ true
155
+ else
156
+ false
157
+ end
158
+ when :Object
159
+ # generic object (usually a Hash), return directly
160
+ value
161
+ when /\AArray<(?<inner_type>.+)>\z/
162
+ inner_type = Regexp.last_match[:inner_type]
163
+ value.map { |v| _deserialize(inner_type, v) }
164
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
165
+ k_type = Regexp.last_match[:k_type]
166
+ v_type = Regexp.last_match[:v_type]
167
+ {}.tap do |hash|
168
+ value.each do |k, v|
169
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
170
+ end
171
+ end
172
+ else # model
173
+ # models (e.g. Pet) or oneOf
174
+ klass = Api.const_get(type)
175
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
176
+ end
177
+ end
178
+
179
+ # Returns the string representation of the object
180
+ # @return [String] String presentation of the object
181
+ def to_s
182
+ to_hash.to_s
183
+ end
184
+
185
+ # to_body is an alias to to_hash (backward compatibility)
186
+ # @return [Hash] Returns the object in the form of hash
187
+ def to_body
188
+ to_hash
189
+ end
190
+
191
+ # Returns the object in the form of hash
192
+ # @return [Hash] Returns the object in the form of hash
193
+ def to_hash
194
+ hash = {}
195
+ self.class.attribute_map.each_pair do |attr, param|
196
+ value = send(attr)
197
+ if value.nil?
198
+ is_nullable = self.class.openapi_nullable.include?(attr)
199
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
200
+ end
201
+
202
+ hash[param] = _to_hash(value)
203
+ end
204
+ hash
205
+ end
206
+
207
+ # Outputs non-array value in the form of hash
208
+ # For object, use to_hash. Otherwise, just return the value
209
+ # @param [Object] value Any valid value
210
+ # @return [Hash] Returns the value in the form of hash
211
+ def _to_hash(value)
212
+ if value.is_a?(Array)
213
+ value.compact.map { |v| _to_hash(v) }
214
+ elsif value.is_a?(Hash)
215
+ {}.tap do |hash|
216
+ value.each { |k, v| hash[k] = _to_hash(v) }
217
+ end
218
+ elsif value.respond_to? :to_hash
219
+ value.to_hash
220
+ else
221
+ value
222
+ end
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,212 @@
1
+ # frozen_string_literal: true
2
+
3
+ # #api/v1/common.proto
4
+ #
5
+ # No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6
+ #
7
+ # The version of the OpenAPI document: version not set
8
+ #
9
+ # Generated by: https://openapi-generator.tech
10
+ # Generator version: 7.9.0
11
+ #
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Api
17
+ class Merchant
18
+ attr_accessor :id, :name
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ :id => :id,
24
+ :name => :name
25
+ }
26
+ end
27
+
28
+ # Returns all the JSON keys this model knows about
29
+ def self.acceptable_attributes
30
+ attribute_map.values
31
+ end
32
+
33
+ # Attribute type mapping.
34
+ def self.openapi_types
35
+ {
36
+ :id => :String,
37
+ :name => :String
38
+ }
39
+ end
40
+
41
+ # List of attributes with nullable: true
42
+ def self.openapi_nullable
43
+ Set.new([])
44
+ end
45
+
46
+ # Initializes the object
47
+ # @param [Hash] attributes Model attributes in the form of hash
48
+ def initialize(attributes = {})
49
+ raise ArgumentError, 'The input argument (attributes) must be a hash in `Api::Merchant` initialize method' unless attributes.is_a?(Hash)
50
+
51
+ # check to see if the attribute exists and convert string to symbol for hash key
52
+ attributes = attributes.each_with_object({}) do |(k, v), h|
53
+ raise ArgumentError, "`#{k}` is not a valid attribute in `Api::Merchant`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect unless self.class.attribute_map.key?(k.to_sym)
54
+
55
+ h[k.to_sym] = v
56
+ end
57
+
58
+ self.id = attributes[:id] if attributes.key?(:id)
59
+
60
+ return unless attributes.key?(:name)
61
+
62
+ self.name = attributes[:name]
63
+ end
64
+
65
+ # Show invalid properties with the reasons. Usually used together with valid?
66
+ # @return Array for valid properties with the reasons
67
+ def list_invalid_properties
68
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
69
+ []
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
+ warn '[DEPRECATED] the `valid?` method is obsolete'
76
+ true
77
+ end
78
+
79
+ # Checks equality by comparing each attribute.
80
+ # @param [Object] Object to be compared
81
+ def ==(other)
82
+ return true if equal?(other)
83
+
84
+ self.class == other.class &&
85
+ id == other.id &&
86
+ name == other.name
87
+ end
88
+
89
+ # @see the `==` method
90
+ # @param [Object] Object to be compared
91
+ def eql?(other)
92
+ self == other
93
+ end
94
+
95
+ # Calculates hash code according to all attributes.
96
+ # @return [Integer] Hash code
97
+ def hash
98
+ [id, name].hash
99
+ end
100
+
101
+ # Builds the object from hash
102
+ # @param [Hash] attributes Model attributes in the form of hash
103
+ # @return [Object] Returns the model itself
104
+ def self.build_from_hash(attributes)
105
+ return nil unless attributes.is_a?(Hash)
106
+
107
+ attributes = attributes.transform_keys(&:to_sym)
108
+ transformed_hash = {}
109
+ openapi_types.each_pair do |key, type|
110
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
111
+ transformed_hash[key.to_s] = nil
112
+ elsif 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
+ transformed_hash[key.to_s] = attributes[attribute_map[key]].map { |v| _deserialize(::Regexp.last_match(1), v) } if attributes[attribute_map[key]].is_a?(Array)
116
+ elsif !attributes[attribute_map[key]].nil?
117
+ transformed_hash[key.to_s] = _deserialize(type, attributes[attribute_map[key]])
118
+ end
119
+ end
120
+ new(transformed_hash)
121
+ end
122
+
123
+ # Deserializes the data based on type
124
+ # @param string type Data type
125
+ # @param string value Value to be deserialized
126
+ # @return [Object] Deserialized data
127
+ def self._deserialize(type, value)
128
+ case type.to_sym
129
+ when :Time
130
+ Time.parse(value)
131
+ when :Date
132
+ Date.parse(value)
133
+ when :String
134
+ value.to_s
135
+ when :Integer
136
+ value.to_i
137
+ when :Float
138
+ value.to_f
139
+ when :Boolean
140
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
141
+ true
142
+ else
143
+ false
144
+ end
145
+ when :Object
146
+ # generic object (usually a Hash), return directly
147
+ value
148
+ when /\AArray<(?<inner_type>.+)>\z/
149
+ inner_type = Regexp.last_match[:inner_type]
150
+ value.map { |v| _deserialize(inner_type, v) }
151
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
152
+ k_type = Regexp.last_match[:k_type]
153
+ v_type = Regexp.last_match[:v_type]
154
+ {}.tap do |hash|
155
+ value.each do |k, v|
156
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
157
+ end
158
+ end
159
+ else # model
160
+ # models (e.g. Pet) or oneOf
161
+ klass = Api.const_get(type)
162
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
163
+ end
164
+ end
165
+
166
+ # Returns the string representation of the object
167
+ # @return [String] String presentation of the object
168
+ def to_s
169
+ to_hash.to_s
170
+ end
171
+
172
+ # to_body is an alias to to_hash (backward compatibility)
173
+ # @return [Hash] Returns the object in the form of hash
174
+ def to_body
175
+ to_hash
176
+ end
177
+
178
+ # Returns the object in the form of hash
179
+ # @return [Hash] Returns the object in the form of hash
180
+ def to_hash
181
+ hash = {}
182
+ self.class.attribute_map.each_pair do |attr, param|
183
+ value = send(attr)
184
+ if value.nil?
185
+ is_nullable = self.class.openapi_nullable.include?(attr)
186
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
187
+ end
188
+
189
+ hash[param] = _to_hash(value)
190
+ end
191
+ hash
192
+ end
193
+
194
+ # Outputs non-array value in the form of hash
195
+ # For object, use to_hash. Otherwise, just return the value
196
+ # @param [Object] value Any valid value
197
+ # @return [Hash] Returns the value in the form of hash
198
+ def _to_hash(value)
199
+ if value.is_a?(Array)
200
+ value.compact.map { |v| _to_hash(v) }
201
+ elsif value.is_a?(Hash)
202
+ {}.tap do |hash|
203
+ value.each { |k, v| hash[k] = _to_hash(v) }
204
+ end
205
+ elsif value.respond_to? :to_hash
206
+ value.to_hash
207
+ else
208
+ value
209
+ end
210
+ end
211
+ end
212
+ end
@@ -0,0 +1,213 @@
1
+ # frozen_string_literal: true
2
+
3
+ # #api/v1/common.proto
4
+ #
5
+ # No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6
+ #
7
+ # The version of the OpenAPI document: version not set
8
+ #
9
+ # Generated by: https://openapi-generator.tech
10
+ # Generator version: 7.9.0
11
+ #
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Api
17
+ # MerchantCustomer represents a customer of merchant, associated in Jamm network.
18
+ class MerchantCustomer
19
+ attr_accessor :customer, :merchant
20
+
21
+ # Attribute mapping from ruby-style variable name to JSON key.
22
+ def self.attribute_map
23
+ {
24
+ :customer => :customer,
25
+ :merchant => :merchant
26
+ }
27
+ end
28
+
29
+ # Returns all the JSON keys this model knows about
30
+ def self.acceptable_attributes
31
+ attribute_map.values
32
+ end
33
+
34
+ # Attribute type mapping.
35
+ def self.openapi_types
36
+ {
37
+ :customer => :Customer,
38
+ :merchant => :Merchant
39
+ }
40
+ end
41
+
42
+ # List of attributes with nullable: true
43
+ def self.openapi_nullable
44
+ Set.new([])
45
+ end
46
+
47
+ # Initializes the object
48
+ # @param [Hash] attributes Model attributes in the form of hash
49
+ def initialize(attributes = {})
50
+ raise ArgumentError, 'The input argument (attributes) must be a hash in `Api::MerchantCustomer` initialize method' unless attributes.is_a?(Hash)
51
+
52
+ # check to see if the attribute exists and convert string to symbol for hash key
53
+ attributes = attributes.each_with_object({}) do |(k, v), h|
54
+ raise ArgumentError, "`#{k}` is not a valid attribute in `Api::MerchantCustomer`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect unless self.class.attribute_map.key?(k.to_sym)
55
+
56
+ h[k.to_sym] = v
57
+ end
58
+
59
+ self.customer = attributes[:customer] if attributes.key?(:customer)
60
+
61
+ return unless attributes.key?(:merchant)
62
+
63
+ self.merchant = attributes[:merchant]
64
+ end
65
+
66
+ # Show invalid properties with the reasons. Usually used together with valid?
67
+ # @return Array for valid properties with the reasons
68
+ def list_invalid_properties
69
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
70
+ []
71
+ end
72
+
73
+ # Check to see if the all the properties in the model are valid
74
+ # @return true if the model is valid
75
+ def valid?
76
+ warn '[DEPRECATED] the `valid?` method is obsolete'
77
+ true
78
+ end
79
+
80
+ # Checks equality by comparing each attribute.
81
+ # @param [Object] Object to be compared
82
+ def ==(other)
83
+ return true if equal?(other)
84
+
85
+ self.class == other.class &&
86
+ customer == other.customer &&
87
+ merchant == other.merchant
88
+ end
89
+
90
+ # @see the `==` method
91
+ # @param [Object] Object to be compared
92
+ def eql?(other)
93
+ self == other
94
+ end
95
+
96
+ # Calculates hash code according to all attributes.
97
+ # @return [Integer] Hash code
98
+ def hash
99
+ [customer, merchant].hash
100
+ end
101
+
102
+ # Builds the object from hash
103
+ # @param [Hash] attributes Model attributes in the form of hash
104
+ # @return [Object] Returns the model itself
105
+ def self.build_from_hash(attributes)
106
+ return nil unless attributes.is_a?(Hash)
107
+
108
+ attributes = attributes.transform_keys(&:to_sym)
109
+ transformed_hash = {}
110
+ openapi_types.each_pair do |key, type|
111
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
112
+ transformed_hash[key.to_s] = nil
113
+ elsif type =~ /\AArray<(.*)>/i
114
+ # check to ensure the input is an array given that the attribute
115
+ # is documented as an array but the input is not
116
+ transformed_hash[key.to_s] = attributes[attribute_map[key]].map { |v| _deserialize(::Regexp.last_match(1), v) } if attributes[attribute_map[key]].is_a?(Array)
117
+ elsif !attributes[attribute_map[key]].nil?
118
+ transformed_hash[key.to_s] = _deserialize(type, attributes[attribute_map[key]])
119
+ end
120
+ end
121
+ new(transformed_hash)
122
+ end
123
+
124
+ # Deserializes the data based on type
125
+ # @param string type Data type
126
+ # @param string value Value to be deserialized
127
+ # @return [Object] Deserialized data
128
+ def self._deserialize(type, value)
129
+ case type.to_sym
130
+ when :Time
131
+ Time.parse(value)
132
+ when :Date
133
+ Date.parse(value)
134
+ when :String
135
+ value.to_s
136
+ when :Integer
137
+ value.to_i
138
+ when :Float
139
+ value.to_f
140
+ when :Boolean
141
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
142
+ true
143
+ else
144
+ false
145
+ end
146
+ when :Object
147
+ # generic object (usually a Hash), return directly
148
+ value
149
+ when /\AArray<(?<inner_type>.+)>\z/
150
+ inner_type = Regexp.last_match[:inner_type]
151
+ value.map { |v| _deserialize(inner_type, v) }
152
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
153
+ k_type = Regexp.last_match[:k_type]
154
+ v_type = Regexp.last_match[:v_type]
155
+ {}.tap do |hash|
156
+ value.each do |k, v|
157
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
158
+ end
159
+ end
160
+ else # model
161
+ # models (e.g. Pet) or oneOf
162
+ klass = Api.const_get(type)
163
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.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 = 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