get_balance()   B
last analyzed

Complexity

Conditions 2

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 2
c 2
b 0
f 1
dl 0
loc 24
rs 8.9713
1
def get_balance
2
  # This method is used to get the balance of the faucet.
3
  # These values are defined in config.json.
4
  wallet_pass = settings.wallet_pass
5
  wallet_id = settings.wallet_id
6
7
  url = "http://blockchain.info/merchant/#{wallet_id}/balance"
8
  request_object = { :password => wallet_pass }
9
10
  # This is in a begin...rescue...end block because if Blockchain.info
11
  # is down, getting the balance will fail.
12
  begin
13
    body = Nestful.get(url, :params => request_object)
14
  rescue
15
    return "ERROR"
16
  end
17
18
  parsed = JSON.parse body
19
20
  # The balance is given in Satoshi, so we convert it into fractional
21
  # bitcoins.
22
  amount = parsed["balance"].to_i * 0.000_000_01
23
  return amount
24
end
25
26