class Covid19::Services::Covid19Data

Constants

RESOURCES
URI

Public Class Methods

all_continents() click to toggle source
# File lib/covid19/services/covid19_data.rb, line 12
def all_continents
  data(resource: RESOURCES[:continents])
end
all_countries() click to toggle source
# File lib/covid19/services/covid19_data.rb, line 16
def all_countries
  data(resource: RESOURCES[:countries])
end
continent(continent_name) click to toggle source
# File lib/covid19/services/covid19_data.rb, line 20
def continent(continent_name)
  data(resource: RESOURCES[:continents], query: titleize(continent_name))
end
country(country_name) click to toggle source
# File lib/covid19/services/covid19_data.rb, line 24
def country(country_name)
  data(resource: RESOURCES[:countries], query: titleize(country_name))
end

Private Class Methods

data(resource:, query: nil) click to toggle source
# File lib/covid19/services/covid19_data.rb, line 28
def data(resource:, query: nil)
  response = HTTParty.get("#{URI}/#{resource}/#{query}")
 
  JSON.parse(response.body)
end
titleize(string) click to toggle source
# File lib/covid19/services/covid19_data.rb, line 34
def titleize(string)
  string
    .split('_')
    .map { |str| str.capitalize }
    .join('%20')
end