Class: Covid19

Inherits:
Object
  • Object
show all
Defined in:
lib/covid19.rb

Overview

Ruby wrapper for covid19api.com/.

Constant Summary collapse

BASE_URL =
'https://api.covid19api.com'.freeze
STATUSES =
%w[confirmed recovered deaths].freeze

Class Method Summary collapse

Class Method Details

.allObject

Warning: returns 10MB of data - use with caution.



16
17
18
# File 'lib/covid19.rb', line 16

def all
  serve_request('all')
end

.cases_by_country(country, status) ⇒ Object



48
49
50
51
52
# File 'lib/covid19.rb', line 48

def cases_by_country(country, status)
  return invalid_status_msg(status) unless valid_status?(status)

  serve_request("/country/#{country}/status/#{status}")
end

.cases_by_country_live(country, status) ⇒ Object



54
55
56
57
58
# File 'lib/covid19.rb', line 54

def cases_by_country_live(country, status)
  return invalid_status_msg(status) unless valid_status?(status)

  serve_request("/country/#{country}/status/#{status}/live")
end

.cases_by_country_total(country, status) ⇒ Object



60
61
62
63
64
# File 'lib/covid19.rb', line 60

def cases_by_country_total(country, status)
  return invalid_status_msg(status) unless valid_status?(status)

  serve_request("/total/country/#{country}/status/#{status}")
end

.cases_by_day_one(country, status) ⇒ Object



32
33
34
35
36
# File 'lib/covid19.rb', line 32

def cases_by_day_one(country, status)
  return invalid_status_msg(status) unless valid_status?(status)

  serve_request("/dayone/country/#{country}/status/#{status}")
end

.cases_by_day_one_live(country, status) ⇒ Object



38
39
40
41
42
# File 'lib/covid19.rb', line 38

def cases_by_day_one_live(country, status)
  return invalid_status_msg(status) unless valid_status?(status)

  serve_request("/dayone/country/#{country}/status/#{status}/live")
end

.cases_by_day_one_total(country, status) ⇒ Object



44
45
46
# File 'lib/covid19.rb', line 44

def cases_by_day_one_total(country, status)
  serve_request("/total/dayone/country/#{country}/status/#{status}")
end

.cases_live_by_country_after_date(country, status, date = (DateTime.now - 1).to_s) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/covid19.rb', line 72

def cases_live_by_country_after_date(
  country,
  status,
  date = (DateTime.now - 1).to_s
)
  return invalid_status_msg(status) unless valid_status?(status)

  serve_request("/live/country/#{country}/status/#{status}/date/#{date}")
end

.cases_live_by_country_and_status(country, status) ⇒ Object



66
67
68
69
70
# File 'lib/covid19.rb', line 66

def cases_live_by_country_and_status(country, status)
  return invalid_status_msg(status) unless valid_status?(status)

  serve_request("/live/country/#{country}/status/#{status}")
end

.countriesObject



28
29
30
# File 'lib/covid19.rb', line 28

def countries
  serve_request('countries')
end

.infoObject



11
12
13
# File 'lib/covid19.rb', line 11

def info
  serve_request('')
end

.statsObject



20
21
22
# File 'lib/covid19.rb', line 20

def stats
  serve_request('stats')
end

.summaryObject



24
25
26
# File 'lib/covid19.rb', line 24

def summary
  serve_request('summary')
end