Sha256: f0d41d6e65646899cd413de333f9c40e87c8e752d6e025e7c0449b34a4eb0069

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

require 'typhoeus'
require 'json'
require_relative 'tablelize'

module Kovid
  class Request
    BASE_URL = 'https://corona.lmao.ninja'

    class << self
      require 'pry'
      def by_country(name)
        path = "/countries/#{name}"
        fetch_url = BASE_URL + path

        response ||= JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 3600).response_body)
        Kovid::Tablelize.country_table(response)
      end

      def by_country_full(name)
        path = "/countries/#{name}"
        fetch_url = BASE_URL + path

        response ||= JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 3600).response_body)
        Kovid::Tablelize.full_country_table(response)
      end

      def by_country_comparison(list)
        array = []


        list.each do |country|
          path = "/countries/#{country}"
          fetch_url = BASE_URL + path

          array << JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 3600).response_body)
        end

        Kovid::Tablelize.compare_countries_table(array)
      end

      def by_country_comparison_full(list)
        array = []

        list.each do |country|
          path = "/countries/#{country}"
          fetch_url = BASE_URL + path

          array << JSON.parse(Typhoeus.get(fetch_url.to_s, cache_ttl: 3600).response_body)
        end

        Kovid::Tablelize.compare_countries_table_full(array)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kovid-0.1.4 lib/kovid/request.rb