kovid 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/kovid/request.rb +24 -27
- data/lib/kovid/tablelize.rb +20 -2
- data/lib/kovid/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97ca9cfffdcd5f3a9f1fefe000e304ebed0fb015ac6ecca7f1e0740f658d2706
|
4
|
+
data.tar.gz: aab2c25abd4c5dbc35b0cd020d210dd8e7ed9057545dd9dd11bae77c751cc891
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0ab48dd5eab1558eb352062d6b9f4351e92402741b641114dbf9928ccc35f0f04c965da6d53401fa05041cc75b8aa4cc65cd8dafeffc1d1fb1f7c9a1db79702
|
7
|
+
data.tar.gz: 54caa7825986c4b5f42d93b22e2201d4690cd3a9cb3059ded43c16fb12649c6c77c5ec59f7ea87d931329d286f14da9056756412d9d4a068a9c43908d2a96abb
|
data/lib/kovid/request.rb
CHANGED
@@ -11,51 +11,28 @@ module Kovid
|
|
11
11
|
class << self
|
12
12
|
require 'pry'
|
13
13
|
def by_country(country_name)
|
14
|
-
|
15
|
-
fetch_url = BASE_URL + path
|
14
|
+
response = fetch_country(country_name)
|
16
15
|
|
17
|
-
response ||= JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 3600).response_body)
|
18
16
|
Kovid::Tablelize.country_table(response)
|
19
17
|
rescue JSON::ParserError
|
20
18
|
no_case_in(country_name)
|
21
19
|
end
|
22
20
|
|
23
21
|
def by_country_full(country_name)
|
24
|
-
|
25
|
-
fetch_url = BASE_URL + path
|
22
|
+
response = fetch_country(country_name)
|
26
23
|
|
27
|
-
response ||= JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 3600).response_body)
|
28
24
|
Kovid::Tablelize.full_country_table(response)
|
29
25
|
rescue JSON::ParserError
|
30
26
|
no_case_in(country_name)
|
31
27
|
end
|
32
28
|
|
33
29
|
def by_country_comparison(list)
|
34
|
-
array =
|
35
|
-
|
36
|
-
list.each do |country|
|
37
|
-
path = "/countries/#{country}"
|
38
|
-
fetch_url = BASE_URL + path
|
39
|
-
|
40
|
-
array << JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 3600).response_body)
|
41
|
-
end
|
42
|
-
|
43
|
-
array = array.sort_by { |json| -json['cases'] }
|
44
|
-
|
30
|
+
array = fetch_countries(list)
|
45
31
|
Kovid::Tablelize.compare_countries_table(array)
|
46
32
|
end
|
47
33
|
|
48
34
|
def by_country_comparison_full(list)
|
49
|
-
array =
|
50
|
-
|
51
|
-
list.each do |country|
|
52
|
-
path = "/countries/#{country}"
|
53
|
-
fetch_url = BASE_URL + path
|
54
|
-
|
55
|
-
array << JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 3600).response_body)
|
56
|
-
end
|
57
|
-
array = array.sort_by { |json| -json['cases'] }
|
58
|
-
|
35
|
+
array = fetch_countries(list)
|
59
36
|
Kovid::Tablelize.compare_countries_table_full(array)
|
60
37
|
end
|
61
38
|
|
@@ -75,6 +52,26 @@ module Kovid
|
|
75
52
|
table = Terminal::Table.new headings: [country.capitalize.to_s], rows: rows
|
76
53
|
puts table
|
77
54
|
end
|
55
|
+
|
56
|
+
def fetch_countries(list)
|
57
|
+
array = []
|
58
|
+
|
59
|
+
list.each do |country|
|
60
|
+
path = "/countries/#{country}"
|
61
|
+
fetch_url = BASE_URL + path
|
62
|
+
|
63
|
+
array << JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 3600).response_body)
|
64
|
+
end
|
65
|
+
|
66
|
+
array = array.sort_by { |json| -json['cases'] }
|
67
|
+
end
|
68
|
+
|
69
|
+
def fetch_country(country_name)
|
70
|
+
path = "/countries/#{country_name}"
|
71
|
+
fetch_url = BASE_URL + path
|
72
|
+
|
73
|
+
JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 3600).response_body)
|
74
|
+
end
|
78
75
|
end
|
79
76
|
end
|
80
77
|
end
|
data/lib/kovid/tablelize.rb
CHANGED
@@ -50,11 +50,29 @@ module Kovid
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def compare_countries_table_full(data)
|
53
|
-
headings = [
|
53
|
+
headings = [
|
54
|
+
'Country',
|
55
|
+
'Cases',
|
56
|
+
'Deaths',
|
57
|
+
'Recovered',
|
58
|
+
'Cases Today',
|
59
|
+
'Deaths Today',
|
60
|
+
'Critical',
|
61
|
+
'Cases/Million'
|
62
|
+
]
|
54
63
|
rows = []
|
55
64
|
|
56
65
|
data.each do |country|
|
57
|
-
rows << [
|
66
|
+
rows << [
|
67
|
+
country['country'],
|
68
|
+
country['cases'],
|
69
|
+
country['deaths'],
|
70
|
+
country['recovered'],
|
71
|
+
country['todayCases'],
|
72
|
+
country['todayDeaths'],
|
73
|
+
country['critical'],
|
74
|
+
country['casesPerOneMillion']
|
75
|
+
]
|
58
76
|
end
|
59
77
|
|
60
78
|
puts Terminal::Table.new(headings: headings, rows: rows)
|
data/lib/kovid/version.rb
CHANGED