Class: Utils
- Inherits:
-
Object
- Object
- Utils
- Defined in:
- lib/utils.rb
Class Method Summary collapse
- .get_bchbtc_price ⇒ Object
- .get_bchxrp_price ⇒ Object
- .get_eoseth_price ⇒ Object
-
.kill_process(pid) ⇒ Object
Try and read the existing pid from the pid file and signal the process.
Class Method Details
.get_bchbtc_price ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/utils.rb', line 9 def self.get_bchbtc_price # fetch bch/xrp price from coin market cap factor = rand(1...1.01) response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/1831/?convert=BTC') hash = JSON.parse (response.body) return hash['data']['quotes']['BTC']['price'].to_f.round(4) * factor end |
.get_bchxrp_price ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/utils.rb', line 2 def self.get_bchxrp_price # fetch bch/xrp price from coin market cap factor = rand(1...1.01) response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/1831/?convert=XRP') hash = JSON.parse (response.body) return hash['data']['quotes']['XRP']['price'].to_f.round(4) * factor end |
.get_eoseth_price ⇒ Object
16 17 18 19 20 21 |
# File 'lib/utils.rb', line 16 def self.get_eoseth_price # fetch bch/xrp price from coin market cap response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/1765/?convert=ETH') hash = JSON.parse (response.body) return hash['data']['quotes']['ETH']['price'].to_f.round(4) end |
.kill_process(pid) ⇒ Object
Try and read the existing pid from the pid file and signal the process. Returns true for a non blocking status.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/utils.rb', line 25 def self.kill_process(pid) opid = File.read("#{pid}.pid").strip.to_i Process.kill "HUP", opid File.delete("#{pid}.pid") File.delete("#{pid}.outfile") File.delete("#{pid}.errfile") puts "Stopped process #{pid}" true rescue Errno::ENOENT $stdout.puts "#{pid} did not exist: Errno::ENOENT" true rescue Errno::ESRCH $stdout.puts "The process #{opid} did not exist: Errno::ESRCH" true rescue Errno::EPERM $stderr.puts "Lack of privileges to manage the process #{opid}: Errno::EPERM" false rescue ::Exception => e $stderr.puts "While signaling the PID, unexpected #{e.class}: #{e}" false end |