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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62b08f268f6500bd01a16f58e6f723f6cb38c993a462a1c5df7ac3d81bb92124
4
- data.tar.gz: 7ce4bf26fc74ef311e456ec9d5e75e0fc8b2f149643153d2afa95a018383a319
3
+ metadata.gz: 97ca9cfffdcd5f3a9f1fefe000e304ebed0fb015ac6ecca7f1e0740f658d2706
4
+ data.tar.gz: aab2c25abd4c5dbc35b0cd020d210dd8e7ed9057545dd9dd11bae77c751cc891
5
5
  SHA512:
6
- metadata.gz: 23e2acc82bc376fc649469c901b155b81672000ac07debb5c4ad04f51271871528fe320e24b71710165f76d2dd3adde89417011a3e361643a67a9991fc19afb5
7
- data.tar.gz: 5b16bbf5ea2cbba4cf2c6eb2944a8dccef026872479c5a14e086e0b6fbe0ca7e0c45d2188b406fa357c7927adc7b69bc7619292e77ca33b590ad37e1fff1f013
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
- path = "/countries/#{country_name}"
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
- path = "/countries/#{country_name}"
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
@@ -50,11 +50,29 @@ module Kovid
50
50
  end
51
51
 
52
52
  def compare_countries_table_full(data)
53
- headings = ['Country', 'Cases', 'Deaths', 'Recovered', 'Cases Today', 'Deaths Today', 'Critical', 'Cases/Million']
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 << [country['country'], country['cases'], country['deaths'], country['recovered'], country['todayCases'], country['todayDeaths'], country['critical'], country['casesPerOneMillion']]
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kovid
4
- VERSION = '0.1.8'
4
+ VERSION = '0.1.9'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kovid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emmanuel Hayford