Advertisement
SperoCoin

deposit.rb

Jan 26th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.66 KB | None | 0 0
  1. require_relative 'validations'
  2.  
  3. module APIv2
  4.   class Deposits < Grape::API
  5.     helpers ::APIv2::NamedParams
  6.  
  7.     before { authenticate! }
  8.  
  9.     desc 'Get your deposits history.'
  10.     params do
  11.       use :auth
  12.       optional :currency, type: String, values: Currency.all.map(&:code), desc: "Currency value contains  #{Currency.all.map(&:code).join(',')}"
  13.       optional :limit, type: Integer, range: 1..100, default: 3, desc: "Set result limit."
  14.       optional :state, type: String, values: Deposit::STATES.map(&:to_s)
  15.     end
  16.     get "/deposits" do
  17.       deposits = current_user.deposits.limit(params[:limit]).recent
  18.       deposits = deposits.with_currency(params[:currency]) if params[:currency]
  19.       deposits = deposits.with_aasm_state(params[:state]) if params[:state].present?
  20.  
  21.       present deposits, with: APIv2::Entities::Deposit
  22.     end
  23.  
  24.     desc 'Get details of specific deposit.'
  25.     params do
  26.       use :auth
  27.       requires :txid
  28.     end
  29.     get "/deposit" do
  30.       deposit = current_user.deposits.find_by(txid: params[:txid])
  31.       raise DepositByTxidNotFoundError, params[:txid] unless deposit
  32.  
  33.       present deposit, with: APIv2::Entities::Deposit
  34.     end
  35.  
  36.     desc 'Where to deposit. The address field could be empty when a new address is generating (e.g. for bitcoin), you should try again later in that case.'
  37.     params do
  38.       use :auth
  39.       requires :currency, type: String, values: Currency.all.map(&:code), desc: "The account to which you want to deposit. Available values: #{Currency.all.map(&:code).join(', ')}"
  40.     end
  41.     get "/deposit_address" do
  42.       current_user.ac(params[:currency]).payment_address.to_json
  43.     end
  44.   end
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement