yapstone-payouts 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/Gemfile.lock +79 -0
  4. data/README.md +150 -0
  5. data/Rakefile +10 -0
  6. data/docs/AuthenticationApi.md +58 -0
  7. data/docs/CancelDepositRequest.md +17 -0
  8. data/docs/CancelRequest.md +19 -0
  9. data/docs/Deposit.md +31 -0
  10. data/docs/DepositDetail.md +23 -0
  11. data/docs/DepositListResponse.md +19 -0
  12. data/docs/DepositRequest.md +19 -0
  13. data/docs/Disbursement.md +27 -0
  14. data/docs/DisbursementListResponse.md +19 -0
  15. data/docs/DisbursementRequest.md +19 -0
  16. data/docs/FundingPool.md +31 -0
  17. data/docs/InlineResponse200.md +25 -0
  18. data/docs/Meta.md +17 -0
  19. data/docs/Page.md +21 -0
  20. data/docs/PaymentTransactionDetail.md +31 -0
  21. data/docs/PayoutsApi.md +2065 -0
  22. data/docs/PoolListResponse.md +21 -0
  23. data/docs/Reimbursement.md +27 -0
  24. data/docs/ReimbursementListResponse.md +19 -0
  25. data/docs/ReimbursementRequest.md +19 -0
  26. data/docs/ReverseDisbursementRequest.md +19 -0
  27. data/docs/ReverseReimbursementRequest.md +19 -0
  28. data/docs/StatusChanges.md +19 -0
  29. data/git_push.sh +55 -0
  30. data/lib/yapstone-payouts.rb +62 -0
  31. data/lib/yapstone-payouts/api/authentication_api.rb +92 -0
  32. data/lib/yapstone-payouts/api/payouts_api.rb +2462 -0
  33. data/lib/yapstone-payouts/api_client.rb +386 -0
  34. data/lib/yapstone-payouts/api_error.rb +57 -0
  35. data/lib/yapstone-payouts/configuration.rb +249 -0
  36. data/lib/yapstone-payouts/models/cancel_deposit_request.rb +235 -0
  37. data/lib/yapstone-payouts/models/cancel_request.rb +244 -0
  38. data/lib/yapstone-payouts/models/deposit.rb +261 -0
  39. data/lib/yapstone-payouts/models/deposit_detail.rb +233 -0
  40. data/lib/yapstone-payouts/models/deposit_list_response.rb +207 -0
  41. data/lib/yapstone-payouts/models/deposit_request.rb +217 -0
  42. data/lib/yapstone-payouts/models/disbursement.rb +243 -0
  43. data/lib/yapstone-payouts/models/disbursement_list_response.rb +207 -0
  44. data/lib/yapstone-payouts/models/disbursement_request.rb +217 -0
  45. data/lib/yapstone-payouts/models/funding_pool.rb +259 -0
  46. data/lib/yapstone-payouts/models/inline_response200.rb +232 -0
  47. data/lib/yapstone-payouts/models/meta.rb +197 -0
  48. data/lib/yapstone-payouts/models/page.rb +218 -0
  49. data/lib/yapstone-payouts/models/payment_transaction_detail.rb +279 -0
  50. data/lib/yapstone-payouts/models/pool_list_response.rb +216 -0
  51. data/lib/yapstone-payouts/models/reimbursement.rb +243 -0
  52. data/lib/yapstone-payouts/models/reimbursement_list_response.rb +207 -0
  53. data/lib/yapstone-payouts/models/reimbursement_request.rb +217 -0
  54. data/lib/yapstone-payouts/models/reverse_disbursement_request.rb +215 -0
  55. data/lib/yapstone-payouts/models/reverse_reimbursement_request.rb +215 -0
  56. data/lib/yapstone-payouts/models/status_changes.rb +205 -0
  57. data/lib/yapstone-payouts/version.rb +15 -0
  58. data/spec/api/authentication_api_spec.rb +48 -0
  59. data/spec/api/payouts_api_spec.rb +506 -0
  60. data/spec/api_client_spec.rb +226 -0
  61. data/spec/configuration_spec.rb +42 -0
  62. data/spec/models/cancel_deposit_request_spec.rb +45 -0
  63. data/spec/models/cancel_request_spec.rb +51 -0
  64. data/spec/models/deposit_detail_spec.rb +59 -0
  65. data/spec/models/deposit_list_response_spec.rb +47 -0
  66. data/spec/models/deposit_request_spec.rb +47 -0
  67. data/spec/models/deposit_spec.rb +83 -0
  68. data/spec/models/disbursement_list_response_spec.rb +47 -0
  69. data/spec/models/disbursement_request_spec.rb +47 -0
  70. data/spec/models/disbursement_spec.rb +71 -0
  71. data/spec/models/funding_pool_spec.rb +83 -0
  72. data/spec/models/inline_response200_spec.rb +65 -0
  73. data/spec/models/meta_spec.rb +41 -0
  74. data/spec/models/page_spec.rb +53 -0
  75. data/spec/models/payment_transaction_detail_spec.rb +83 -0
  76. data/spec/models/pool_list_response_spec.rb +53 -0
  77. data/spec/models/reimbursement_list_response_spec.rb +47 -0
  78. data/spec/models/reimbursement_request_spec.rb +47 -0
  79. data/spec/models/reimbursement_spec.rb +71 -0
  80. data/spec/models/reverse_disbursement_request_spec.rb +47 -0
  81. data/spec/models/reverse_reimbursement_request_spec.rb +47 -0
  82. data/spec/models/status_changes_spec.rb +47 -0
  83. data/spec/spec_helper.rb +111 -0
  84. data/yapstone-payouts.gemspec +45 -0
  85. metadata +333 -0
@@ -0,0 +1,217 @@
1
+ =begin
2
+ #Payout Orchestrator API
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ The version of the OpenAPI document: 1.0.3
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.1.0-SNAPSHOT
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module Yapstone
16
+ class ReimbursementRequest
17
+ attr_accessor :currency
18
+
19
+ attr_accessor :reimbursements
20
+
21
+ # Attribute mapping from ruby-style variable name to JSON key.
22
+ def self.attribute_map
23
+ {
24
+ :'currency' => :'currency',
25
+ :'reimbursements' => :'reimbursements'
26
+ }
27
+ end
28
+
29
+ # Attribute type mapping.
30
+ def self.openapi_types
31
+ {
32
+ :'currency' => :'String',
33
+ :'reimbursements' => :'Array<PaymentTransactionDetail>'
34
+ }
35
+ end
36
+
37
+ # Initializes the object
38
+ # @param [Hash] attributes Model attributes in the form of hash
39
+ def initialize(attributes = {})
40
+ if (!attributes.is_a?(Hash))
41
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Yapstone::ReimbursementRequest` initialize method"
42
+ end
43
+
44
+ # check to see if the attribute exists and convert string to symbol for hash key
45
+ attributes = attributes.each_with_object({}) { |(k, v), h|
46
+ if (!self.class.attribute_map.key?(k.to_sym))
47
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Yapstone::ReimbursementRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
48
+ end
49
+ h[k.to_sym] = v
50
+ }
51
+
52
+ if attributes.key?(:'currency')
53
+ self.currency = attributes[:'currency']
54
+ end
55
+
56
+ if attributes.key?(:'reimbursements')
57
+ if (value = attributes[:'reimbursements']).is_a?(Array)
58
+ self.reimbursements = value
59
+ end
60
+ end
61
+ end
62
+
63
+ # Show invalid properties with the reasons. Usually used together with valid?
64
+ # @return Array for valid properties with the reasons
65
+ def list_invalid_properties
66
+ invalid_properties = Array.new
67
+ if @currency.nil?
68
+ invalid_properties.push('invalid value for "currency", currency cannot be nil.')
69
+ end
70
+
71
+ if @reimbursements.nil?
72
+ invalid_properties.push('invalid value for "reimbursements", reimbursements cannot be nil.')
73
+ end
74
+
75
+ invalid_properties
76
+ end
77
+
78
+ # Check to see if the all the properties in the model are valid
79
+ # @return true if the model is valid
80
+ def valid?
81
+ return false if @currency.nil?
82
+ return false if @reimbursements.nil?
83
+ true
84
+ end
85
+
86
+ # Checks equality by comparing each attribute.
87
+ # @param [Object] Object to be compared
88
+ def ==(o)
89
+ return true if self.equal?(o)
90
+ self.class == o.class &&
91
+ currency == o.currency &&
92
+ reimbursements == o.reimbursements
93
+ end
94
+
95
+ # @see the `==` method
96
+ # @param [Object] Object to be compared
97
+ def eql?(o)
98
+ self == o
99
+ end
100
+
101
+ # Calculates hash code according to all attributes.
102
+ # @return [Integer] Hash code
103
+ def hash
104
+ [currency, reimbursements].hash
105
+ end
106
+
107
+ # Builds the object from hash
108
+ # @param [Hash] attributes Model attributes in the form of hash
109
+ # @return [Object] Returns the model itself
110
+ def self.build_from_hash(attributes)
111
+ new.build_from_hash(attributes)
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 build_from_hash(attributes)
118
+ return nil unless attributes.is_a?(Hash)
119
+ self.class.openapi_types.each_pair do |key, type|
120
+ if type =~ /\AArray<(.*)>/i
121
+ # check to ensure the input is an array given that the attribute
122
+ # is documented as an array but the input is not
123
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
124
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
125
+ end
126
+ elsif !attributes[self.class.attribute_map[key]].nil?
127
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
128
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
129
+ end
130
+
131
+ self
132
+ end
133
+
134
+ # Deserializes the data based on type
135
+ # @param string type Data type
136
+ # @param string value Value to be deserialized
137
+ # @return [Object] Deserialized data
138
+ def _deserialize(type, value)
139
+ case type.to_sym
140
+ when :DateTime
141
+ DateTime.parse(value)
142
+ when :Date
143
+ Date.parse(value)
144
+ when :String
145
+ value.to_s
146
+ when :Integer
147
+ value.to_i
148
+ when :Float
149
+ value.to_f
150
+ when :Boolean
151
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
152
+ true
153
+ else
154
+ false
155
+ end
156
+ when :Object
157
+ # generic object (usually a Hash), return directly
158
+ value
159
+ when /\AArray<(?<inner_type>.+)>\z/
160
+ inner_type = Regexp.last_match[:inner_type]
161
+ value.map { |v| _deserialize(inner_type, v) }
162
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
163
+ k_type = Regexp.last_match[:k_type]
164
+ v_type = Regexp.last_match[:v_type]
165
+ {}.tap do |hash|
166
+ value.each do |k, v|
167
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
168
+ end
169
+ end
170
+ else # model
171
+ Yapstone.const_get(type).build_from_hash(value)
172
+ end
173
+ end
174
+
175
+ # Returns the string representation of the object
176
+ # @return [String] String presentation of the object
177
+ def to_s
178
+ to_hash.to_s
179
+ end
180
+
181
+ # to_body is an alias to to_hash (backward compatibility)
182
+ # @return [Hash] Returns the object in the form of hash
183
+ def to_body
184
+ to_hash
185
+ end
186
+
187
+ # Returns the object in the form of hash
188
+ # @return [Hash] Returns the object in the form of hash
189
+ def to_hash
190
+ hash = {}
191
+ self.class.attribute_map.each_pair do |attr, param|
192
+ value = self.send(attr)
193
+ next if value.nil?
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,215 @@
1
+ =begin
2
+ #Payout Orchestrator API
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ The version of the OpenAPI document: 1.0.3
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.1.0-SNAPSHOT
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module Yapstone
16
+ class ReverseDisbursementRequest
17
+ attr_accessor :reversal_amount
18
+
19
+ attr_accessor :reversal_type
20
+
21
+ # Attribute mapping from ruby-style variable name to JSON key.
22
+ def self.attribute_map
23
+ {
24
+ :'reversal_amount' => :'reversalAmount',
25
+ :'reversal_type' => :'reversalType'
26
+ }
27
+ end
28
+
29
+ # Attribute type mapping.
30
+ def self.openapi_types
31
+ {
32
+ :'reversal_amount' => :'Integer',
33
+ :'reversal_type' => :'String'
34
+ }
35
+ end
36
+
37
+ # Initializes the object
38
+ # @param [Hash] attributes Model attributes in the form of hash
39
+ def initialize(attributes = {})
40
+ if (!attributes.is_a?(Hash))
41
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Yapstone::ReverseDisbursementRequest` initialize method"
42
+ end
43
+
44
+ # check to see if the attribute exists and convert string to symbol for hash key
45
+ attributes = attributes.each_with_object({}) { |(k, v), h|
46
+ if (!self.class.attribute_map.key?(k.to_sym))
47
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Yapstone::ReverseDisbursementRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
48
+ end
49
+ h[k.to_sym] = v
50
+ }
51
+
52
+ if attributes.key?(:'reversal_amount')
53
+ self.reversal_amount = attributes[:'reversal_amount']
54
+ end
55
+
56
+ if attributes.key?(:'reversal_type')
57
+ self.reversal_type = attributes[:'reversal_type']
58
+ end
59
+ end
60
+
61
+ # Show invalid properties with the reasons. Usually used together with valid?
62
+ # @return Array for valid properties with the reasons
63
+ def list_invalid_properties
64
+ invalid_properties = Array.new
65
+ if @reversal_amount.nil?
66
+ invalid_properties.push('invalid value for "reversal_amount", reversal_amount cannot be nil.')
67
+ end
68
+
69
+ if @reversal_type.nil?
70
+ invalid_properties.push('invalid value for "reversal_type", reversal_type cannot be nil.')
71
+ end
72
+
73
+ invalid_properties
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
+ return false if @reversal_amount.nil?
80
+ return false if @reversal_type.nil?
81
+ true
82
+ end
83
+
84
+ # Checks equality by comparing each attribute.
85
+ # @param [Object] Object to be compared
86
+ def ==(o)
87
+ return true if self.equal?(o)
88
+ self.class == o.class &&
89
+ reversal_amount == o.reversal_amount &&
90
+ reversal_type == o.reversal_type
91
+ end
92
+
93
+ # @see the `==` method
94
+ # @param [Object] Object to be compared
95
+ def eql?(o)
96
+ self == o
97
+ end
98
+
99
+ # Calculates hash code according to all attributes.
100
+ # @return [Integer] Hash code
101
+ def hash
102
+ [reversal_amount, reversal_type].hash
103
+ end
104
+
105
+ # Builds the object from hash
106
+ # @param [Hash] attributes Model attributes in the form of hash
107
+ # @return [Object] Returns the model itself
108
+ def self.build_from_hash(attributes)
109
+ new.build_from_hash(attributes)
110
+ end
111
+
112
+ # Builds the object from hash
113
+ # @param [Hash] attributes Model attributes in the form of hash
114
+ # @return [Object] Returns the model itself
115
+ def build_from_hash(attributes)
116
+ return nil unless attributes.is_a?(Hash)
117
+ self.class.openapi_types.each_pair do |key, type|
118
+ if type =~ /\AArray<(.*)>/i
119
+ # check to ensure the input is an array given that the attribute
120
+ # is documented as an array but the input is not
121
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
122
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
123
+ end
124
+ elsif !attributes[self.class.attribute_map[key]].nil?
125
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
126
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
127
+ end
128
+
129
+ self
130
+ end
131
+
132
+ # Deserializes the data based on type
133
+ # @param string type Data type
134
+ # @param string value Value to be deserialized
135
+ # @return [Object] Deserialized data
136
+ def _deserialize(type, value)
137
+ case type.to_sym
138
+ when :DateTime
139
+ DateTime.parse(value)
140
+ when :Date
141
+ Date.parse(value)
142
+ when :String
143
+ value.to_s
144
+ when :Integer
145
+ value.to_i
146
+ when :Float
147
+ value.to_f
148
+ when :Boolean
149
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
150
+ true
151
+ else
152
+ false
153
+ end
154
+ when :Object
155
+ # generic object (usually a Hash), return directly
156
+ value
157
+ when /\AArray<(?<inner_type>.+)>\z/
158
+ inner_type = Regexp.last_match[:inner_type]
159
+ value.map { |v| _deserialize(inner_type, v) }
160
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
161
+ k_type = Regexp.last_match[:k_type]
162
+ v_type = Regexp.last_match[:v_type]
163
+ {}.tap do |hash|
164
+ value.each do |k, v|
165
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
166
+ end
167
+ end
168
+ else # model
169
+ Yapstone.const_get(type).build_from_hash(value)
170
+ end
171
+ end
172
+
173
+ # Returns the string representation of the object
174
+ # @return [String] String presentation of the object
175
+ def to_s
176
+ to_hash.to_s
177
+ end
178
+
179
+ # to_body is an alias to to_hash (backward compatibility)
180
+ # @return [Hash] Returns the object in the form of hash
181
+ def to_body
182
+ to_hash
183
+ end
184
+
185
+ # Returns the object in the form of hash
186
+ # @return [Hash] Returns the object in the form of hash
187
+ def to_hash
188
+ hash = {}
189
+ self.class.attribute_map.each_pair do |attr, param|
190
+ value = self.send(attr)
191
+ next if value.nil?
192
+ hash[param] = _to_hash(value)
193
+ end
194
+ hash
195
+ end
196
+
197
+ # Outputs non-array value in the form of hash
198
+ # For object, use to_hash. Otherwise, just return the value
199
+ # @param [Object] value Any valid value
200
+ # @return [Hash] Returns the value in the form of hash
201
+ def _to_hash(value)
202
+ if value.is_a?(Array)
203
+ value.compact.map { |v| _to_hash(v) }
204
+ elsif value.is_a?(Hash)
205
+ {}.tap do |hash|
206
+ value.each { |k, v| hash[k] = _to_hash(v) }
207
+ end
208
+ elsif value.respond_to? :to_hash
209
+ value.to_hash
210
+ else
211
+ value
212
+ end
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,215 @@
1
+ =begin
2
+ #Payout Orchestrator API
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ The version of the OpenAPI document: 1.0.3
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.1.0-SNAPSHOT
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module Yapstone
16
+ class ReverseReimbursementRequest
17
+ attr_accessor :reversal_amount
18
+
19
+ attr_accessor :reversal_type
20
+
21
+ # Attribute mapping from ruby-style variable name to JSON key.
22
+ def self.attribute_map
23
+ {
24
+ :'reversal_amount' => :'reversalAmount',
25
+ :'reversal_type' => :'reversalType'
26
+ }
27
+ end
28
+
29
+ # Attribute type mapping.
30
+ def self.openapi_types
31
+ {
32
+ :'reversal_amount' => :'Integer',
33
+ :'reversal_type' => :'String'
34
+ }
35
+ end
36
+
37
+ # Initializes the object
38
+ # @param [Hash] attributes Model attributes in the form of hash
39
+ def initialize(attributes = {})
40
+ if (!attributes.is_a?(Hash))
41
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Yapstone::ReverseReimbursementRequest` initialize method"
42
+ end
43
+
44
+ # check to see if the attribute exists and convert string to symbol for hash key
45
+ attributes = attributes.each_with_object({}) { |(k, v), h|
46
+ if (!self.class.attribute_map.key?(k.to_sym))
47
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Yapstone::ReverseReimbursementRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
48
+ end
49
+ h[k.to_sym] = v
50
+ }
51
+
52
+ if attributes.key?(:'reversal_amount')
53
+ self.reversal_amount = attributes[:'reversal_amount']
54
+ end
55
+
56
+ if attributes.key?(:'reversal_type')
57
+ self.reversal_type = attributes[:'reversal_type']
58
+ end
59
+ end
60
+
61
+ # Show invalid properties with the reasons. Usually used together with valid?
62
+ # @return Array for valid properties with the reasons
63
+ def list_invalid_properties
64
+ invalid_properties = Array.new
65
+ if @reversal_amount.nil?
66
+ invalid_properties.push('invalid value for "reversal_amount", reversal_amount cannot be nil.')
67
+ end
68
+
69
+ if @reversal_type.nil?
70
+ invalid_properties.push('invalid value for "reversal_type", reversal_type cannot be nil.')
71
+ end
72
+
73
+ invalid_properties
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
+ return false if @reversal_amount.nil?
80
+ return false if @reversal_type.nil?
81
+ true
82
+ end
83
+
84
+ # Checks equality by comparing each attribute.
85
+ # @param [Object] Object to be compared
86
+ def ==(o)
87
+ return true if self.equal?(o)
88
+ self.class == o.class &&
89
+ reversal_amount == o.reversal_amount &&
90
+ reversal_type == o.reversal_type
91
+ end
92
+
93
+ # @see the `==` method
94
+ # @param [Object] Object to be compared
95
+ def eql?(o)
96
+ self == o
97
+ end
98
+
99
+ # Calculates hash code according to all attributes.
100
+ # @return [Integer] Hash code
101
+ def hash
102
+ [reversal_amount, reversal_type].hash
103
+ end
104
+
105
+ # Builds the object from hash
106
+ # @param [Hash] attributes Model attributes in the form of hash
107
+ # @return [Object] Returns the model itself
108
+ def self.build_from_hash(attributes)
109
+ new.build_from_hash(attributes)
110
+ end
111
+
112
+ # Builds the object from hash
113
+ # @param [Hash] attributes Model attributes in the form of hash
114
+ # @return [Object] Returns the model itself
115
+ def build_from_hash(attributes)
116
+ return nil unless attributes.is_a?(Hash)
117
+ self.class.openapi_types.each_pair do |key, type|
118
+ if type =~ /\AArray<(.*)>/i
119
+ # check to ensure the input is an array given that the attribute
120
+ # is documented as an array but the input is not
121
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
122
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
123
+ end
124
+ elsif !attributes[self.class.attribute_map[key]].nil?
125
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
126
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
127
+ end
128
+
129
+ self
130
+ end
131
+
132
+ # Deserializes the data based on type
133
+ # @param string type Data type
134
+ # @param string value Value to be deserialized
135
+ # @return [Object] Deserialized data
136
+ def _deserialize(type, value)
137
+ case type.to_sym
138
+ when :DateTime
139
+ DateTime.parse(value)
140
+ when :Date
141
+ Date.parse(value)
142
+ when :String
143
+ value.to_s
144
+ when :Integer
145
+ value.to_i
146
+ when :Float
147
+ value.to_f
148
+ when :Boolean
149
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
150
+ true
151
+ else
152
+ false
153
+ end
154
+ when :Object
155
+ # generic object (usually a Hash), return directly
156
+ value
157
+ when /\AArray<(?<inner_type>.+)>\z/
158
+ inner_type = Regexp.last_match[:inner_type]
159
+ value.map { |v| _deserialize(inner_type, v) }
160
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
161
+ k_type = Regexp.last_match[:k_type]
162
+ v_type = Regexp.last_match[:v_type]
163
+ {}.tap do |hash|
164
+ value.each do |k, v|
165
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
166
+ end
167
+ end
168
+ else # model
169
+ Yapstone.const_get(type).build_from_hash(value)
170
+ end
171
+ end
172
+
173
+ # Returns the string representation of the object
174
+ # @return [String] String presentation of the object
175
+ def to_s
176
+ to_hash.to_s
177
+ end
178
+
179
+ # to_body is an alias to to_hash (backward compatibility)
180
+ # @return [Hash] Returns the object in the form of hash
181
+ def to_body
182
+ to_hash
183
+ end
184
+
185
+ # Returns the object in the form of hash
186
+ # @return [Hash] Returns the object in the form of hash
187
+ def to_hash
188
+ hash = {}
189
+ self.class.attribute_map.each_pair do |attr, param|
190
+ value = self.send(attr)
191
+ next if value.nil?
192
+ hash[param] = _to_hash(value)
193
+ end
194
+ hash
195
+ end
196
+
197
+ # Outputs non-array value in the form of hash
198
+ # For object, use to_hash. Otherwise, just return the value
199
+ # @param [Object] value Any valid value
200
+ # @return [Hash] Returns the value in the form of hash
201
+ def _to_hash(value)
202
+ if value.is_a?(Array)
203
+ value.compact.map { |v| _to_hash(v) }
204
+ elsif value.is_a?(Hash)
205
+ {}.tap do |hash|
206
+ value.each { |k, v| hash[k] = _to_hash(v) }
207
+ end
208
+ elsif value.respond_to? :to_hash
209
+ value.to_hash
210
+ else
211
+ value
212
+ end
213
+ end
214
+ end
215
+ end