ccy-rates 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/ccy-rates.gemspec +1 -1
  3. data/index.rb +20 -5
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55fc2d117360bb97505c0ba16912ffae1e8b7996
4
- data.tar.gz: bee933d40beb366d290dded3eb31eba1e6c56f01
3
+ metadata.gz: dd64ad8ec255deaf5ed4b74b181ba2f230509d48
4
+ data.tar.gz: 0c07d12798c6d2223b09edd8f65a062d3e1e57d1
5
5
  SHA512:
6
- metadata.gz: 056bedf74fefe8e2d1b56f2d7385dbb8f95790fe63bda179ab24587bfcf33b20ac1947d98ff0fc1872db0951b106695ed5a3636feccf74691c3e08552b6c828f
7
- data.tar.gz: 5a2cc751e3068fabb07f2c3f4ec7c9e90b43633bb38c1e807adc8689429bed4997afaa4690100ba7d54117b76260bf747c554919c575ca0e5eeef9c0e0572297
6
+ metadata.gz: 4a012665eeb7c8a9c9b3ca6859d7ad0c29a03c95e312af108b45df1e0ad3476d4429a71a928fc00747ee51090f84f4030ada9bf1a4650e830df2d1ffd3a4106f
7
+ data.tar.gz: 4f1cd048a2e09fdbea7abb24aed840a9c799b361241204416c1056ba17ccd3324d40ea504d4f729e97a5d72f118409fe7d183f9b267491a857990da927abdca3
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ccy-rates"
6
- s.version = "1.0.1"
6
+ s.version = "1.0.2"
7
7
  s.author = "Yaroslav Konoplov"
8
8
  s.email = "eahome00@gmail.com"
9
9
  s.summary = "Currency exchange rates in your shell."
data/index.rb CHANGED
@@ -68,58 +68,73 @@ def print_rates(source, rates)
68
68
  end
69
69
 
70
70
  def privatbank_exchange_office_rates
71
+ url = "https://api.privatbank.ua/p24api/pubinfo?json&exchange&coursid=5"
71
72
  rates = {}
72
- JSON.load(Faraday.get("https://api.privatbank.ua/p24api/pubinfo?json&exchange&coursid=5").body).tap do |x|
73
+ JSON.load(Faraday.get(url).body).tap do |x|
73
74
  x.each do |y|
74
75
  ccy = normalize_currency_name(y["ccy"])
75
76
  rates[ccy] = { ccy: ccy, buy: y["sale"].to_f, sell: y["buy"].to_f }
76
77
  end
77
78
  end
78
79
  print_rates("PrivatBank (currency exchange office)", rates)
80
+ rescue Faraday::Error => e
81
+ warn "Failed to load #{url}: #{e.inspect}."
79
82
  end
80
83
 
81
84
  def privatbank_cashless_rates
85
+ url = "https://api.privatbank.ua/p24api/pubinfo?json&exchange&coursid=11"
82
86
  rates = {}
83
- JSON.load(Faraday.get("https://api.privatbank.ua/p24api/pubinfo?json&exchange&coursid=11").body).tap do |x|
87
+ JSON.load(Faraday.get(url).body).tap do |x|
84
88
  x.each do |y|
85
89
  ccy = normalize_currency_name(y["ccy"])
86
90
  rates[ccy] = { ccy: ccy, buy: y["sale"].to_f, sell: y["buy"].to_f }
87
91
  end
88
92
  end
89
93
  print_rates("PrivatBank (cashless)", rates)
94
+ rescue Faraday::Error => e
95
+ warn "Failed to load #{url}: #{e.inspect}."
90
96
  end
91
97
 
92
98
  def national_bank_of_ukraine_rates
99
+ url = "https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?json"
93
100
  rates = {}
94
- JSON.load(Faraday.get("https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?json").body).tap do |x|
101
+ JSON.load(Faraday.get(url).body).tap do |x|
95
102
  x.each do |y|
96
103
  ccy = normalize_currency_name(y["cc"])
97
104
  rates[ccy] = { ccy: ccy, buy: y["rate"].to_f }
98
105
  end
99
106
  end
100
107
  print_rates("National Bank of Ukraine", rates)
108
+ rescue Faraday::Error => e
109
+ warn "Failed to load #{url}: #{e.inspect}."
101
110
  end
102
111
 
103
112
  def finance_ua_black_market_rates
113
+ url = "https://finance.ua/"
104
114
  rates = {}
105
- document = Nokogiri::HTML.fragment(Faraday.get("https://finance.ua/").body) { |config| config.nonet.huge.nowarning.noerror }
115
+ document = Nokogiri::HTML.fragment(Faraday.get(url).body) { |config| config.nonet.huge.nowarning.noerror }
106
116
  td_els = document.at_css("#table-currency-tab0").css("> table > tbody > tr:nth-child(2n+1) > td")
107
117
  td_els.to_a.in_groups_of 3, false do |group|
108
118
  ccy = normalize_currency_name(group[0].text)
109
119
  rates[ccy] = { ccy: ccy, buy: group[2].text.squish.to_f, sell: group[1].text.squish.to_f }
110
120
  end
111
121
  print_rates("Black Market (finance.ua)", rates)
122
+ rescue Faraday::Error => e
123
+ warn "Failed to load #{url}: #{e.inspect}."
112
124
  end
113
125
 
114
126
  def finance_i_ua_black_market_rates
127
+ url = "https://finance.i.ua/"
115
128
  rates = {}
116
- document = Nokogiri::HTML.fragment(Faraday.get("https://finance.i.ua/").body) { |config| config.nonet.huge.nowarning.noerror }
129
+ document = Nokogiri::HTML.fragment(Faraday.get(url).body) { |config| config.nonet.huge.nowarning.noerror }
117
130
  document.at_css(".widget-currency_cash").css("tbody tr").each do |tr|
118
131
  ccy = normalize_currency_name(tr.at_css("th").text)
119
132
  tds = tr.css("td")
120
133
  rates[ccy] = { ccy: ccy, buy: tds[1].text.squish.to_f, sell: tds[0].text.squish.to_f }
121
134
  end
122
135
  print_rates("Black Market (finance.i.ua)", rates)
136
+ rescue Faraday::Error => e
137
+ warn "Failed to load #{url}: #{e.inspect}."
123
138
  end
124
139
 
125
140
  print "Today's currency exchange rates in Ukraine".colorize(:yellow),
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ccy-rates
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaroslav Konoplov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-29 00:00:00.000000000 Z
11
+ date: 2017-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri