class Sarskov::Request
Constants
- AFRICA_ISOS
- ASIA_ISOS
- BASE_URL
- COUNTRIES_PATH
- EUROPE_ISOS
- EU_ISOS
- JHUCSSE_URL
- SERVER_DOWN
- SOUTH_AMERICA_ISOS
- STATES_PATH
Public Class Methods
africa()
click to toggle source
CONTINENTS ##
# File lib/sarskov/request.rb, line 56 def africa aggregator(AFRICA_ISOS) end
asia()
click to toggle source
# File lib/sarskov/request.rb, line 72 def asia aggregator(ASIA_ISOS) end
check(country_name)
click to toggle source
FETCH METHODS ###
# File lib/sarskov/request.rb, line 31 def check(country_name) uri = URI("#{COUNTRIES_PATH}#{country_name}") JSON.parse(Net::HTTP.get(uri)) end
compare_countries(*list)
click to toggle source
Returns data sorted by 'cases'
# File lib/sarskov/request.rb, line 79 def compare_countries(*list) list.map do |country| uri = URI(COUNTRIES_PATH + country.to_s) JSON.parse(Net::HTTP.get(uri)) end.sort_by { |country| -country['cases'] } end
compare_states(*states)
click to toggle source
Returns an array of hashes containing list of states passed as parameter
# File lib/sarskov/request.rb, line 88 def compare_states(*states) JSON.parse(Net::HTTP.get(URI(STATES_PATH))).map do |state| state if states.include?(state['state'].downcase) end.compact end
eu()
click to toggle source
# File lib/sarskov/request.rb, line 64 def eu aggregator(EU_ISOS) end
europe()
click to toggle source
# File lib/sarskov/request.rb, line 60 def europe aggregator(EUROPE_ISOS) end
province()
click to toggle source
# File lib/sarskov/request.rb, line 44 def province; end
sa()
click to toggle source
# File lib/sarskov/request.rb, line 68 def sa aggregator(SOUTH_AMERICA_ISOS) end
state(state_name)
click to toggle source
# File lib/sarskov/request.rb, line 37 def state(state_name) uri = URI(STATES_PATH) states_array = JSON.parse(Net::HTTP.get(uri)) states_array.select { |sn| sn['state'] == capitalize_words(state_name) }.first end
world()
click to toggle source
WORLD ##
# File lib/sarskov/request.rb, line 48 def world uri = URI(BASE_URL + 'all/') JSON.parse(Net::HTTP.get(uri)) end
Private Class Methods
aggregator(isos)
click to toggle source
HISTORY ###
# File lib/sarskov/request.rb, line 98 def aggregator(isos) uri = URI(COUNTRIES_PATH) countries_array = JSON.parse(Net::HTTP.get(uri)) country_array = countries_array.select do |hash| isos.include?(hash['countryInfo']['iso2']) end data = country_array.inject do |base, other| base.merge(other) do |key, left, right| left ||= 0 right ||= 0 left + right unless %w[country countryInfo].include?(key) end end.compact end
capitalize_words(string)
click to toggle source
# File lib/sarskov/request.rb, line 116 def capitalize_words(string) string.split.map(&:capitalize).join(' ') end