lib/cubits/helpers.rb
# Executes "Buy bitcoins" API call.
# Buy Bitcoins using funds in a Cubits account. Bought Bitcoins will be credited
# to your Cubits Wallet.
#
# @param params [Hash]
# @param params[:sender] [Hash] Sender attributes define spending part of transaction
# @param params[:sender][:currency] [String] ISO 4217 code of the currency, that you want
#                                            to spend (e.g. "EUR")
# @param params[:sender][:amount] [String] Amount in specified currency to be spent,
#                                          decimal number as a String (e.g. "12.50")
#
Executes "Buy bitcoins" API call.
Buy Bitcoins using funds in a Cubits account. Bought Bitcoins will be credited
to your Cubits Wallet.
Executes " Buy bitcoins " API call . Buy Bitcoins using funds in a Cubits account . Bought Bitcoins will be credited to your Cubits Wallet .
def buy(params)
      fail ArgumentError, 'Hash is expected as params' unless params.is_a?(Hash)
      fail ArgumentError, 'Hash is expected as :sender' unless params[:sender].is_a?(Hash)
      sender = params[:sender]
      fail ArgumentError, 'String is expected as sender[:currency]' unless sender[:currency].is_a?(String)
      fail ArgumentError, 'String is expected as sender[:amount]' unless sender[:amount].is_a?(String)
      fail ArgumentError, 'Invalid amount format' unless sender[:amount] =~ /^\d+\.\d+$/
      Cubits.connection.post(
        '/api/v1/buy',
        sender: {
          currency: sender[:currency],
          amount: sender[:amount]
        }
      )
    end
def buy ( params ) fail ArgumentError , 'Hash is expected as params' unless params . is_a? ( Hash ) fail ArgumentError , 'Hash is expected as :sender' unless params [ :sender ] . is_a? ( Hash ) sender = params [ :sender ] fail ArgumentError , 'String is expected as sender[:currency]' unless sender [ :currency ] . is_a? ( String ) fail ArgumentError , 'String is expected as sender[:amount]' unless sender [ :amount ] . is_a? ( String ) fail ArgumentError , 'Invalid amount format' unless sender [ :amount ] =~ / ^ \d + \. \d +$ / Cubits . connection . post ( '/api/v1/buy' , sender : { currency : sender [ :currency ] , amount : sender [ :amount ] } ) end
Executes "Buy bitcoins" API call.
Executes " Buy bitcoins " API call .
params
[Hash] Sender attributes define spending part of transaction
[ Hash ] Sender attributes define spending part of transaction
[String] Amount in specified currency to be spent, decimal number as a String
[ String ] Amount in specified currency to be spent decimal number as a String