Class: BasicInfo

Inherits:
Object
  • Object
show all
Includes:
GetInfo
Defined in:
lib/nation/basic_info.rb

Overview

API Documentation: restcountries.eu/#sources

Instance Method Summary collapse

Instance Method Details

#get(nation_code) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/nation/basic_info.rb', line 10

def get(nation_code)
    api_endpoint = "https://restcountries.eu/rest/v2/name/#{nation_code}?fullText=true"
    response = get_api_info(api_endpoint).first

    raise "Country info not avaliable" if response.class != Hash

    languages = response["languages"].map{|k, v| k["name"]}
    country_basic_info = {"name": response["name"], "capital": response["capital"], "continent": response["region"],
    "region": response["subregion"], "population": response["population"], "languages": languages}
end