Sha256: 7a31f9a29c13ca60c0be1484c877fb2e43c0be6e9eb9e10534320371a6adf7f9
Contents?: true
Size: 1.04 KB
Versions: 4
Compression:
Stored size: 1.04 KB
Contents
require 'httparty' require 'json' module Covid19 module Services class Covid19Data URI = 'https://corona.lmao.ninja/v3/covid-19' RESOURCES = { continents: 'continents', countries: 'countries' } class << self def all_continents data(resource: RESOURCES[:continents]) end def all_countries data(resource: RESOURCES[:countries]) end def continent(continent_name) data(resource: RESOURCES[:continents], query: titleize(continent_name)) end def country(country_name) data(resource: RESOURCES[:countries], query: titleize(country_name)) end def data(resource:, query: nil) response = HTTParty.get("#{URI}/#{resource}/#{query}") JSON.parse(response.body) end def titleize(string) string .split('_') .map { |str| str.capitalize } .join('%20') end end private_class_method :data, :titleize end end end
Version data entries
4 entries across 4 versions & 1 rubygems