GDP Data API - Ruby Gem

Get GDP (Gross Domestic Product) data for any country including current values and historical data going back to 1960.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_gdp'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_gdp

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_gdp'

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

# Make a request
response = client.execute({
  country: "US",
  year: 2023
})

# Print the response
puts response

Error Handling

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

Debug Mode

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

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "country": "US",
    "countryName": "United States",
    "currency": "USD",
    "year": 2023,
    "gdp": 27360935000000,
    "gdpFormatted": "$27.36 trillion",
    "gdpGrowth": 2.54,
    "gdpPerCapita": 81632,
    "count": 1,
    "years": [
      {
        "year": 2023,
        "gdp": 27360935000000,
        "gdpFormatted": "$27.36 trillion",
        "gdpGrowth": 2.54,
        "gdpPerCapita": 81632
      }
    ]
  },
  "code": 200
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.