Class: Utils
- Inherits:
-
Object
- Object
- Utils
- Defined in:
- lib/utils.rb
Class Method Summary collapse
-
.bchbtc_price ⇒ float
fetch bch/btc price from coin market cap.
-
.bchxrp_price ⇒ float
fetch bch/xrp price from coin market cap.
-
.btcltc_price ⇒ float
fetch btc/ltc price from coin market cap.
-
.btcxrp_price ⇒ float
fetch btc/xrp price from coin market cap.
-
.eoseth_price ⇒ float
fetch eos/eth price from coin market cap.
-
.kill_process(pid) ⇒ FalseClass and TrueClass
Try and read the existing pid from the pid file and signal the process.
-
.ltcbch_price ⇒ float
fetch ltc/bch price from coin market cap.
-
.ltcbtc_price ⇒ float
fetch ltc/btc price from coin market cap.
-
.ltcxrp_price ⇒ float
fetch ltc/xrp price from coin market cap.
-
.quote(market) ⇒ FalseClass and Float
accept market paramter and return the coinmarket cap quote for said market.
Class Method Details
.bchbtc_price ⇒ float
fetch bch/btc price from coin market cap
80 81 82 83 84 |
# File 'lib/utils.rb', line 80 def self.bchbtc_price response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/1831/?convert=BTC') hash = JSON.parse (response.body) hash['data']['quotes']['BTC']['price'].to_f.round(4) end |
.bchxrp_price ⇒ float
fetch bch/xrp price from coin market cap
48 49 50 51 52 |
# File 'lib/utils.rb', line 48 def self.bchxrp_price response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/1831/?convert=XRP') hash = JSON.parse(response.body) hash['data']['quotes']['XRP']['price'].to_f.round(4) end |
.btcltc_price ⇒ float
fetch btc/ltc price from coin market cap
64 65 66 67 68 |
# File 'lib/utils.rb', line 64 def self.btcltc_price response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/1/?convert=LTC') hash = JSON.parse(response.body) hash['data']['quotes']['LTC']['price'].to_f.round(4) end |
.btcxrp_price ⇒ float
fetch btc/xrp price from coin market cap
88 89 90 91 92 |
# File 'lib/utils.rb', line 88 def self.btcxrp_price response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/1/?convert=XRP') hash = JSON.parse (response.body) hash['data']['quotes']['XRP']['price'].to_f.round(4) end |
.eoseth_price ⇒ float
fetch eos/eth price from coin market cap
96 97 98 99 100 |
# File 'lib/utils.rb', line 96 def self.eoseth_price 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) ⇒ FalseClass and TrueClass
Try and read the existing pid from the pid file and signal the process. Returns true for a non blocking status.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/utils.rb', line 106 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 |
.ltcbch_price ⇒ float
fetch ltc/bch price from coin market cap
40 41 42 43 44 |
# File 'lib/utils.rb', line 40 def self.ltcbch_price response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/2/?convert=BCH') hash = JSON.parse(response.body) hash['data']['quotes']['BCH']['price'].to_f.round(4) end |
.ltcbtc_price ⇒ float
fetch ltc/btc price from coin market cap
56 57 58 59 60 |
# File 'lib/utils.rb', line 56 def self.ltcbtc_price response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/2/?convert=BTC') hash = JSON.parse(response.body) hash['data']['quotes']['BTC']['price'].to_f.round(4) end |
.ltcxrp_price ⇒ float
fetch ltc/xrp price from coin market cap
32 33 34 35 36 |
# File 'lib/utils.rb', line 32 def self.ltcxrp_price response = RestClient.get('https://api.coinmarketcap.com/v2/ticker/2/?convert=XRP') hash = JSON.parse(response.body) hash['data']['quotes']['XRP']['price'].to_f.round(4) end |
.quote(market) ⇒ FalseClass and Float
accept market paramter and return the coinmarket cap quote for said market
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/utils.rb', line 5 def self.quote(market) case market when 'bchxrp' bchxrp_price when 'bchbtc' bchbtc_price when 'btcxrp' btcxrp_price when 'eoseth' eoseth_price when 'btcltc' btcltc_price when 'ltcbtc' ltcbtc_price when 'bchxrp' bchxrp_price when 'ltcbch' ltcbch_price when 'ltcxrp' ltcxrp_price else false end end |