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,233 @@
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
+ # Charge represents a charge information for the customer.
18
+ class Charge
19
+ # 決済ID (例: chg-1234567890) @gotags: validate:\"required\"
20
+ attr_accessor :id
21
+
22
+ # 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\"
23
+ attr_accessor :price
24
+
25
+ # Description is an arbitrary string for merchant to track the charge. This information is displayed on Merchant Dashboard. 決済の説明。ショップが決済を追跡するための任意の文字列です。 @gotags: validate:\"required\"
26
+ attr_accessor :description
27
+
28
+ # Merchant can optionally set the expiry date for the payment. Defaults to 90 minutes if not specified. 決済の有効期限。未指定の場合は90分後に自動失効します。
29
+ attr_accessor :expires_at
30
+
31
+ # Attribute mapping from ruby-style variable name to JSON key.
32
+ def self.attribute_map
33
+ {
34
+ :id => :id,
35
+ :price => :price,
36
+ :description => :description,
37
+ :expires_at => :expiresAt
38
+ }
39
+ end
40
+
41
+ # Returns all the JSON keys this model knows about
42
+ def self.acceptable_attributes
43
+ attribute_map.values
44
+ end
45
+
46
+ # Attribute type mapping.
47
+ def self.openapi_types
48
+ {
49
+ :id => :String,
50
+ :price => :Integer,
51
+ :description => :String,
52
+ :expires_at => :Time
53
+ }
54
+ end
55
+
56
+ # List of attributes with nullable: true
57
+ def self.openapi_nullable
58
+ Set.new([])
59
+ end
60
+
61
+ # Initializes the object
62
+ # @param [Hash] attributes Model attributes in the form of hash
63
+ def initialize(attributes = {})
64
+ raise ArgumentError, 'The input argument (attributes) must be a hash in `Api::Charge` initialize method' unless attributes.is_a?(Hash)
65
+
66
+ # check to see if the attribute exists and convert string to symbol for hash key
67
+ attributes = attributes.each_with_object({}) do |(k, v), h|
68
+ raise ArgumentError, "`#{k}` is not a valid attribute in `Api::Charge`. 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)
69
+
70
+ h[k.to_sym] = v
71
+ end
72
+
73
+ self.id = attributes[:id] if attributes.key?(:id)
74
+
75
+ self.price = attributes[:price] if attributes.key?(:price)
76
+
77
+ self.description = attributes[:description] if attributes.key?(:description)
78
+
79
+ return unless attributes.key?(:expires_at)
80
+
81
+ self.expires_at = attributes[:expires_at]
82
+ end
83
+
84
+ # Show invalid properties with the reasons. Usually used together with valid?
85
+ # @return Array for valid properties with the reasons
86
+ def list_invalid_properties
87
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
88
+ []
89
+ end
90
+
91
+ # Check to see if the all the properties in the model are valid
92
+ # @return true if the model is valid
93
+ def valid?
94
+ warn '[DEPRECATED] the `valid?` method is obsolete'
95
+ true
96
+ end
97
+
98
+ # Checks equality by comparing each attribute.
99
+ # @param [Object] Object to be compared
100
+ def ==(other)
101
+ return true if equal?(other)
102
+
103
+ self.class == other.class &&
104
+ id == other.id &&
105
+ price == other.price &&
106
+ description == other.description &&
107
+ expires_at == other.expires_at
108
+ end
109
+
110
+ # @see the `==` method
111
+ # @param [Object] Object to be compared
112
+ def eql?(other)
113
+ self == other
114
+ end
115
+
116
+ # Calculates hash code according to all attributes.
117
+ # @return [Integer] Hash code
118
+ def hash
119
+ [id, price, description, expires_at].hash
120
+ end
121
+
122
+ # Builds the object from hash
123
+ # @param [Hash] attributes Model attributes in the form of hash
124
+ # @return [Object] Returns the model itself
125
+ def self.build_from_hash(attributes)
126
+ return nil unless attributes.is_a?(Hash)
127
+
128
+ attributes = attributes.transform_keys(&:to_sym)
129
+ transformed_hash = {}
130
+ openapi_types.each_pair do |key, type|
131
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
132
+ transformed_hash[key.to_s] = nil
133
+ elsif type =~ /\AArray<(.*)>/i
134
+ # check to ensure the input is an array given that the attribute
135
+ # is documented as an array but the input is not
136
+ 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)
137
+ elsif !attributes[attribute_map[key]].nil?
138
+ transformed_hash[key.to_s] = _deserialize(type, attributes[attribute_map[key]])
139
+ end
140
+ end
141
+ new(transformed_hash)
142
+ end
143
+
144
+ # Deserializes the data based on type
145
+ # @param string type Data type
146
+ # @param string value Value to be deserialized
147
+ # @return [Object] Deserialized data
148
+ def self._deserialize(type, value)
149
+ case type.to_sym
150
+ when :Time
151
+ Time.parse(value)
152
+ when :Date
153
+ Date.parse(value)
154
+ when :String
155
+ value.to_s
156
+ when :Integer
157
+ value.to_i
158
+ when :Float
159
+ value.to_f
160
+ when :Boolean
161
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
162
+ true
163
+ else
164
+ false
165
+ end
166
+ when :Object
167
+ # generic object (usually a Hash), return directly
168
+ value
169
+ when /\AArray<(?<inner_type>.+)>\z/
170
+ inner_type = Regexp.last_match[:inner_type]
171
+ value.map { |v| _deserialize(inner_type, v) }
172
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
173
+ k_type = Regexp.last_match[:k_type]
174
+ v_type = Regexp.last_match[:v_type]
175
+ {}.tap do |hash|
176
+ value.each do |k, v|
177
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
178
+ end
179
+ end
180
+ else # model
181
+ # models (e.g. Pet) or oneOf
182
+ klass = Api.const_get(type)
183
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
184
+ end
185
+ end
186
+
187
+ # Returns the string representation of the object
188
+ # @return [String] String presentation of the object
189
+ def to_s
190
+ to_hash.to_s
191
+ end
192
+
193
+ # to_body is an alias to to_hash (backward compatibility)
194
+ # @return [Hash] Returns the object in the form of hash
195
+ def to_body
196
+ to_hash
197
+ end
198
+
199
+ # Returns the object in the form of hash
200
+ # @return [Hash] Returns the object in the form of hash
201
+ def to_hash
202
+ hash = {}
203
+ self.class.attribute_map.each_pair do |attr, param|
204
+ value = send(attr)
205
+ if value.nil?
206
+ is_nullable = self.class.openapi_nullable.include?(attr)
207
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
208
+ end
209
+
210
+ hash[param] = _to_hash(value)
211
+ end
212
+ hash
213
+ end
214
+
215
+ # Outputs non-array value in the form of hash
216
+ # For object, use to_hash. Otherwise, just return the value
217
+ # @param [Object] value Any valid value
218
+ # @return [Hash] Returns the value in the form of hash
219
+ def _to_hash(value)
220
+ if value.is_a?(Array)
221
+ value.compact.map { |v| _to_hash(v) }
222
+ elsif value.is_a?(Hash)
223
+ {}.tap do |hash|
224
+ value.each { |k, v| hash[k] = _to_hash(v) }
225
+ end
226
+ elsif value.respond_to? :to_hash
227
+ value.to_hash
228
+ else
229
+ value
230
+ end
231
+ end
232
+ end
233
+ end
@@ -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
+ # Contract represents a payment agreement between the Jamm customer and the merchant. Merchant must use the contract ID to further make a charge, therefore please persist this ID into your database. 契約はJammの顧客とショップの間の支払い契約を表します。 ショップは契約IDを使用して決済を行う必要がありますので、このIDはデータベースに保存してください。
18
+ class Contract
19
+ # 契約ID (例: con-1234567890) @gotags: validate:\"required\"
20
+ attr_accessor :id
21
+
22
+ # Created date of the contract. 契約の作成日時。
23
+ attr_accessor :created_at
24
+
25
+ # Updated date of the contract. 契約の更新日時。
26
+ attr_accessor :updated_at
27
+
28
+ # Attribute mapping from ruby-style variable name to JSON key.
29
+ def self.attribute_map
30
+ {
31
+ :id => :id,
32
+ :created_at => :createdAt,
33
+ :updated_at => :updatedAt
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
+ :id => :String,
46
+ :created_at => :Time,
47
+ :updated_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::Contract` 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::Contract`. 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.id = attributes[:id] if attributes.key?(:id)
69
+
70
+ self.created_at = attributes[:created_at] if attributes.key?(:created_at)
71
+
72
+ return unless attributes.key?(:updated_at)
73
+
74
+ self.updated_at = attributes[:updated_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
+ id == other.id &&
98
+ created_at == other.created_at &&
99
+ updated_at == other.updated_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
+ [id, created_at, updated_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,217 @@
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 CreateContractWithChargeRequest
18
+ attr_accessor :buyer, :charge, :redirect
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ :buyer => :buyer,
24
+ :charge => :charge,
25
+ :redirect => :redirect
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
+ :buyer => :Buyer,
38
+ :charge => :InitialCharge,
39
+ :redirect => :URL
40
+ }
41
+ end
42
+
43
+ # List of attributes with nullable: true
44
+ def self.openapi_nullable
45
+ Set.new([])
46
+ end
47
+
48
+ # Initializes the object
49
+ # @param [Hash] attributes Model attributes in the form of hash
50
+ def initialize(attributes = {})
51
+ raise ArgumentError, 'The input argument (attributes) must be a hash in `Api::CreateContractWithChargeRequest` initialize method' unless attributes.is_a?(Hash)
52
+
53
+ # check to see if the attribute exists and convert string to symbol for hash key
54
+ attributes = attributes.each_with_object({}) do |(k, v), h|
55
+ raise ArgumentError, "`#{k}` is not a valid attribute in `Api::CreateContractWithChargeRequest`. 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)
56
+
57
+ h[k.to_sym] = v
58
+ end
59
+
60
+ self.buyer = attributes[:buyer] if attributes.key?(:buyer)
61
+
62
+ self.charge = attributes[:charge] if attributes.key?(:charge)
63
+
64
+ return unless attributes.key?(:redirect)
65
+
66
+ self.redirect = attributes[:redirect]
67
+ end
68
+
69
+ # Show invalid properties with the reasons. Usually used together with valid?
70
+ # @return Array for valid properties with the reasons
71
+ def list_invalid_properties
72
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
73
+ []
74
+ end
75
+
76
+ # Check to see if the all the properties in the model are valid
77
+ # @return true if the model is valid
78
+ def valid?
79
+ warn '[DEPRECATED] the `valid?` method is obsolete'
80
+ true
81
+ end
82
+
83
+ # Checks equality by comparing each attribute.
84
+ # @param [Object] Object to be compared
85
+ def ==(other)
86
+ return true if equal?(other)
87
+
88
+ self.class == other.class &&
89
+ buyer == other.buyer &&
90
+ charge == other.charge &&
91
+ redirect == other.redirect
92
+ end
93
+
94
+ # @see the `==` method
95
+ # @param [Object] Object to be compared
96
+ def eql?(other)
97
+ self == other
98
+ end
99
+
100
+ # Calculates hash code according to all attributes.
101
+ # @return [Integer] Hash code
102
+ def hash
103
+ [buyer, charge, redirect].hash
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 self.build_from_hash(attributes)
110
+ return nil unless attributes.is_a?(Hash)
111
+
112
+ attributes = attributes.transform_keys(&:to_sym)
113
+ transformed_hash = {}
114
+ openapi_types.each_pair do |key, type|
115
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
116
+ transformed_hash[key.to_s] = nil
117
+ elsif type =~ /\AArray<(.*)>/i
118
+ # check to ensure the input is an array given that the attribute
119
+ # is documented as an array but the input is not
120
+ 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)
121
+ elsif !attributes[attribute_map[key]].nil?
122
+ transformed_hash[key.to_s] = _deserialize(type, attributes[attribute_map[key]])
123
+ end
124
+ end
125
+ new(transformed_hash)
126
+ end
127
+
128
+ # Deserializes the data based on type
129
+ # @param string type Data type
130
+ # @param string value Value to be deserialized
131
+ # @return [Object] Deserialized data
132
+ def self._deserialize(type, value)
133
+ case type.to_sym
134
+ when :Time
135
+ Time.parse(value)
136
+ when :Date
137
+ Date.parse(value)
138
+ when :String
139
+ value.to_s
140
+ when :Integer
141
+ value.to_i
142
+ when :Float
143
+ value.to_f
144
+ when :Boolean
145
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
146
+ true
147
+ else
148
+ false
149
+ end
150
+ when :Object
151
+ # generic object (usually a Hash), return directly
152
+ value
153
+ when /\AArray<(?<inner_type>.+)>\z/
154
+ inner_type = Regexp.last_match[:inner_type]
155
+ value.map { |v| _deserialize(inner_type, v) }
156
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
157
+ k_type = Regexp.last_match[:k_type]
158
+ v_type = Regexp.last_match[:v_type]
159
+ {}.tap do |hash|
160
+ value.each do |k, v|
161
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
162
+ end
163
+ end
164
+ else # model
165
+ # models (e.g. Pet) or oneOf
166
+ klass = Api.const_get(type)
167
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
168
+ end
169
+ end
170
+
171
+ # Returns the string representation of the object
172
+ # @return [String] String presentation of the object
173
+ def to_s
174
+ to_hash.to_s
175
+ end
176
+
177
+ # to_body is an alias to to_hash (backward compatibility)
178
+ # @return [Hash] Returns the object in the form of hash
179
+ def to_body
180
+ to_hash
181
+ end
182
+
183
+ # Returns the object in the form of hash
184
+ # @return [Hash] Returns the object in the form of hash
185
+ def to_hash
186
+ hash = {}
187
+ self.class.attribute_map.each_pair do |attr, param|
188
+ value = send(attr)
189
+ if value.nil?
190
+ is_nullable = self.class.openapi_nullable.include?(attr)
191
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
192
+ end
193
+
194
+ hash[param] = _to_hash(value)
195
+ end
196
+ hash
197
+ end
198
+
199
+ # Outputs non-array value in the form of hash
200
+ # For object, use to_hash. Otherwise, just return the value
201
+ # @param [Object] value Any valid value
202
+ # @return [Hash] Returns the value in the form of hash
203
+ def _to_hash(value)
204
+ if value.is_a?(Array)
205
+ value.compact.map { |v| _to_hash(v) }
206
+ elsif value.is_a?(Hash)
207
+ {}.tap do |hash|
208
+ value.each { |k, v| hash[k] = _to_hash(v) }
209
+ end
210
+ elsif value.respond_to? :to_hash
211
+ value.to_hash
212
+ else
213
+ value
214
+ end
215
+ end
216
+ end
217
+ end