Skip to content

Commit

Permalink
#6 usd_rate()
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jul 5, 2019
1 parent 1e542bf commit 4ed0c0e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/zold/wts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ def pay(keygap, bnf, amount, details)
job
end

# Returns current USD rate of one ZLD.
def usd_rate
clean(Typhoeus::Request.get('https://wts.zold.io/usd_rate')).body.to_f
end

# Find transactions by the criteria. All criterias are regular expressions
# and their summary result is concatenated by OR. For example, this request
# will return all transactions that have "pizza" in details OR which
Expand Down Expand Up @@ -184,7 +189,8 @@ def wait(job, time: 5 * 60)
raise "Job #{job} not found on the server" if http.code == 404
raise "Unpredictable response code #{http.code}" unless http.code == 200
if http.body == 'Running'
@log.debug("Job #{job} is still running, #{Zold::Age.new(start)} already...")
@log.debug("Job #{job} is still running, \
#{Zold::Age.new(start)} already...")
sleep 1
next
end
Expand Down
6 changes: 6 additions & 0 deletions test/zold/test_wts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def test_retrieves_balance
assert(!wts.balance.nil?)
end

def test_retrieves_usd_rate
wts = Zold::WTS.new(KEY, log: Loog::VERBOSE)
rate = wts.usd_rate
assert(!rate.nil?)
end

def test_works_with_fake
wts = Zold::WTS::Fake.new
job = wts.pull
Expand Down

0 comments on commit 4ed0c0e

Please sign in to comment.