Module: Cubits::Helpers
- Included in:
- Cubits
- Defined in:
- lib/cubits/helpers.rb
Instance Method Summary collapse
-
#available? ⇒ Boolean
Runs a few calls to Cubits API and returns true if the connection to the API is configured correctly.
-
#send_money(params) ⇒ Object
Executes “Send money” API call.
Instance Method Details
#available? ⇒ Boolean
Runs a few calls to Cubits API and returns true if the connection to the API is configured correctly.
7 8 9 10 11 12 13 |
# File 'lib/cubits/helpers.rb', line 7 def available? Cubits.connection.get('/api/v1/test', foo: 'bar') Cubits.connection.post('/api/v1/test', foo: 'bar') true rescue StandardError false end |
#send_money(params) ⇒ Object
Executes “Send money” API call. Sends Bitcoins from Cubits Wallet to external Bitcoin address.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cubits/helpers.rb', line 23 def send_money(params) fail ArgumentError, 'Hash is expected as params' unless params.is_a?(Hash) fail ArgumentError, 'String is expected as :amount' unless params[:amount].is_a?(String) fail ArgumentError, 'String is expected as :address' unless params[:address].is_a?(String) fail ArgumentError, 'Invalid amount format' unless params[:amount] =~ /^\d+\.\d+$/ fail ArgumentError, 'Invalid address format' unless params[:address] =~ /^[A-Za-z0-9]+$/ Cubits.connection.post( '/api/v1/send_money', amount: params[:amount], address: params[:address] ) end |