sibit 0.13.0 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e93c805c891cda23a83a22d1b2672e8bee9f50cd6bd6cdce29e5554f782faa4a
4
- data.tar.gz: 1dbfc35d75a85cc9fa4c480429357f2361f588307ca87ee740a10acdfa558d83
3
+ metadata.gz: 217f15565505e50e8f5d019458edb7a1ced3ae311d3aa8a3600ee9c00f9636fe
4
+ data.tar.gz: c98b24bb8acdb59652eea6eab03397487ee0e9be66e9791fac3a2397b5a108fc
5
5
  SHA512:
6
- metadata.gz: ba8615db5e241046b2c47f11cb5c238973d39753eda17b96ecd942c385e680204bf4a5aeb2af2a247d7c8fac7f7f5963bd4761c009715ae65f7cb7e7055aa0b6
7
- data.tar.gz: 02d888118626eb0cda9b9d282a310f33e1fc28cd587a7de871a2d2a283d60ac82c84e3b4a14c150a28201db085b11ca00a0c8a05f8bd0fbe449f96920ee2d44a
6
+ metadata.gz: ad0fa1e2cc7589eb8f0016b7ba8735750e033dbf1dd8776f6b6ac0e7e2acbb5f8ae4d6d69918cb35fb1031ab1218b4523cc6c6e27602cb29d0643d9bb990b9a8
7
+ data.tar.gz: 43fc86116a93558807dfea80b9af201a9958c2b5a788309287a72591d9e44bfdb6abf6441d8a6ea3fce952a2a5168c191b1500732b8ac8a5fa8bb03c3b906fd3
@@ -52,7 +52,9 @@ class Sibit
52
52
  URI('https://blockchain.info/ticker')
53
53
  )[currency]
54
54
  raise Error, "Unrecognized currency #{currency}" if h.nil?
55
- h['15m']
55
+ price = h['15m']
56
+ @log.info("The price of BTC is #{price} USD")
57
+ price
56
58
  end
57
59
 
58
60
  # Gets the balance of the address, in satoshi.
@@ -52,7 +52,12 @@ class Sibit
52
52
  def balance(address)
53
53
  uri = URI("https://chain.api.btc.com/v3/address/#{address}/unspent")
54
54
  json = Sibit::Json.new(http: @http, log: @log).get(uri)
55
- txns = json['data']['list']
55
+ data = json['data']
56
+ if data.nil?
57
+ @log.info("The balance of #{address} is zero (not found)")
58
+ return 0
59
+ end
60
+ txns = data['list']
56
61
  balance = txns.map { |tx| tx['value'] }.inject(&:+) || 0
57
62
  @log.info("The balance of #{address} is #{balance}, total txns: #{txns.count}")
58
63
  balance
@@ -26,5 +26,5 @@
26
26
  # License:: MIT
27
27
  class Sibit
28
28
  # Current version of the library.
29
- VERSION = '0.13.0'
29
+ VERSION = '0.13.1'
30
30
  end
@@ -42,6 +42,17 @@ class TestBtc < Minitest::Test
42
42
  assert_equal(0, balance)
43
43
  end
44
44
 
45
+ def test_get_empty_balance
46
+ stub_request(
47
+ :get,
48
+ 'https://chain.api.btc.com/v3/address/1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f/unspent'
49
+ ).to_return(body: '{"data":null,"err_no":1,"err_msg":"Resource Not Found"}')
50
+ sibit = Sibit::Btc.new
51
+ balance = sibit.balance('1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f')
52
+ assert(balance.is_a?(Integer))
53
+ assert_equal(0, balance)
54
+ end
55
+
45
56
  def test_get_balance
46
57
  stub_request(
47
58
  :get,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sibit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko