Class: BlockBee::API
- Inherits:
-
Object
- Object
- BlockBee::API
- Defined in:
- lib/blockbee.rb
Class Method Summary collapse
- .check_payout_status(api_key, payout_id) ⇒ Object
- .create_payout(coin, payout_requests, api_key, process: false) ⇒ Object
- .create_payout_by_ids(api_key, payout_ids) ⇒ Object
- .get_estimate(coin, api_key, addresses: 1, priority: 'default') ⇒ Object
- .get_info(coin, prices: 0) ⇒ Object
- .get_payout_wallet(coin, api_key, balance = false) ⇒ Object
- .get_supported_coins ⇒ Object
- .list_payouts(coin, api_key, status: 'all', page: 1, payout_request: false) ⇒ Object
- .process_payout(api_key, payout_id) ⇒ Object
Instance Method Summary collapse
- #get_address ⇒ Object
- #get_conversion(from_coin, value) ⇒ Object
- #get_logs ⇒ Object
- #get_qrcode(value: nil, size: 300) ⇒ Object
-
#initialize(coin, callback_url, api_key, own_address: '', parameters: {}, bb_params: {}) ⇒ API
constructor
A new instance of API.
Constructor Details
#initialize(coin, callback_url, api_key, own_address: '', parameters: {}, bb_params: {}) ⇒ API
Returns a new instance of API.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/blockbee.rb', line 44 def initialize(coin, callback_url, api_key, own_address: '', parameters: {}, bb_params: {}) raise BlockBee::MissingAPIKeyError, 'Provide your API Key' if api_key.nil? raise BlockBee::CallbackURLMissing, 'Provide your callback URL' if callback_url.nil? _cb = URI::parse(callback_url) @callback_url = URI::HTTPS.build( host: _cb.host, path: _cb.path, query: URI.encode_www_form(parameters) ) @coin = coin @own_address = own_address @parameters = parameters @bb_params = bb_params @api_key = api_key @payment_address = '' end |
Class Method Details
.check_payout_status(api_key, payout_id) ⇒ Object
231 232 233 234 235 |
# File 'lib/blockbee.rb', line 231 def self.check_payout_status(api_key, payout_id) _status = BlockBee::process_request_post(nil, 'payout/status', api_key, body: { 'payout_id' => payout_id }) _status end |
.create_payout(coin, payout_requests, api_key, process: false) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/blockbee.rb', line 167 def self.create_payout(coin, payout_requests, api_key, process: false) body = { 'outputs' => payout_requests } endpoint = 'payout/request/bulk' endpoint += '/process' if process _payout = BlockBee::process_request_post(coin, endpoint, api_key, body: body, is_json: true) _payout end |
.create_payout_by_ids(api_key, payout_ids) ⇒ Object
219 220 221 222 223 |
# File 'lib/blockbee.rb', line 219 def self.create_payout_by_ids(api_key, payout_ids) _payout = BlockBee::process_request_post(nil, 'payout/create', api_key, body: { 'request_ids' => payout_ids.join(',') }) _payout end |
.get_estimate(coin, api_key, addresses: 1, priority: 'default') ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/blockbee.rb', line 154 def self.get_estimate(coin, api_key, addresses: 1, priority: 'default') raise BlockBee::MissingAPIKeyError, 'Provide your API Key' if api_key.nil? _params = { 'addresses' => addresses, 'priority' => priority, } _estimate = BlockBee::process_request_get(coin, 'estimate', params: _params) _estimate end |
.get_info(coin, prices: 0) ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/blockbee.rb', line 126 def self.get_info(coin, prices: 0) _params = { 'prices' => prices, } _info = BlockBee::process_request_get(coin, 'info', params: _params) end |
.get_payout_wallet(coin, api_key, balance = false) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/blockbee.rb', line 195 def self.get_payout_wallet(coin, api_key, balance = false) wallet = BlockBee::process_request_get(coin, 'payout/address', params: { 'apikey' => api_key }) if wallet['status'] == 'error' raise BlockBee::Error, wallet['error'] end output = { 'address' => wallet['address'] } if balance wallet_balance = BlockBee::process_request_get(coin, 'payout/balance', params: { 'apikey' => api_key }) if wallet_balance['status'] == 'error' raise BlockBee::Error, wallet_balance['error'] end if wallet_balance['status'] == 'success' output['balance'] = wallet_balance['balance'] end end output end |
.get_supported_coins ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/blockbee.rb', line 134 def self.get_supported_coins() _info = get_info(nil) _info.delete('fee_tiers') _coins = {} _info.each do |ticker, coin_info| if coin_info.key?('coin') _coins[ticker] = coin_info['coin'] else coin_info.each do |token, token_info| _coins[ticker + '_' + token] = token_info['coin'] + ' (' + ticker.upcase + ')' end end end _coins end |
.list_payouts(coin, api_key, status: 'all', page: 1, payout_request: false) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/blockbee.rb', line 179 def self.list_payouts(coin, api_key, status: 'all', page: 1, payout_request: false) _params = { 'apikey' => api_key, 'status' => status, 'p' => page } endpoint = 'payout/list' endpoint = 'payout/request/list' if payout_request _payouts = BlockBee::process_request_get(coin, endpoint, params: _params) _payouts end |
.process_payout(api_key, payout_id) ⇒ Object
225 226 227 228 229 |
# File 'lib/blockbee.rb', line 225 def self.process_payout(api_key, payout_id) _process = BlockBee::process_request_post(nil, 'payout/process', api_key, body: { 'payout_id' => payout_id }) _process end |
Instance Method Details
#get_address ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/blockbee.rb', line 64 def get_address return nil if @coin.nil? _params = { 'callback' => @callback_url, 'apikey' => @api_key }.merge(@bb_params) if !@own_address.nil? && !@own_address.empty? (_params['address'] = @own_address) end _address = BlockBee::process_request_get(@coin, 'create', params: _params) @payment_address = _address['address_in'] _address end |
#get_conversion(from_coin, value) ⇒ Object
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/blockbee.rb', line 115 def get_conversion(from_coin, value) _params = { 'from' => from_coin, 'value' => value, } _conversion = BlockBee::process_request_get(@coin, 'convert', params: _params) _conversion end |
#get_logs ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/blockbee.rb', line 83 def get_logs _params = { 'callback' => @callback_url, 'apikey' => @api_key } _logs = BlockBee::process_request_get(@coin, 'logs', params: _params) _logs end |
#get_qrcode(value: nil, size: 300) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/blockbee.rb', line 94 def get_qrcode(value: nil, size: 300) return nil if @coin.nil? address = @payment_address address = get_address['address_in'] if address.empty? _params = { 'address' => address, 'size' => size } if value.is_a? Numeric _params['value'] = value end _qrcode = BlockBee::process_request_get(@coin, 'qrcode', params: _params) _qrcode end |