Class: Insight::API
- Inherits:
-
Object
- Object
- Insight::API
- Defined in:
- lib/insight/api.rb
Instance Attribute Summary collapse
-
#api_version ⇒ Object
readonly
Returns the value of attribute api_version.
-
#network ⇒ Object
Returns the value of attribute network.
Instance Method Summary collapse
- #address(address) ⇒ Object
- #address_balance(address) ⇒ Object
- #address_total_received(address) ⇒ Object
- #address_total_sent(address) ⇒ Object
- #address_unconfirmed_balance(address) ⇒ Object
- #address_unspent_transactions(address, params = nil) ⇒ Object
- #block(hash) ⇒ Object
- #block_raw(hash) ⇒ Object
- #blocks(params) ⇒ Object
- #estimatefee(nbBlocks = 2) ⇒ Object
-
#initialize(network: 'btc', url: nil, api_version: nil) ⇒ API
constructor
A new instance of API.
- #latest_block ⇒ Object
- #push_transaction(hex) ⇒ Object
- #rawtx(hash) ⇒ Object
- #transaction(hash) ⇒ Object
- #url ⇒ Object
- #url=(other) ⇒ Object
Constructor Details
#initialize(network: 'btc', url: nil, api_version: nil) ⇒ API
Returns a new instance of API.
6 7 8 9 10 |
# File 'lib/insight/api.rb', line 6 def initialize(network: 'btc', url: nil, api_version: nil) @url = url self.network = network @api_version = api_version end |
Instance Attribute Details
#api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
3 4 5 |
# File 'lib/insight/api.rb', line 3 def api_version @api_version end |
#network ⇒ Object
Returns the value of attribute network.
3 4 5 |
# File 'lib/insight/api.rb', line 3 def network @network end |
Instance Method Details
#address(address) ⇒ Object
58 59 60 |
# File 'lib/insight/api.rb', line 58 def address(address) @connection.get("/addr/#{address}") end |
#address_balance(address) ⇒ Object
62 63 64 |
# File 'lib/insight/api.rb', line 62 def address_balance(address) @connection.get("/addr/#{address}/balance") end |
#address_total_received(address) ⇒ Object
66 67 68 |
# File 'lib/insight/api.rb', line 66 def address_total_received(address) @connection.get("/addr/#{address}/totalReceived") end |
#address_total_sent(address) ⇒ Object
70 71 72 |
# File 'lib/insight/api.rb', line 70 def address_total_sent(address) @connection.get("/addr/#{address}/totalSent") end |
#address_unconfirmed_balance(address) ⇒ Object
74 75 76 |
# File 'lib/insight/api.rb', line 74 def address_unconfirmed_balance(address) @connection.get("/addr/#{address}/unconfirmedBalance") end |
#address_unspent_transactions(address, params = nil) ⇒ Object
78 79 80 |
# File 'lib/insight/api.rb', line 78 def address_unspent_transactions(address, params = nil) @connection.get("/addr/#{address}/utxo#{'?' + params.to_param if params}") end |
#block(hash) ⇒ Object
30 31 32 |
# File 'lib/insight/api.rb', line 30 def block(hash) @connection.get("/block/#{hash}") end |
#block_raw(hash) ⇒ Object
42 43 44 |
# File 'lib/insight/api.rb', line 42 def block_raw(hash) @connection.get("/rawblock/#{hash}") end |
#blocks(params) ⇒ Object
34 35 36 |
# File 'lib/insight/api.rb', line 34 def blocks(params) @connection.get("/blocks#{'?' + params.to_param if params}") end |
#estimatefee(nbBlocks = 2) ⇒ Object
82 83 84 |
# File 'lib/insight/api.rb', line 82 def estimatefee(nbBlocks = 2) @connection.get("/utils/estimatefee?nbBlocks=#{nbBlocks}") end |
#latest_block ⇒ Object
38 39 40 |
# File 'lib/insight/api.rb', line 38 def latest_block blocks(limit: 1)[:blocks].first end |
#push_transaction(hex) ⇒ Object
54 55 56 |
# File 'lib/insight/api.rb', line 54 def push_transaction(hex) @connection.post('/tx/send', rawtx: hex) end |
#rawtx(hash) ⇒ Object
50 51 52 |
# File 'lib/insight/api.rb', line 50 def rawtx(hash) @connection.get("/rawtx/#{hash}") end |
#transaction(hash) ⇒ Object
46 47 48 |
# File 'lib/insight/api.rb', line 46 def transaction(hash) @connection.get("/tx/#{hash}") end |
#url ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/insight/api.rb', line 12 def url @url ||= if network == 'btc' 'https://insight.bitpay.com/api' else 'https://test-insight.bitpay.com/api' end end |
#url=(other) ⇒ Object
20 21 22 23 |
# File 'lib/insight/api.rb', line 20 def url=(other) @url = other @connection = Connection.new(other) end |