Sha256: 4845b1fbc454320207f86642b5723a0f525e48a2a8e4c34455dd0205a937dfdd

Contents?: true

Size: 1.65 KB

Versions: 3

Compression:

Stored size: 1.65 KB

Contents

class Utils
  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
  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
  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

  # Try and read the existing pid from the pid file and signal the
  # process. Returns true for a non blocking status.
  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
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
SimBot-0.1.7 lib/utils.rb
SimBot-0.1.6 lib/utils.rb
SimBot-0.1.5 lib/utils.rb