lib/zold/wts.rb in zold-ruby-sdk-0.2.3 vs lib/zold/wts.rb in zold-ruby-sdk-0.3.0
- old
+ new
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-# Copyright (c) 2018-2020 Yegor Bugayenko
+# Copyright (c) 2018-2023 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -29,11 +29,11 @@
require 'zold/txn'
# WTS gateway.
#
# Author:: Yegor Bugayenko (yegor256@gmail.com)
-# Copyright:: Copyright (c) 2018-2020 Yegor Bugayenko
+# Copyright:: Copyright (c) 2018-2023 Yegor Bugayenko
# License:: MIT
class Zold::WTS
# Fake implementation.
class Fake
def pull
@@ -162,15 +162,16 @@
# find(details: /pizza/, bnf: '0000000000000000')
#
# The method returns an array of Zold::Txn objects.
def find(query)
start = Time.now
+ tail = query.map do |k, v|
+ "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
+ end.join('&')
http = clean(
Typhoeus::Request.get(
- 'https://wts.zold.io/find?' + query.map do |k, v|
- "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
- end.join('&'),
+ "https://wts.zold.io/find?#{tail}",
headers: headers
)
)
txns = http.body.split("\n").map { |t| Zold::Txn.parse(t) }
@log.debug("#{txns.count} transactions found in #{Zold::Age.new(start)}")
@@ -181,14 +182,12 @@
# method returns 'OK' in a few seconds (up to a few minutes). If the
# is some error, the exception will be raised.
def wait(job, time: 5 * 60)
start = Time.now
loop do
- if Time.now - start > time
- raise "Can't wait any longer for the job #{job} to complete"
- end
+ raise "Can't wait any longer for the job #{job} to complete" if Time.now - start > time
http = Typhoeus::Request.get(
- 'https://wts.zold.io/job?id=' + job,
+ "https://wts.zold.io/job?id=#{job}",
headers: headers
)
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'