class Covid19Data

Constants

BASE_URL
DEFAULT_SOURCE

Public Class Methods

find_by_country_code(country_code, with_timelines: false, source: DEFAULT_SOURCE) click to toggle source
# File lib/covid19_data_ruby.rb, line 25
def find_by_country_code(country_code, with_timelines: false, source: DEFAULT_SOURCE)
  timelines = with_timelines ? '&timelines=true' : ''
  uri = URI("#{BASE_URL}locations?country_code=#{country_code.upcase}#{timelines}&source=#{source}")
  get_json_data(uri)
end
find_by_location(id, source: DEFAULT_SOURCE) click to toggle source
# File lib/covid19_data_ruby.rb, line 31
def find_by_location(id, source: DEFAULT_SOURCE)
  uri = URI("#{BASE_URL}locations/#{id}?source=#{source}")
  get_json_data(uri)
end
get_all_locations(source: DEFAULT_SOURCE) click to toggle source
# File lib/covid19_data_ruby.rb, line 20
def get_all_locations(source: DEFAULT_SOURCE)
  uri = URI("#{BASE_URL}locations?source=#{source}")
  get_json_data(uri)
end
get_latest(source: DEFAULT_SOURCE) click to toggle source
# File lib/covid19_data_ruby.rb, line 15
def get_latest(source: DEFAULT_SOURCE)
  uri = URI("#{BASE_URL}latest?source=#{source}")
  get_json_data(uri)
end
get_sources() click to toggle source
# File lib/covid19_data_ruby.rb, line 10
def get_sources
  uri = URI("#{BASE_URL}sources")
  get_json_data(uri)
end

Private Class Methods

get_json_data(uri) click to toggle source
# File lib/covid19_data_ruby.rb, line 38
def get_json_data(uri)
  response = Net::HTTP.get(uri)
  JSON.parse(response)
end