sarskov 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12b759afa44875ac51d7ade86700b311b0cda27e43befa0752bad17c9c940274
4
- data.tar.gz: 1765644c983fb48dfd2e6af128c9333ea53c6aee55e4d0fed88d757f92aef486
3
+ metadata.gz: 26a2b62614552ad3d4af0cf328f2c0e6e703d5117a404ed8e909651c07db6b6c
4
+ data.tar.gz: c02352ceedee2c9022621d445dcfecb7fff132db5689a82be6da6b1741ba14c8
5
5
  SHA512:
6
- metadata.gz: fe4aa1a5d6545ab6a74469e29e50bfefb97a9e460f0bfa6afe9ee482483065b3f596cac2c83dc6543ac0c98b0ddfd6c5952bb42dc468f95a88632afa0be25230
7
- data.tar.gz: ce0581b737a0949913788fad7ec1af32878b72690adb3c06420c1048a29e88de6ef0d30dfcba407f179f605bb1761dc1b847da769a2d7c08df93b9b935227ea0
6
+ metadata.gz: d4d7c6db37b5106ed90b2a533dbdd8338f501c337338fc6c97df850f3ab5bdbc30a53c600015577d86e853153f4d4051b27757ef91bad04622d4d21790dbbaab
7
+ data.tar.gz: f2b4578e5908a3e3e20a022b6f6cdd7eb55c515130edf9fedd8f279c581eda9809c8c4a5797b6d1ab33671331530a22eadc9ad1acb29357cffdb52091acbb7a8
data/Gemfile CHANGED
@@ -1,7 +1,9 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in sarskov.gemspec
4
6
  gemspec
5
7
 
6
- gem "rake", "~> 12.0"
7
- gem "rspec", "~> 3.0"
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rspec', '~> 3.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sarskov (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (12.3.3)
11
+ rspec (3.9.0)
12
+ rspec-core (~> 3.9.0)
13
+ rspec-expectations (~> 3.9.0)
14
+ rspec-mocks (~> 3.9.0)
15
+ rspec-core (3.9.1)
16
+ rspec-support (~> 3.9.1)
17
+ rspec-expectations (3.9.1)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.9.0)
20
+ rspec-mocks (3.9.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.9.0)
23
+ rspec-support (3.9.2)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ rake (~> 12.0)
30
+ rspec (~> 3.0)
31
+ sarskov!
32
+
33
+ BUNDLED WITH
34
+ 2.1.2
data/README.md CHANGED
@@ -1,38 +1,300 @@
1
- # Sarskov
1
+ # 😷 Sarskov
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sarskov`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Sarskov returns JSON formated statistics on COVID-19.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
6
5
 
7
6
  ## Installation
8
7
 
9
- Add this line to your application's Gemfile:
8
+ Add this line to your application's Gemfile: `gem 'sarskov'`. And then execute: `bundle install`. Or install it yourself as: `gem install sarskov`.
9
+
10
+ ## Usage
11
+ ### FETCHING
12
+ 🧫 Fetching country data
10
13
 
11
14
  ```ruby
12
- gem 'sarskov'
15
+ Sarskov::Request.check("ghana")
13
16
  ```
17
+ returns:
14
18
 
15
- And then execute:
19
+ ```json
20
+ {
21
+ "country": "Ghana",
22
+ "countryInfo": {
23
+ "_id": 288,
24
+ "iso2": "GH",
25
+ "iso3": "GHA",
26
+ "lat": 8,
27
+ "long": -2,
28
+ "flag": "https://raw.githubusercontent.com/NovelCOVID/API/master/assets/flags/gh.png"
29
+ },
30
+ "cases": 195,
31
+ "todayCases": 0,
32
+ "deaths": 5,
33
+ "todayDeaths": 0,
34
+ "recovered": 31,
35
+ "active": 159,
36
+ "critical": 1,
37
+ "casesPerOneMillion": 6,
38
+ "deathsPerOneMillion": 0.2,
39
+ "updated": 1585805640451
40
+ }
41
+ ```
16
42
 
17
- $ bundle install
43
+ 🧫 Fetch world stats:
18
44
 
19
- Or install it yourself as:
45
+ ```ruby
46
+ Sarskov::Request.world
47
+ ```
48
+ returns:
20
49
 
21
- $ gem install sarskov
50
+ ```json
51
+ {
52
+ "cases": 955136,
53
+ "deaths": 48578,
54
+ "recovered": 203011,
55
+ "updated": 1585831890796,
56
+ "active": 703547,
57
+ "affectedCountries": 205
58
+ }
59
+ ```
22
60
 
23
- ## Usage
61
+ 🧫 Fetch Fetch aggregated data on Africa (all 57 states):
62
+
63
+ ```ruby
64
+ Sarskov::Request.africa
65
+ ```
66
+ returns:
67
+
68
+ ```json
69
+ {
70
+ "cases": 6547,
71
+ "todayCases": 164,
72
+ "deaths": 244,
73
+ "todayDeaths": 8,
74
+ "recovered": 524,
75
+ "active": 5779,
76
+ "critical": 30,
77
+ "casesPerOneMillion": 520.4,
78
+ "deathsPerOneMillion": 15.7,
79
+ "updated": 77706080976400
80
+ }
81
+ ```
82
+
83
+ 🧫 Fetch Fetch aggregated data on Europe (all 45 states):
24
84
 
25
- TODO: Write usage instructions here
85
+ ```ruby
86
+ Sarskov::Request.europe
87
+ ```
88
+ returns:
89
+
90
+ ```json
91
+ {
92
+ "cases": 507309,
93
+ "todayCases": 20179,
94
+ "deaths": 35362,
95
+ "todayDeaths": 1716,
96
+ "recovered": 85480,
97
+ "active": 386467,
98
+ "critical": 24246,
99
+ "casesPerOneMillion": 49194,
100
+ "deathsPerOneMillion": 2054.3,
101
+ "updated": 68191050652346
102
+ }
103
+ ```
104
+
105
+
106
+ 🧫 Fetch aggregated data on The EU (all 28 states):
107
+ ```ruby
108
+ Sarskov::Request.eu
109
+ ```
110
+ returns:
111
+
112
+ ```json
113
+ {
114
+ "cases": 426951,
115
+ "todayCases": 0,
116
+ "deaths": 30612,
117
+ "todayDeaths": 0,
118
+ "recovered": 75010,
119
+ "active": 321329,
120
+ "critical": 23062,
121
+ "casesPerOneMillion": 18769,
122
+ "deathsPerOneMillion": 813.2,
123
+ "updated": 42816752292016
124
+ }
125
+ ```
126
+
127
+ 🧫 Fetch Fetch aggregated data on Asia (all 53 states):
128
+ ```ruby
129
+ Sarskov::Request.asia
130
+ ```
131
+ returns:
132
+
133
+ ```json
134
+ {
135
+ "cases": 191871,
136
+ "todayCases": 5005,
137
+ "deaths": 7602,
138
+ "todayDeaths": 188,
139
+ "recovered": 103818,
140
+ "active": 80451,
141
+ "critical": 5942,
142
+ "casesPerOneMillion": 4077.5000000000005,
143
+ "deathsPerOneMillion": 68.96000000000001,
144
+ "updated": 71362727427057
145
+ }
146
+ ```
147
+
148
+ 🧫 Fetch Fetch aggregated data on South America (all 15 states):
149
+ ```ruby
150
+ Sarskov::Request.sa
151
+ ```
152
+ returns:
153
+
154
+ ```json
155
+ {
156
+ "cases": 16212,
157
+ "todayCases": 512,
158
+ "deaths": 444,
159
+ "todayDeaths": 22,
160
+ "recovered": 1075,
161
+ "active": 14693,
162
+ "critical": 548,
163
+ "casesPerOneMillion": 757,
164
+ "deathsPerOneMillion": 15.700000000000001,
165
+ "updated": 17444222259947
166
+ }
167
+ ```
168
+
169
+
170
+ 🧫 Fetching state data 🇺🇸
171
+ ```ruby
172
+ Sarskov::Request.state("ohio")
173
+ ```
174
+ returns:
175
+
176
+ ```json
177
+ {
178
+ "state": "Ohio",
179
+ "cases": 2547,
180
+ "todayCases": 0,
181
+ "deaths": 65,
182
+ "todayDeaths": 0,
183
+ "active": 2482
184
+ }
185
+ ```
186
+
187
+ ### COMPARING
188
+ 🧫 Country Comparison
189
+ ```ruby
190
+ Sarskov::Request.compare_countries("poland", "ghana", "iran")
191
+ ```
192
+ returns an array of hashes sorted in DESC of number of cases:
193
+
194
+ ```json
195
+ [
196
+ {
197
+ "country": "Iran",
198
+ "countryInfo": {
199
+ "_id": 364,
200
+ "iso2": "IR",
201
+ "iso3": "IRN",
202
+ "lat": 32,
203
+ "long": 53,
204
+ "flag": "https://raw.githubusercontent.com/NovelCOVID/API/master/assets/flags/ir.png"
205
+ },
206
+ "cases": 47593,
207
+ "todayCases": 0,
208
+ "deaths": 3036,
209
+ "todayDeaths": 0,
210
+ "recovered": 15473,
211
+ "active": 29084,
212
+ "critical": 3871,
213
+ "casesPerOneMillion": 567,
214
+ "deathsPerOneMillion": 36,
215
+ "updated": 1585805640441
216
+ },
217
+ {
218
+ "country": "Poland",
219
+ "countryInfo": {
220
+ "_id": 616,
221
+ "iso2": "PL",
222
+ "iso3": "POL",
223
+ "lat": 52,
224
+ "long": 20,
225
+ "flag": "https://raw.githubusercontent.com/NovelCOVID/API/master/assets/flags/pl.png"
226
+ },
227
+ "cases": 2554,
228
+ "todayCases": 0,
229
+ "deaths": 43,
230
+ "todayDeaths": 0,
231
+ "recovered": 56,
232
+ "active": 2455,
233
+ "critical": 50,
234
+ "casesPerOneMillion": 67,
235
+ "deathsPerOneMillion": 1,
236
+ "updated": 1585805640443
237
+ },
238
+ {
239
+ "country": "Ghana",
240
+ "countryInfo": {
241
+ "_id": 288,
242
+ "iso2": "GH",
243
+ "iso3": "GHA",
244
+ "lat": 8,
245
+ "long": -2,
246
+ "flag": "https://raw.githubusercontent.com/NovelCOVID/API/master/assets/flags/gh.png"
247
+ },
248
+ "cases": 195,
249
+ "todayCases": 0,
250
+ "deaths": 5,
251
+ "todayDeaths": 0,
252
+ "recovered": 31,
253
+ "active": 159,
254
+ "critical": 1,
255
+ "casesPerOneMillion": 6,
256
+ "deathsPerOneMillion": 0.2,
257
+ "updated": 1585805640451
258
+ }
259
+ ]
260
+ ```
261
+
262
+ 🧫 State Comparison
263
+ ```ruby
264
+ Sarskov::Request.compare_states("maryland", "ohio")
265
+ ```
266
+ returns:
267
+
268
+ ```json
269
+ [
270
+ {
271
+ "state": "Ohio",
272
+ "cases": 2547,
273
+ "todayCases": 0,
274
+ "deaths": 65,
275
+ "todayDeaths": 0,
276
+ "active": 2482
277
+ },
278
+ {
279
+ "state": "Maryland",
280
+ "cases": 1985,
281
+ "todayCases": 0,
282
+ "deaths": 31,
283
+ "todayDeaths": 0,
284
+ "active": 1885
285
+ }
286
+ ]
287
+ ```
26
288
 
27
289
  ## Development
28
290
 
29
291
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
292
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
293
+ To install this gem onto your local machine, run `bundle exec rake install`.
32
294
 
33
295
  ## Contributing
34
296
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sarskov. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/sarskov/blob/master/CODE_OF_CONDUCT.md).
297
+ Bug reports and pull requests are welcome on GitHub at https://github.com/siaw23/sarskov. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/siaw23/sarskov/blob/master/CODE_OF_CONDUCT.md).
36
298
 
37
299
 
38
300
  ## License
@@ -41,4 +303,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
41
303
 
42
304
  ## Code of Conduct
43
305
 
44
- Everyone interacting in the Sarskov project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/sarskov/blob/master/CODE_OF_CONDUCT.md).
306
+ Everyone interacting in the Sarskov project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/siaw23/sarskov/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "sarskov"
4
+ require 'bundler/setup'
5
+ require 'sarskov'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "sarskov"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
@@ -7,13 +7,115 @@ module Sarskov
7
7
 
8
8
  BASE_URL = 'https://corona.lmao.ninja/'
9
9
  COUNTRIES_PATH = BASE_URL + 'countries/'
10
+ STATES_PATH = BASE_URL + 'states/'
11
+ JHUCSSE_URL = BASE_URL + '/v2/jhucsse'
12
+
13
+ SERVER_DOWN = 'Server overwhelmed. Please try again in a moment.'
14
+
15
+ EU_ISOS = %w[AT BE BG CY CZ DE DK EE ES FI FR GR HR HU IE IT LT \
16
+ LU LV MT NL PL PT RO SE SI SK].freeze
17
+ EUROPE_ISOS = EU_ISOS + %w[GB IS NO CH MC AD SM VA BA RS ME MK AL\
18
+ BY UA RU MD]
19
+ AFRICA_ISOS = %w[DZ AO BJ BW BF BI CM CV CF TD KM CD CG CI DJ EG \
20
+ GQ ER SZ ET GA GM GH GN GW KE LS LR LY MG MW ML MR MU MA MZ NA NE \
21
+ NG RW ST SN SC SL SO ZA SS SD TZ TG TN UG ZM ZW EH].freeze
22
+ SOUTH_AMERICA_ISOS = ['AR' 'BO', 'BV', 'BR', 'CL', 'CO', 'EC', \
23
+ 'FK', 'GF', 'GY', 'PY', 'PE', 'GS', 'SR', 'UY', 'VE'].freeze
24
+ ASIA_ISOS = %w[AE AF AM AZ BD BH BN BT CC CN CX GE HK ID IL IN \
25
+ IQ IR JO JP KG KH KP KR KW KZ LA LB LK MM MN MO MY NP OM PH PK \
26
+ PS QA SA SG SY TH TJ TL TM TR TW UZ VN YE].freeze
10
27
 
11
28
  class << self
29
+ ### FETCH METHODS ###
30
+
12
31
  def check(country_name)
13
32
  uri = URI("#{COUNTRIES_PATH}#{country_name}")
14
33
 
15
34
  JSON.parse(Net::HTTP.get(uri))
16
35
  end
36
+
37
+ def state(state_name)
38
+ uri = URI(STATES_PATH)
39
+ states_array = JSON.parse(Net::HTTP.get(uri))
40
+
41
+ states_array.select { |sn| sn['state'] == capitalize_words(state_name) }.first
42
+ end
43
+
44
+ def province; end
45
+
46
+ ## WORLD ##
47
+
48
+ def world
49
+ uri = URI(BASE_URL + 'all/')
50
+
51
+ JSON.parse(Net::HTTP.get(uri))
52
+ end
53
+
54
+ ## CONTINENTS ##
55
+
56
+ def africa
57
+ aggregator(AFRICA_ISOS)
58
+ end
59
+
60
+ def europe
61
+ aggregator(EUROPE_ISOS)
62
+ end
63
+
64
+ def eu
65
+ aggregator(EU_ISOS)
66
+ end
67
+
68
+ def sa
69
+ aggregator(SOUTH_AMERICA_ISOS)
70
+ end
71
+
72
+ def asia
73
+ aggregator(ASIA_ISOS)
74
+ end
75
+
76
+ ### COMPARE METHODS ###
77
+
78
+ # Returns data sorted by 'cases'
79
+ def compare_countries(*list)
80
+ list.map do |country|
81
+ uri = URI(COUNTRIES_PATH + country.to_s)
82
+
83
+ JSON.parse(Net::HTTP.get(uri))
84
+ end.sort_by { |country| -country['cases'] }
85
+ end
86
+
87
+ # Returns an array of hashes containing list of states passed as parameter
88
+ def compare_states(*states)
89
+ JSON.parse(Net::HTTP.get(URI(STATES_PATH))).map do |state|
90
+ state if states.include?(state['state'].downcase)
91
+ end.compact
92
+ end
93
+
94
+ ### HISTORY ###
95
+
96
+ private
97
+
98
+ def aggregator(isos)
99
+ uri = URI(COUNTRIES_PATH)
100
+ countries_array = JSON.parse(Net::HTTP.get(uri))
101
+
102
+ country_array = countries_array.select do |hash|
103
+ isos.include?(hash['countryInfo']['iso2'])
104
+ end
105
+
106
+ data = country_array.inject do |base, other|
107
+ base.merge(other) do |key, left, right|
108
+ left ||= 0
109
+ right ||= 0
110
+
111
+ left + right unless %w[country countryInfo].include?(key)
112
+ end
113
+ end.compact
114
+ end
115
+
116
+ def capitalize_words(string)
117
+ string.split.map(&:capitalize).join(' ')
118
+ end
17
119
  end
18
120
  end
19
121
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sarskov
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
data/lib/sarskov.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'sarskov/version'
4
+ require 'sarskov/request'
4
5
 
5
6
  module Sarskov
6
7
  class Error < StandardError; end
data/sarskov.gemspec CHANGED
@@ -1,29 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'lib/sarskov/version'
2
4
 
3
5
  Gem::Specification.new do |spec|
4
- spec.name = "sarskov"
6
+ spec.name = 'sarskov'
5
7
  spec.version = Sarskov::VERSION
6
- spec.authors = ["Emmanuel Hayford"]
7
- spec.email = ["siawmensah@gmail.com"]
8
+ spec.authors = ['Emmanuel Hayford']
9
+ spec.email = ['siawmensah@gmail.com']
8
10
 
9
- spec.summary = %q{Sarskov returns statistics on the COVID-19 pandemic in a JSON format.}
10
- spec.description = %q{Sarskov returns statistics on the COVID-19 pandemic in a JSON format.}
11
- spec.homepage = "https://github.com/siaw23/sarskov"
12
- spec.license = "MIT"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
11
+ spec.summary = 'Sarskov returns statistics on the COVID-19 pandemic in a JSON format.'
12
+ spec.description = 'Sarskov returns statistics on the COVID-19 pandemic in a JSON format.'
13
+ spec.homepage = 'https://github.com/siaw23/sarskov'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
14
16
 
15
- spec.metadata["allowed_push_host"] = "https://rubygems.org/"
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
16
18
 
17
- spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = "https://github.com/siaw23/sarskov"
19
- spec.metadata["changelog_uri"] = "https://github.com/siaw23/sarskov"
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/siaw23/sarskov'
21
+ spec.metadata['changelog_uri'] = 'https://github.com/siaw23/sarskov'
20
22
 
21
23
  # Specify which files should be added to the gem when it is released.
22
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
26
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
27
  end
26
- spec.bindir = "exe"
28
+ spec.bindir = 'exe'
27
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
30
+ spec.require_paths = ['lib']
29
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sarskov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emmanuel Hayford
@@ -22,6 +22,7 @@ files:
22
22
  - ".travis.yml"
23
23
  - CODE_OF_CONDUCT.md
24
24
  - Gemfile
25
+ - Gemfile.lock
25
26
  - LICENSE.txt
26
27
  - README.md
27
28
  - Rakefile