Skip to content

Instantly share code, notes, and snippets.

View onedebos's full-sized avatar

Adebola Adeniran onedebos

View GitHub Profile
@onedebos
onedebos / adebola-cv.md
Last active March 17, 2022 23:09
Resume for Adebola Adeniran
@onedebos
onedebos / Gemfile
Created March 26, 2020 15:00
Gemfile for coronaQL Rails API
gem 'httparty'
gem 'graphql'
gem 'graphiql-rails'
gem 'sprockets', '~> 3'
@onedebos
onedebos / routes.rb
Created March 26, 2020 15:10
Routes.rb file for the CoronaQL tutorial
Rails.application.routes.draw do
post "/graphql", to: "graphql#execute"
mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"
end
@onedebos
onedebos / seeds.rb
Last active March 26, 2020 16:09
Seed file for the CoronaQL tutorial
require 'httparty'
Summaries.create(id:1)
def get_countries
country_names = []
base_url = "https://corona.lmao.ninja/countries"
request = HTTParty.get(base_url).body
response = JSON.parse(request)
response.each_with_index do |c, i|
module Types
class CountryType < Types::BaseObject
field :id, ID, null: false # default field in our db
field :country_name, String, null: false # default field in our db
field :cases, Integer, null: false # from here to line 12 are auto generated fields
field :cases_today, Integer, null: false
field :deaths, Integer, null: false
field :deaths_today, Integer, null: false
field :recovered, Integer, null: false
field :active, Integer, null: false
module Types
class SummaryType < Types::BaseObject
field :total_cases, Integer, null: false
field :total_deaths, Integer, null: false
field :total_recovered, Integer, null: false
def request
base_url = "https://corona.lmao.ninja/all"
request = HTTParty.get(base_url).body
module Types
class QueryType < Types::BaseObject
field :summary, [Types::SummaryType], null: false
field :all_countries, [Types::CountryType], null: false
field :find_country, [CountryType], null: true do
argument :country_name, String, required: true
end
field :all_countries_limit, [CountryType], null: false do
argument :per_page, Integer, required: false, default_value: 10
argument :start, Integer, required: false, default_value: 1
source 'https://rubygems.org'
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
gem 'byebug'
gem 'httparty'
gem 'nokogiri'
require 'httparty'
require 'nokogiri'
require 'byebug'
require 'json'
def all_countries
unparsed_page = HTTParty.get('https://www.worldometers.info/coronavirus/')
parsed_page = Nokogiri::HTML(unparsed_page)
records = []
def find_country_by_name(country_to_find)
down_country = country_to_find.downcase
all_countries.select { |country| country[:name].downcase == down_country }
end
puts find_country("nigeria")