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
- #estimatefee(nbBlocks = 2) ⇒ Object
-
#initialize(network: 'btc') ⇒ API
constructor
A new instance of API.
- #push_transaction(hex) ⇒ Object
- #rawtx(hash) ⇒ Object
- #transaction(hash) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(network: 'btc') ⇒ API
Returns a new instance of API.
6 7 8 9 10 |
# File 'lib/insight/api.rb', line 6 def initialize(network:'btc') @network = network @api_version = api_version @connection = Connection.new(url) 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
45 46 47 |
# File 'lib/insight/api.rb', line 45 def address(address) @connection.get("/addr/#{address}") end |
#address_balance(address) ⇒ Object
49 50 51 |
# File 'lib/insight/api.rb', line 49 def address_balance(address) @connection.get("/addr/#{address}/balance") end |
#address_total_received(address) ⇒ Object
53 54 55 |
# File 'lib/insight/api.rb', line 53 def address_total_received(address) @connection.get("/addr/#{address}/totalReceived") end |
#address_total_sent(address) ⇒ Object
57 58 59 |
# File 'lib/insight/api.rb', line 57 def address_total_sent(address) @connection.get("/addr/#{address}/totalSent") end |
#address_unconfirmed_balance(address) ⇒ Object
61 62 63 |
# File 'lib/insight/api.rb', line 61 def address_unconfirmed_balance(address) @connection.get("/addr/#{address}/unconfirmedBalance") end |
#address_unspent_transactions(address, params = nil) ⇒ Object
65 66 67 |
# File 'lib/insight/api.rb', line 65 def address_unspent_transactions(address, params = nil) @connection.get("/addr/#{address}/utxo#{'?' + params.to_param if params}") end |
#block(hash) ⇒ Object
25 26 27 |
# File 'lib/insight/api.rb', line 25 def block(hash) @connection.get("/block/#{hash}") end |
#block_raw(hash) ⇒ Object
29 30 31 |
# File 'lib/insight/api.rb', line 29 def block_raw(hash) @connection.get("/rawblock/#{hash}") end |
#estimatefee(nbBlocks = 2) ⇒ Object
69 70 71 |
# File 'lib/insight/api.rb', line 69 def estimatefee(nbBlocks = 2) @connection.get("/utils/estimatefee?nbBlocks=#{nbBlocks}") end |
#push_transaction(hex) ⇒ Object
41 42 43 |
# File 'lib/insight/api.rb', line 41 def push_transaction(hex) @connection.post('/tx/send', rawtx: hex) end |
#rawtx(hash) ⇒ Object
37 38 39 |
# File 'lib/insight/api.rb', line 37 def rawtx(hash) @connection.get("/rawtx/#{hash}") end |
#transaction(hash) ⇒ Object
33 34 35 |
# File 'lib/insight/api.rb', line 33 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 if network == 'btc' 'https://insight.bitpay.com/api' else 'https://test-insight.bitpay.com/api' end end |