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.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/blockbee.rb', line 46 def initialize(coin, callback_url, api_key, own_address: '', parameters: {}, bb_params: {}) raise BlockBee::MissingAPIKeyError, 'Provide your API Key' if api_key.nil? || api_key.empty? raise BlockBee::CallbackURLMissing, 'Provide your callback URL' if callback_url.nil? || callback_url.empty? raise ArgumentError, 'Coin must be a string' unless coin.nil? || coin.is_a?(String) raise ArgumentError, 'Parameters must be a hash' unless parameters.is_a?(Hash) raise ArgumentError, 'BB params must be a hash' unless bb_params.is_a?(Hash) begin _cb = URI.parse(callback_url) raise ArgumentError, 'Invalid callback URL' unless _cb.scheme && _cb.host rescue URI::InvalidURIError raise ArgumentError, 'Invalid callback URL format' end # Preserve original scheme (HTTP/HTTPS) for development flexibility if _cb.scheme.downcase == 'https' @callback_url = URI::HTTPS.build( host: _cb.host, path: _cb.path, query: URI.encode_www_form(parameters) ) else @callback_url = URI::HTTP.build( host: _cb.host, path: _cb.path, query: URI.encode_www_form(parameters) ) end @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
254 255 256 257 258 |
# File 'lib/blockbee.rb', line 254 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
190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/blockbee.rb', line 190 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
242 243 244 245 246 |
# File 'lib/blockbee.rb', line 242 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
177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/blockbee.rb', line 177 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
149 150 151 152 153 154 155 |
# File 'lib/blockbee.rb', line 149 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
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/blockbee.rb', line 218 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
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/blockbee.rb', line 157 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
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/blockbee.rb', line 202 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
248 249 250 251 252 |
# File 'lib/blockbee.rb', line 248 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
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/blockbee.rb', line 83 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
138 139 140 141 142 143 144 145 146 147 |
# File 'lib/blockbee.rb', line 138 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
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/blockbee.rb', line 102 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
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/blockbee.rb', line 113 def get_qrcode(value: nil, size: 300) return nil if @coin.nil? raise ArgumentError, 'Size must be a positive integer' unless size.is_a?(Integer) && size > 0 raise ArgumentError, 'Value must be numeric if provided' unless value.nil? || value.is_a?(Numeric) raise ArgumentError, 'Value must be positive if provided' if value.is_a?(Numeric) && value <= 0 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 |