Country Lookup API - Ruby Gem

Country Lookup is a simple tool for looking up country data. It returns the country name, capital, and more.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_countrylookup'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_countrylookup

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_countrylookup'

# Initialize the client
client = APIVerve::Countrylookup::Client.new(api_key: "YOUR_API_KEY")

# Make a request
response = client.execute({
  country: "USA",
  majorcities: true
})

# Print the response
puts response

Error Handling

begin
  response = client.execute({ country: "USA", majorcities: true })
  puts response["data"]
rescue APIVerve::Countrylookup::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Countrylookup::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

# Enable debug logging
client = APIVerve::Countrylookup::Client.new(
  api_key: "YOUR_API_KEY",
  debug: true
)

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "search": "USA",
    "countries": [
      {
        "name": {
          "common": "United States",
          "official": "United States of America",
          "native": {
            "eng": {
              "official": "United States of America",
              "common": "United States"
            }
          }
        },
        "tld": [
          ".us"
        ],
        "cca2": "US",
        "ccn3": "840",
        "cca3": "USA",
        "cioc": "USA",
        "independent": true,
        "status": "officially-assigned",
        "capital": [
          "Washington D.C."
        ],
        "altSpellings": [
          "US",
          "USA",
          "United States of America"
        ],
        "region": "Americas",
        "subregion": "North America",
        "languages": {
          "eng": "English"
        },
        "latlng": [
          38,
          -97
        ],
        "landlocked": false,
        "flag": "🇺🇸"
      }
    ]
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.