I-Bond Rates API - Ruby Gem

I-Bond Rates provides current and historical interest rates for US Series I Savings Bonds. I-Bonds are inflation-protected savings bonds with a composite rate made up of a fixed rate plus an inflation rate that adjusts every 6 months.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_savingsbonds'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_savingsbonds

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_savingsbonds'

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

# Make a request
response = client.execute({ period: "2024-11" })

# Print the response
puts response

Error Handling

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

Debug Mode

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

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "iBonds": {
      "currentRate": 5.27,
      "fixedRate": 1.3,
      "inflationRate": 1.97,
      "purchaseLimit": 10000
    },
    "eeBonds": {
      "currentRate": 2.7,
      "guaranteedDoubling": "20 years (guaranteed to double in value)",
      "purchaseLimit": 10000
    },
    "recommendation": "I Bonds",
    "recommendationReason": "I Bonds currently offer 5.27% vs EE Bonds at 2.70%",
    "nextRateChange": "2024-05-01",
    "lastUpdated": "2024-02-01T00:00:00.000Z"
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.