CPI Inflation API - Ruby Gem
CPI Inflation provides monthly Consumer Price Index data broken down by category including food, housing, transportation, medical care, and more. Includes year-over-year inflation rates for each category.
Installation
Add this line to your application's Gemfile:
gem 'apiverve_cpiinflation'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install apiverve_cpiinflation
Getting Started
Get your API key at APIVerve
Basic Usage
require 'apiverve_cpiinflation'
# Initialize the client
client = APIVerve::Cpiinflation::Client.new(api_key: "YOUR_API_KEY")
# Make a request
response = client.execute({
date: "2023-06",
category: "food"
})
# Print the response
puts response
Error Handling
begin
response = client.execute({ date: "2023-06", category: "food" })
puts response["data"]
rescue APIVerve::Cpiinflation::ValidationError => e
puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Cpiinflation::APIError => e
puts "API error: #{e.}"
puts "Status code: #{e.status_code}"
end
Debug Mode
# Enable debug logging
client = APIVerve::Cpiinflation::Client.new(
api_key: "YOUR_API_KEY",
debug: true
)
Example Response
{
"status": "ok",
"error": null,
"data": {
"yearMonth": "2024-01",
"year": 2024,
"month": 1,
"categories": {
"all": {
"index": 308.417,
"yearOverYearChange": 3.1
},
"food": {
"index": 327.891,
"yearOverYearChange": 2.6
},
"housing": {
"index": 341.256,
"yearOverYearChange": 4.8
},
"transportation": {
"index": 278.543,
"yearOverYearChange": 1.2
},
"medical": {
"index": 542.189,
"yearOverYearChange": 3.5
},
"gasoline": {
"index": 287.654,
"yearOverYearChange": -3.2
},
"electricity": {
"index": 298.123,
"yearOverYearChange": 5.1
}
}
}
}
Documentation
For more information, visit the API Documentation.
Support
- Website: https://apiverve.com/marketplace/cpiinflation?utm_source=ruby&utm_medium=readme
- Email: hello@apiverve.com
License
This gem is available under the MIT License.