jamm 1.0.8 → 1.0.10

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 (64) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +9 -1
  4. data/Rakefile +5 -0
  5. data/lib/jamm/api/api/customer_api.rb +68 -10
  6. data/lib/jamm/api/api/healthcheck_api.rb +2 -2
  7. data/lib/jamm/api/api/payment_api.rb +145 -20
  8. data/lib/jamm/api/api/webhook_service_api.rb +82 -0
  9. data/lib/jamm/api/api_client.rb +2 -2
  10. data/lib/jamm/api/api_error.rb +2 -2
  11. data/lib/jamm/api/configuration.rb +2 -2
  12. data/lib/jamm/api/models/customer_service_update_customer_body.rb +9 -4
  13. data/lib/jamm/api/models/{rpc_status.rb → googlerpc_status.rb} +5 -5
  14. data/lib/jamm/api/models/protobuf_any.rb +2 -2
  15. data/lib/jamm/api/models/v1_add_charge_request.rb +2 -2
  16. data/lib/jamm/api/models/v1_add_charge_response.rb +2 -2
  17. data/lib/jamm/api/models/v1_buyer.rb +11 -3
  18. data/lib/jamm/api/models/v1_charge.rb +2 -2
  19. data/lib/jamm/api/models/v1_charge_message.rb +297 -0
  20. data/lib/jamm/api/models/v1_charge_message_status.rb +44 -0
  21. data/lib/jamm/api/models/v1_charge_result.rb +285 -0
  22. data/lib/jamm/api/models/v1_contract.rb +2 -2
  23. data/lib/jamm/api/models/v1_contract_message.rb +222 -0
  24. data/lib/jamm/api/models/v1_contract_status.rb +2 -2
  25. data/lib/jamm/api/models/v1_create_contract_with_charge_request.rb +2 -2
  26. data/lib/jamm/api/models/v1_create_contract_with_charge_response.rb +2 -2
  27. data/lib/jamm/api/models/v1_create_contract_without_charge_request.rb +2 -2
  28. data/lib/jamm/api/models/v1_create_contract_without_charge_response.rb +2 -2
  29. data/lib/jamm/api/models/v1_create_customer_request.rb +2 -2
  30. data/lib/jamm/api/models/v1_create_customer_response.rb +2 -2
  31. data/lib/jamm/api/models/v1_customer.rb +9 -4
  32. data/lib/jamm/api/models/v1_delete_customer_response.rb +2 -2
  33. data/lib/jamm/api/models/v1_error.rb +217 -0
  34. data/lib/jamm/api/models/v1_event_type.rb +46 -0
  35. data/lib/jamm/api/models/v1_get_charge_response.rb +212 -0
  36. data/lib/jamm/api/models/v1_get_charges_response.rb +214 -0
  37. data/lib/jamm/api/models/v1_get_contract_response.rb +13 -13
  38. data/lib/jamm/api/models/v1_get_customer_response.rb +2 -2
  39. data/lib/jamm/api/models/v1_initial_charge.rb +2 -2
  40. data/lib/jamm/api/models/v1_merchant.rb +2 -2
  41. data/lib/jamm/api/models/v1_merchant_customer.rb +2 -2
  42. data/lib/jamm/api/models/v1_merchant_webhook_message.rb +259 -0
  43. data/lib/jamm/api/models/v1_message_response.rb +217 -0
  44. data/lib/jamm/api/models/v1_pagination.rb +212 -0
  45. data/lib/jamm/api/models/v1_payment_link.rb +2 -2
  46. data/lib/jamm/api/models/v1_ping_response.rb +2 -2
  47. data/lib/jamm/api/models/v1_update_customer_response.rb +2 -2
  48. data/lib/jamm/api/models/v1_url.rb +2 -2
  49. data/lib/jamm/api/models/v1_withdraw_request.rb +212 -0
  50. data/lib/jamm/api/models/v1_withdraw_response.rb +212 -0
  51. data/lib/jamm/api/version.rb +2 -2
  52. data/lib/jamm/api.rb +17 -3
  53. data/lib/jamm/api_patches.rb +14 -0
  54. data/lib/jamm/charge.rb +43 -0
  55. data/lib/jamm/client.rb +1 -1
  56. data/lib/jamm/contract.rb +35 -0
  57. data/lib/jamm/customer.rb +24 -9
  58. data/lib/jamm/healthcheck.rb +14 -0
  59. data/lib/jamm/openapi.rb +10 -0
  60. data/lib/jamm/version.rb +1 -1
  61. data/lib/jamm/webhook.rb +46 -0
  62. data/lib/jamm.rb +16 -14
  63. metadata +23 -4
  64. data/lib/jamm/payment.rb +0 -27
@@ -0,0 +1,217 @@
1
+ # frozen_string_literal: true
2
+
3
+ # #Jamm API
4
+ #
5
+ # No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6
+ #
7
+ # The version of the OpenAPI document: 1.0
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
+ # Generic error type.
18
+ class Error
19
+ # Jamm defined error code.
20
+ attr_accessor :code
21
+
22
+ # Human readable error message.
23
+ attr_accessor :message
24
+
25
+ # Attribute mapping from ruby-style variable name to JSON key.
26
+ def self.attribute_map
27
+ {
28
+ :code => :code,
29
+ :message => :message
30
+ }
31
+ end
32
+
33
+ # Returns all the JSON keys this model knows about
34
+ def self.acceptable_attributes
35
+ attribute_map.values
36
+ end
37
+
38
+ # Attribute type mapping.
39
+ def self.openapi_types
40
+ {
41
+ :code => :String,
42
+ :message => :String
43
+ }
44
+ end
45
+
46
+ # List of attributes with nullable: true
47
+ def self.openapi_nullable
48
+ Set.new([])
49
+ end
50
+
51
+ # Initializes the object
52
+ # @param [Hash] attributes Model attributes in the form of hash
53
+ def initialize(attributes = {})
54
+ raise ArgumentError, 'The input argument (attributes) must be a hash in `Api::Error` initialize method' unless attributes.is_a?(Hash)
55
+
56
+ # check to see if the attribute exists and convert string to symbol for hash key
57
+ attributes = attributes.each_with_object({}) do |(k, v), h|
58
+ raise ArgumentError, "`#{k}` is not a valid attribute in `Api::Error`. 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)
59
+
60
+ h[k.to_sym] = v
61
+ end
62
+
63
+ self.code = attributes[:code] if attributes.key?(:code)
64
+
65
+ return unless attributes.key?(:message)
66
+
67
+ self.message = attributes[:message]
68
+ end
69
+
70
+ # Show invalid properties with the reasons. Usually used together with valid?
71
+ # @return Array for valid properties with the reasons
72
+ def list_invalid_properties
73
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
74
+ []
75
+ end
76
+
77
+ # Check to see if the all the properties in the model are valid
78
+ # @return true if the model is valid
79
+ def valid?
80
+ warn '[DEPRECATED] the `valid?` method is obsolete'
81
+ true
82
+ end
83
+
84
+ # Checks equality by comparing each attribute.
85
+ # @param [Object] Object to be compared
86
+ def ==(other)
87
+ return true if equal?(other)
88
+
89
+ self.class == other.class &&
90
+ code == other.code &&
91
+ message == other.message
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
+ [code, message].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
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # #Jamm API
4
+ #
5
+ # No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6
+ #
7
+ # The version of the OpenAPI document: 1.0
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 EventType
18
+ UNSPECIFIED = 'EVENT_TYPE_UNSPECIFIED'
19
+ CHARGE_CREATED = 'EVENT_TYPE_CHARGE_CREATED'
20
+ CHARGE_UPDATED = 'EVENT_TYPE_CHARGE_UPDATED'
21
+ CHARGE_SUCCESS = 'EVENT_TYPE_CHARGE_SUCCESS'
22
+ CHARGE_FAIL = 'EVENT_TYPE_CHARGE_FAIL'
23
+ CONTRACT_ACTIVATED = 'EVENT_TYPE_CONTRACT_ACTIVATED'
24
+ TESTING = 'EVENT_TYPE_TESTING'
25
+
26
+ def self.all_vars
27
+ @all_vars ||= [UNSPECIFIED, CHARGE_CREATED, CHARGE_UPDATED, CHARGE_SUCCESS, CHARGE_FAIL, CONTRACT_ACTIVATED, TESTING].freeze
28
+ end
29
+
30
+ # Builds the enum from string
31
+ # @param [String] The enum value in the form of the string
32
+ # @return [String] The enum value
33
+ def self.build_from_hash(value)
34
+ new.build_from_hash(value)
35
+ end
36
+
37
+ # Builds the enum from string
38
+ # @param [String] The enum value in the form of the string
39
+ # @return [String] The enum value
40
+ def build_from_hash(value)
41
+ return value if EventType.all_vars.include?(value)
42
+
43
+ raise "Invalid ENUM value #{value} for class #EventType"
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,212 @@
1
+ # frozen_string_literal: true
2
+
3
+ # #Jamm API
4
+ #
5
+ # No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6
+ #
7
+ # The version of the OpenAPI document: 1.0
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 GetChargeResponse
18
+ attr_accessor :charge, :customer
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ :charge => :charge,
24
+ :customer => :customer
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
+ :charge => :ChargeResult,
37
+ :customer => :Customer
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::GetChargeResponse` 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::GetChargeResponse`. 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.charge = attributes[:charge] if attributes.key?(:charge)
59
+
60
+ return unless attributes.key?(:customer)
61
+
62
+ self.customer = attributes[:customer]
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
+ charge == other.charge &&
86
+ customer == other.customer
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
+ [charge, customer].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,214 @@
1
+ # frozen_string_literal: true
2
+
3
+ # #Jamm API
4
+ #
5
+ # No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6
+ #
7
+ # The version of the OpenAPI document: 1.0
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 GetChargesResponse
18
+ attr_accessor :charges, :customer
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ :charges => :charges,
24
+ :customer => :customer
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
+ :charges => :'Array<ChargeResult>',
37
+ :customer => :Customer
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::GetChargesResponse` 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::GetChargesResponse`. 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
+ if attributes.key?(:charges) && (value = attributes[:charges]).is_a?(Array)
59
+ self.charges = value
60
+ end
61
+
62
+ return unless attributes.key?(:customer)
63
+
64
+ self.customer = attributes[:customer]
65
+ end
66
+
67
+ # Show invalid properties with the reasons. Usually used together with valid?
68
+ # @return Array for valid properties with the reasons
69
+ def list_invalid_properties
70
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
71
+ []
72
+ end
73
+
74
+ # Check to see if the all the properties in the model are valid
75
+ # @return true if the model is valid
76
+ def valid?
77
+ warn '[DEPRECATED] the `valid?` method is obsolete'
78
+ true
79
+ end
80
+
81
+ # Checks equality by comparing each attribute.
82
+ # @param [Object] Object to be compared
83
+ def ==(other)
84
+ return true if equal?(other)
85
+
86
+ self.class == other.class &&
87
+ charges == other.charges &&
88
+ customer == other.customer
89
+ end
90
+
91
+ # @see the `==` method
92
+ # @param [Object] Object to be compared
93
+ def eql?(other)
94
+ self == other
95
+ end
96
+
97
+ # Calculates hash code according to all attributes.
98
+ # @return [Integer] Hash code
99
+ def hash
100
+ [charges, customer].hash
101
+ end
102
+
103
+ # Builds the object from hash
104
+ # @param [Hash] attributes Model attributes in the form of hash
105
+ # @return [Object] Returns the model itself
106
+ def self.build_from_hash(attributes)
107
+ return nil unless attributes.is_a?(Hash)
108
+
109
+ attributes = attributes.transform_keys(&:to_sym)
110
+ transformed_hash = {}
111
+ openapi_types.each_pair do |key, type|
112
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
113
+ transformed_hash[key.to_s] = nil
114
+ elsif type =~ /\AArray<(.*)>/i
115
+ # check to ensure the input is an array given that the attribute
116
+ # is documented as an array but the input is not
117
+ 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)
118
+ elsif !attributes[attribute_map[key]].nil?
119
+ transformed_hash[key.to_s] = _deserialize(type, attributes[attribute_map[key]])
120
+ end
121
+ end
122
+ new(transformed_hash)
123
+ end
124
+
125
+ # Deserializes the data based on type
126
+ # @param string type Data type
127
+ # @param string value Value to be deserialized
128
+ # @return [Object] Deserialized data
129
+ def self._deserialize(type, value)
130
+ case type.to_sym
131
+ when :Time
132
+ Time.parse(value)
133
+ when :Date
134
+ Date.parse(value)
135
+ when :String
136
+ value.to_s
137
+ when :Integer
138
+ value.to_i
139
+ when :Float
140
+ value.to_f
141
+ when :Boolean
142
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
143
+ true
144
+ else
145
+ false
146
+ end
147
+ when :Object
148
+ # generic object (usually a Hash), return directly
149
+ value
150
+ when /\AArray<(?<inner_type>.+)>\z/
151
+ inner_type = Regexp.last_match[:inner_type]
152
+ value.map { |v| _deserialize(inner_type, v) }
153
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
154
+ k_type = Regexp.last_match[:k_type]
155
+ v_type = Regexp.last_match[:v_type]
156
+ {}.tap do |hash|
157
+ value.each do |k, v|
158
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
159
+ end
160
+ end
161
+ else # model
162
+ # models (e.g. Pet) or oneOf
163
+ klass = Api.const_get(type)
164
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
165
+ end
166
+ end
167
+
168
+ # Returns the string representation of the object
169
+ # @return [String] String presentation of the object
170
+ def to_s
171
+ to_hash.to_s
172
+ end
173
+
174
+ # to_body is an alias to to_hash (backward compatibility)
175
+ # @return [Hash] Returns the object in the form of hash
176
+ def to_body
177
+ to_hash
178
+ end
179
+
180
+ # Returns the object in the form of hash
181
+ # @return [Hash] Returns the object in the form of hash
182
+ def to_hash
183
+ hash = {}
184
+ self.class.attribute_map.each_pair do |attr, param|
185
+ value = send(attr)
186
+ if value.nil?
187
+ is_nullable = self.class.openapi_nullable.include?(attr)
188
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
189
+ end
190
+
191
+ hash[param] = _to_hash(value)
192
+ end
193
+ hash
194
+ end
195
+
196
+ # Outputs non-array value in the form of hash
197
+ # For object, use to_hash. Otherwise, just return the value
198
+ # @param [Object] value Any valid value
199
+ # @return [Hash] Returns the value in the form of hash
200
+ def _to_hash(value)
201
+ if value.is_a?(Array)
202
+ value.compact.map { |v| _to_hash(v) }
203
+ elsif value.is_a?(Hash)
204
+ {}.tap do |hash|
205
+ value.each { |k, v| hash[k] = _to_hash(v) }
206
+ end
207
+ elsif value.respond_to? :to_hash
208
+ value.to_hash
209
+ else
210
+ value
211
+ end
212
+ end
213
+ end
214
+ end