National Debt API - Ruby Gem

National Debt provides real-time access to the US national debt (Debt to the Penny). It returns the total public debt, debt held by the public, intragovernmental holdings, and per-capita debt calculations.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_nationaldebt'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_nationaldebt

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_nationaldebt'

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

# Make a request
response = client.execute({ date: "2023-06-15" })

# Print the response
puts response

Error Handling

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

Debug Mode

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

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "date": "2024-02-01",
    "totalDebt": 34186489456789.12,
    "totalDebtFormatted": "$34.19 trillion",
    "publicDebt": 26912345678901.23,
    "publicDebtFormatted": "$26.91 trillion",
    "intragovernmentalDebt": 7274143777887.89,
    "intragovernmentalDebtFormatted": "$7.27 trillion",
    "perCapita": 102049,
    "perCapitaFormatted": "$102,049",
    "population": 335000000,
    "publicDebtRatio": 78.73,
    "perHousehold": 255122.24,
    "perHouseholdFormatted": "$255,122"
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.