bleumi_pay_sdk_ruby 1.0.3 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/README.md +31 -26
  4. data/assets/images/BleumiPay.png +0 -0
  5. data/bleumi_pay_sdk_ruby.gemspec +4 -4
  6. data/docs/AlgorandAddress.md +28 -0
  7. data/docs/AlgorandBalance.md +28 -0
  8. data/docs/AlgorandWalletAddress.md +24 -0
  9. data/docs/AlgorandWalletInputs.md +23 -0
  10. data/docs/BadRequest.md +1 -1
  11. data/docs/Chain.md +6 -3
  12. data/docs/CheckoutToken.md +8 -3
  13. data/docs/CreateCheckoutUrlRequest.md +7 -8
  14. data/docs/CreatePayoutRequest.md +1 -1
  15. data/docs/CreatePayoutResponse.md +1 -1
  16. data/docs/EthereumAddress.md +29 -0
  17. data/docs/EthereumBalance.md +30 -0
  18. data/docs/EthereumWalletAddress.md +23 -0
  19. data/docs/EthereumWalletInputs.md +23 -0
  20. data/docs/HostedCheckoutsApi.md +31 -23
  21. data/docs/PaginatedPaymentOperations.md +2 -3
  22. data/docs/PaginatedPayments.md +41 -10
  23. data/docs/PaginatedPayoutItems.md +1 -1
  24. data/docs/Payment.md +13 -7
  25. data/docs/PaymentAddresses.md +29 -7
  26. data/docs/PaymentBalances.md +20 -8
  27. data/docs/PaymentOperation.md +2 -2
  28. data/docs/PaymentOperationInputs.md +3 -4
  29. data/docs/PaymentRefundRequest.md +1 -3
  30. data/docs/PaymentSettleRequest.md +1 -1
  31. data/docs/PaymentsApi.md +15 -73
  32. data/docs/Payout.md +2 -1
  33. data/docs/PayoutItem.md +1 -1
  34. data/docs/PayoutItemInputs.md +1 -1
  35. data/docs/PayoutsApi.md +10 -10
  36. data/docs/RskAddress.md +29 -0
  37. data/docs/RskBalance.md +28 -0
  38. data/docs/ValidateCheckoutRequest.md +2 -2
  39. data/docs/WalletBalance.md +13 -9
  40. data/lib/bleumi_pay_sdk_ruby.rb +13 -8
  41. data/lib/bleumi_pay_sdk_ruby/api/hosted_checkouts_api.rb +17 -5
  42. data/lib/bleumi_pay_sdk_ruby/api/payments_api.rb +34 -78
  43. data/lib/bleumi_pay_sdk_ruby/api/payouts_api.rb +2 -2
  44. data/lib/bleumi_pay_sdk_ruby/api/request_validator.rb +261 -0
  45. data/lib/bleumi_pay_sdk_ruby/api_client.rb +10 -8
  46. data/lib/bleumi_pay_sdk_ruby/api_error.rb +2 -2
  47. data/lib/bleumi_pay_sdk_ruby/configuration.rb +3 -3
  48. data/lib/bleumi_pay_sdk_ruby/models/algorand_address.rb +219 -0
  49. data/lib/bleumi_pay_sdk_ruby/models/algorand_balance.rb +219 -0
  50. data/lib/bleumi_pay_sdk_ruby/models/{create_payment_response.rb → algorand_wallet_address.rb} +20 -11
  51. data/lib/bleumi_pay_sdk_ruby/models/algorand_wallet_inputs.rb +247 -0
  52. data/lib/bleumi_pay_sdk_ruby/models/bad_request.rb +3 -3
  53. data/lib/bleumi_pay_sdk_ruby/models/chain.rb +6 -5
  54. data/lib/bleumi_pay_sdk_ruby/models/checkout_token.rb +46 -16
  55. data/lib/bleumi_pay_sdk_ruby/models/create_checkout_url_request.rb +26 -13
  56. data/lib/bleumi_pay_sdk_ruby/models/create_checkout_url_response.rb +2 -2
  57. data/lib/bleumi_pay_sdk_ruby/models/create_payout_request.rb +4 -3
  58. data/lib/bleumi_pay_sdk_ruby/models/create_payout_response.rb +2 -2
  59. data/lib/bleumi_pay_sdk_ruby/models/{create_payment_request.rb → ethereum_address.rb} +39 -38
  60. data/lib/bleumi_pay_sdk_ruby/models/{network_balance.rb → ethereum_balance.rb} +13 -46
  61. data/lib/bleumi_pay_sdk_ruby/models/{wallet_address.rb → ethereum_wallet_address.rb} +19 -10
  62. data/lib/bleumi_pay_sdk_ruby/models/ethereum_wallet_inputs.rb +247 -0
  63. data/lib/bleumi_pay_sdk_ruby/models/paginated_payment_operations.rb +2 -2
  64. data/lib/bleumi_pay_sdk_ruby/models/paginated_payments.rb +2 -2
  65. data/lib/bleumi_pay_sdk_ruby/models/paginated_payout_items.rb +2 -2
  66. data/lib/bleumi_pay_sdk_ruby/models/payment.rb +2 -2
  67. data/lib/bleumi_pay_sdk_ruby/models/payment_addresses.rb +25 -9
  68. data/lib/bleumi_pay_sdk_ruby/models/payment_balances.rb +24 -6
  69. data/lib/bleumi_pay_sdk_ruby/models/payment_operation.rb +4 -3
  70. data/lib/bleumi_pay_sdk_ruby/models/payment_operation_inputs.rb +3 -3
  71. data/lib/bleumi_pay_sdk_ruby/models/payment_operation_response.rb +2 -2
  72. data/lib/bleumi_pay_sdk_ruby/models/payment_refund_request.rb +3 -3
  73. data/lib/bleumi_pay_sdk_ruby/models/payment_settle_request.rb +3 -3
  74. data/lib/bleumi_pay_sdk_ruby/models/payout.rb +16 -6
  75. data/lib/bleumi_pay_sdk_ruby/models/payout_item.rb +2 -2
  76. data/lib/bleumi_pay_sdk_ruby/models/payout_item_inputs.rb +2 -2
  77. data/lib/bleumi_pay_sdk_ruby/models/rsk_address.rb +219 -0
  78. data/lib/bleumi_pay_sdk_ruby/models/{token.rb → rsk_balance.rb} +41 -36
  79. data/lib/bleumi_pay_sdk_ruby/models/validate_checkout_request.rb +2 -2
  80. data/lib/bleumi_pay_sdk_ruby/models/validate_checkout_response.rb +2 -2
  81. data/lib/bleumi_pay_sdk_ruby/models/wallet_balance.rb +21 -6
  82. data/lib/bleumi_pay_sdk_ruby/version.rb +3 -3
  83. data/spec/api/hosted_checkouts_api_spec.rb +1 -1
  84. data/spec/api/payments_api_spec.rb +6 -17
  85. data/spec/api_client_spec.rb +1 -1
  86. data/spec/models/{create_payment_response_spec.rb → algorand_address_spec.rb} +13 -7
  87. data/spec/models/{token_spec.rb → algorand_balance_spec.rb} +15 -9
  88. data/spec/models/algorand_wallet_address_spec.rb +47 -0
  89. data/spec/models/algorand_wallet_inputs_spec.rb +65 -0
  90. data/spec/models/checkout_token_spec.rb +13 -1
  91. data/spec/models/create_checkout_url_request_spec.rb +7 -1
  92. data/spec/models/{create_payment_request_spec.rb → ethereum_address_spec.rb} +15 -9
  93. data/spec/models/{network_balance_spec.rb → ethereum_balance_spec.rb} +9 -27
  94. data/spec/models/ethereum_wallet_address_spec.rb +47 -0
  95. data/spec/models/ethereum_wallet_inputs_spec.rb +65 -0
  96. data/spec/models/payment_addresses_spec.rb +12 -0
  97. data/spec/models/payment_balances_spec.rb +12 -0
  98. data/spec/models/payout_spec.rb +6 -0
  99. data/spec/models/{eth_address_spec.rb → rsk_address_spec.rb} +13 -7
  100. data/spec/models/{wallet_address_spec.rb → rsk_balance_spec.rb} +13 -7
  101. data/spec/models/wallet_balance_spec.rb +6 -0
  102. metadata +48 -28
  103. data/docs/CreatePaymentRequest.md +0 -19
  104. data/docs/CreatePaymentResponse.md +0 -15
  105. data/docs/EthAddress.md +0 -13
  106. data/docs/NetworkBalance.md +0 -29
  107. data/docs/Token.md +0 -15
  108. data/docs/WalletAddress.md +0 -14
  109. data/lib/bleumi_pay_sdk_ruby/models/eth_address.rb +0 -208
@@ -1,7 +1,7 @@
1
1
  =begin
2
- #Bleumi Pay API
2
+ #Bleumi Pay REST API
3
3
 
4
- #A simple and powerful REST API to integrate ERC-20, Ethereum, xDai payments and/or payouts into your business or application
4
+ #A simple and powerful REST API to integrate ERC-20, Ethereum, xDai, Algorand payments and/or payouts into your business or application
5
5
 
6
6
  The version of the OpenAPI document: 1.0.0
7
7
  Contact: info@bleumi.com
@@ -0,0 +1,261 @@
1
+ =begin
2
+ #Bleumi Pay REST API
3
+
4
+ #A simple and powerful REST API to integrate ERC-20, Ethereum, xDai, Algorand payments and/or payouts into your business or application
5
+
6
+ Contact: info@bleumi.com
7
+
8
+ =end
9
+ module BleumiPay
10
+ class RequestValidator
11
+
12
+ def self.default
13
+ @@default ||= RequestValidator.new
14
+ end
15
+
16
+ def eth_address?(str)
17
+ # We use !! to convert the return value to a boolean
18
+ !!(str =~ /^0x[a-fA-F0-9]{40}$/)
19
+ end
20
+
21
+ def algo_address?(str)
22
+ # We use !! to convert the return value to a boolean
23
+ !!(str =~ /^[A-Z2-7+=*]{58}$/)
24
+ end
25
+
26
+ def algo_token?(str)
27
+ # We use !! to convert the return value to a boolean
28
+ !!(str =~ /^[0-9]*$/)
29
+ end
30
+
31
+ def is_not_empty(str)
32
+ if (str == nil || str == "") then
33
+ return false
34
+ end
35
+ return true
36
+ end
37
+
38
+ def check_eth_addr(name, input)
39
+ if !((eth_address?(input))||(input == "ETH")||(input == "XDAI")||(input == "XDAIT")) then
40
+ return "`#{name}` is not a valid Ethereum address"
41
+ end
42
+ return nil
43
+ end
44
+
45
+ def check_rsk_addr(name, input)
46
+ if !((eth_address?(input))||(input == "RBTC")) then
47
+ return "`#{name}` is not a valid RSK address"
48
+ end
49
+ return nil
50
+ end
51
+
52
+ def check_alg_addr(name, input, is_token)
53
+ if (is_token)
54
+ if !((algo_token?(input))||(input == "ALGO")) then
55
+ return "`#{name}` is not a valid Algorand token"
56
+ end
57
+ else
58
+ if !(algo_address?(input)) then
59
+ return "`#{name}` is not a valid Algorand address"
60
+ end
61
+ end
62
+ return nil
63
+ end
64
+
65
+ def is_algo_network(chain)
66
+ return ((chain == "alg_mainnet")||(chain == "alg_testnet"))
67
+ end
68
+
69
+ def is_rsk_network(chain)
70
+ return ((chain == "rsk")||(chain == "rsk_testnet"))
71
+ end
72
+
73
+ def check_req_param(name, input)
74
+ if (input == nil || input == "")
75
+ return "Missing required parameter `#{name}`"
76
+ end
77
+ return nil
78
+ end
79
+
80
+ def check_network_addr(name, input, chain, mandatory, is_token)
81
+ if mandatory then
82
+ msg = check_req_param(name, input)
83
+ if is_not_empty(msg) then
84
+ return msg
85
+ end
86
+ end
87
+ if is_not_empty(input) then
88
+ msg = nil
89
+ if is_algo_network(chain) then
90
+ msg = check_alg_addr(name, input, is_token)
91
+ elsif is_rsk_network(chain) then
92
+ msg = check_rsk_addr(name, input)
93
+ else
94
+ msg = check_eth_addr(name, input)
95
+ end
96
+ if is_not_empty(msg) then
97
+ return msg
98
+ end
99
+ end
100
+ return nil
101
+ end
102
+
103
+ def validate_refund_payment_request(params, chain)
104
+ # check if chain is provided
105
+ msg = check_req_param("Chain", chain)
106
+ if is_not_empty(msg) then
107
+ return msg
108
+ end
109
+ # check if token is valid address in the network
110
+ msg = check_network_addr("Token", params.token, chain, mandatory=true, is_token=true)
111
+ if is_not_empty(msg) then
112
+ return msg
113
+ end
114
+ return nil
115
+ end
116
+
117
+ def validate_settle_payment_request(params, chain)
118
+ # check if chain is provided
119
+ msg = check_req_param("Chain", chain)
120
+ if is_not_empty(msg) then
121
+ return msg
122
+ end
123
+ # check if token is valid address in the network
124
+ msg = check_network_addr("Token", params.token, chain, mandatory=true, is_token=true)
125
+ if is_not_empty(msg) then
126
+ return msg
127
+ end
128
+ # check if amount to settle is provided
129
+ msg = check_req_param("Amount", params.amount)
130
+ if is_not_empty(msg) then
131
+ return msg
132
+ end
133
+ return nil
134
+ end
135
+
136
+ def validate_create_checkout_url_request(params)
137
+ # check if id is provided while creating checkout url
138
+ msg = check_req_param("Id", params.id)
139
+ if is_not_empty(msg) then
140
+ return msg
141
+ end
142
+
143
+ # check if currency is provided while creating checkout url
144
+ msg = check_req_param("Currency", params.currency)
145
+ if is_not_empty(msg) then
146
+ return msg
147
+ end
148
+
149
+ # check if amount is provided while creating checkout url
150
+ msg = check_req_param("Amount", params.amount)
151
+ if is_not_empty(msg) then
152
+ return msg
153
+ end
154
+
155
+ # check if cancel_url is provided while creating checkout url
156
+ msg = check_req_param("CancelUrl", params.cancel_url)
157
+ if is_not_empty(msg) then
158
+ return msg
159
+ end
160
+
161
+ # check if success_url is provided while creating checkout url
162
+ msg = check_req_param("SuccessUrl", params.success_url)
163
+ if is_not_empty(msg) then
164
+ return msg
165
+ end
166
+
167
+ # check if token is valid address in the network (if provided)
168
+ if is_not_empty(params.token) then
169
+
170
+ # check if chain is provided in the request, when token is provided, this is required
171
+ msg = check_req_param("Chain", params.chain)
172
+ if is_not_empty(msg) then
173
+ return msg
174
+ end
175
+
176
+ # check if token is valid address in the network (if provided)
177
+ msg = check_network_addr("Token", params.token, params.chain, mandatory=false, is_token=true)
178
+ if is_not_empty(msg) then
179
+ return msg
180
+ end
181
+
182
+ # check if transfer_address is valid address in the network (if provided)
183
+ if is_not_empty(params.transfer_address) then
184
+ msg = check_network_addr("TransferAddress", params.transfer_address, params.chain, mandatory=false, is_token=false)
185
+ if is_not_empty(msg) then
186
+ return msg
187
+ end
188
+ end
189
+ end
190
+ return nil
191
+ end
192
+
193
+ def validate_checkout_payment_params(params)
194
+
195
+ # check if hmac_alg is provided while creating checkout payment parameters request
196
+ msg = check_req_param("HmacAlg", params.hmac_alg)
197
+ if is_not_empty(msg) then
198
+ return msg
199
+ end
200
+
201
+ # check if hmac_input is provided while creating checkout payment parameters request
202
+ msg = check_req_param("HmacInput", params.hmac_input)
203
+ if is_not_empty(msg) then
204
+ return msg
205
+ end
206
+
207
+ # check if hmac_key_id is provided while creating checkout payment parameters request
208
+ msg = check_req_param("HmacKeyId", params.hmac_key_id)
209
+ if is_not_empty(msg) then
210
+ return msg
211
+ end
212
+
213
+ # check if hmac_value is provided while creating checkout payment parameters request
214
+ msg = check_req_param("HmacValue", params.hmac_value)
215
+ if is_not_empty(msg) then
216
+ return msg
217
+ end
218
+ return nil
219
+ end
220
+
221
+ def validate_create_payout_request(params, chain)
222
+ msg = check_req_param("Chain", chain)
223
+ if is_not_empty(msg) then
224
+ return msg
225
+ end
226
+ # check if token is valid address in the network
227
+ msg = check_network_addr("Token", params.token, chain, mandatory=true, is_token=true)
228
+ if is_not_empty(msg) then
229
+ return msg
230
+ end
231
+
232
+ payouts = params.payouts
233
+ if payouts.length == 0 then
234
+ return "Payouts not defined."
235
+ end
236
+
237
+ for payout in payouts
238
+ # check if payout.transfer_address is valid address in the network
239
+ msg = check_network_addr("TransferAddress", payout.transfer_address, chain, mandatory=true, is_token=false)
240
+ if is_not_empty(msg) then
241
+ return msg
242
+ end
243
+
244
+ # check if payout.amount is provided for payout
245
+ msg = check_req_param("Amount", payout.amount)
246
+ if is_not_empty(msg) then
247
+ return msg
248
+ end
249
+
250
+ if is_algo_network(chain) then
251
+ # check if payout.authorization is provided for Algorand payout
252
+ msg = check_req_param("Authorization", payout.authorization)
253
+ if is_not_empty(msg) then
254
+ return msg
255
+ end
256
+ end
257
+ end
258
+ return nil
259
+ end
260
+ end
261
+ end
@@ -1,7 +1,7 @@
1
1
  =begin
2
- #Bleumi Pay API
2
+ #Bleumi Pay REST API
3
3
 
4
- #A simple and powerful REST API to integrate ERC-20, Ethereum, xDai payments and/or payouts into your business or application
4
+ #A simple and powerful REST API to integrate ERC-20, Ethereum, xDai, Algorand payments and/or payouts into your business or application
5
5
 
6
6
  The version of the OpenAPI document: 1.0.0
7
7
  Contact: info@bleumi.com
@@ -30,7 +30,7 @@ module BleumiPay
30
30
  # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
31
31
  def initialize(config = Configuration.default)
32
32
  @config = config
33
- @user_agent = "BleumiPay/#{VERSION}/ruby"
33
+ @user_agent = "bleumi_pay_sdk_ruby/#{VERSION}/ruby"
34
34
  @default_headers = {
35
35
  'Content-Type' => 'application/json',
36
36
  'User-Agent' => @user_agent
@@ -269,11 +269,13 @@ module BleumiPay
269
269
  tempfile.write(chunk)
270
270
  end
271
271
  request.on_complete do |response|
272
- tempfile.close if tempfile
273
- @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
274
- "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
275
- "will be deleted automatically with GC. It's also recommended to delete the temp file "\
276
- "explicitly with `tempfile.delete`"
272
+ if tempfile
273
+ tempfile.close
274
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
275
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
276
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
277
+ "explicitly with `tempfile.delete`"
278
+ end
277
279
  end
278
280
  end
279
281
 
@@ -1,7 +1,7 @@
1
1
  =begin
2
- #Bleumi Pay API
2
+ #Bleumi Pay REST API
3
3
 
4
- #A simple and powerful REST API to integrate ERC-20, Ethereum, xDai payments and/or payouts into your business or application
4
+ #A simple and powerful REST API to integrate ERC-20, Ethereum, xDai, Algorand payments and/or payouts into your business or application
5
5
 
6
6
  The version of the OpenAPI document: 1.0.0
7
7
  Contact: info@bleumi.com
@@ -1,7 +1,7 @@
1
1
  =begin
2
- #Bleumi Pay API
2
+ #Bleumi Pay REST API
3
3
 
4
- #A simple and powerful REST API to integrate ERC-20, Ethereum, xDai payments and/or payouts into your business or application
4
+ #A simple and powerful REST API to integrate ERC-20, Ethereum, xDai, Algorand payments and/or payouts into your business or application
5
5
 
6
6
  The version of the OpenAPI document: 1.0.0
7
7
  Contact: info@bleumi.com
@@ -208,7 +208,7 @@ module BleumiPay
208
208
  [
209
209
  {
210
210
  url: "https://api.pay.bleumi.com/",
211
- description: "Bleumi Pay API",
211
+ description: "Bleumi Pay REST API",
212
212
  }
213
213
  ]
214
214
  end
@@ -0,0 +1,219 @@
1
+ =begin
2
+ #Bleumi Pay API
3
+
4
+ #A simple and powerful REST API to integrate ERC-20, Ethereum, xDai payments and/or payouts into your business or application
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ Contact: info@bleumi.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.2.2
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module BleumiPay
16
+ class AlgorandAddress
17
+ attr_accessor :alg_mainnet
18
+
19
+ attr_accessor :alg_testnet
20
+
21
+ # Attribute mapping from ruby-style variable name to JSON key.
22
+ def self.attribute_map
23
+ {
24
+ :'alg_mainnet' => :'alg_mainnet',
25
+ :'alg_testnet' => :'alg_testnet'
26
+ }
27
+ end
28
+
29
+ # Attribute type mapping.
30
+ def self.openapi_types
31
+ {
32
+ :'alg_mainnet' => :'Hash<String, AlgorandWalletAddress>',
33
+ :'alg_testnet' => :'Hash<String, AlgorandWalletAddress>'
34
+ }
35
+ end
36
+
37
+ # List of attributes with nullable: true
38
+ def self.openapi_nullable
39
+ Set.new([
40
+ ])
41
+ end
42
+
43
+ # Initializes the object
44
+ # @param [Hash] attributes Model attributes in the form of hash
45
+ def initialize(attributes = {})
46
+ if (!attributes.is_a?(Hash))
47
+ fail ArgumentError, "The input argument (attributes) must be a hash in `BleumiPay::AlgorandAddress` initialize method"
48
+ end
49
+
50
+ # check to see if the attribute exists and convert string to symbol for hash key
51
+ attributes = attributes.each_with_object({}) { |(k, v), h|
52
+ if (!self.class.attribute_map.key?(k.to_sym))
53
+ fail ArgumentError, "`#{k}` is not a valid attribute in `BleumiPay::AlgorandAddress`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
54
+ end
55
+ h[k.to_sym] = v
56
+ }
57
+
58
+ if attributes.key?(:'alg_mainnet')
59
+ if (value = attributes[:'alg_mainnet']).is_a?(Hash)
60
+ self.alg_mainnet = value
61
+ end
62
+ end
63
+
64
+ if attributes.key?(:'alg_testnet')
65
+ if (value = attributes[:'alg_testnet']).is_a?(Hash)
66
+ self.alg_testnet = value
67
+ end
68
+ end
69
+ end
70
+
71
+ # Show invalid properties with the reasons. Usually used together with valid?
72
+ # @return Array for valid properties with the reasons
73
+ def list_invalid_properties
74
+ invalid_properties = Array.new
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
+ 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
+ alg_mainnet == o.alg_mainnet &&
90
+ alg_testnet == o.alg_testnet
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
+ [alg_mainnet, alg_testnet].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
+ BleumiPay.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
+ if value.nil?
192
+ is_nullable = self.class.openapi_nullable.include?(attr)
193
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
194
+ end
195
+
196
+ hash[param] = _to_hash(value)
197
+ end
198
+ hash
199
+ end
200
+
201
+ # Outputs non-array value in the form of hash
202
+ # For object, use to_hash. Otherwise, just return the value
203
+ # @param [Object] value Any valid value
204
+ # @return [Hash] Returns the value in the form of hash
205
+ def _to_hash(value)
206
+ if value.is_a?(Array)
207
+ value.compact.map { |v| _to_hash(v) }
208
+ elsif value.is_a?(Hash)
209
+ {}.tap do |hash|
210
+ value.each { |k, v| hash[k] = _to_hash(v) }
211
+ end
212
+ elsif value.respond_to? :to_hash
213
+ value.to_hash
214
+ else
215
+ value
216
+ end
217
+ end
218
+ end
219
+ end