Mortgage Rate API - Ruby Gem
Mortgage Rate is a tool for retrieving current and historical US fixed-rate mortgage rates. It returns weekly average rates for 30-year and 15-year fixed mortgages from the Freddie Mac Primary Mortgage Market Survey.
Installation
Add this line to your application's Gemfile:
gem 'apiverve_mortgagerate'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install apiverve_mortgagerate
Getting Started
Get your API key at APIVerve
Basic Usage
require 'apiverve_mortgagerate'
# Initialize the client
client = APIVerve::Mortgagerate::Client.new(api_key: "YOUR_API_KEY")
# Make a request
response = client.execute({
type: "30year",
year: 2023,
month: 6
})
# Print the response
puts response
Error Handling
begin
response = client.execute({ type: "30year", year: 2023, month: 6 })
puts response["data"]
rescue APIVerve::Mortgagerate::ValidationError => e
puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Mortgagerate::APIError => e
puts "API error: #{e.}"
puts "Status code: #{e.status_code}"
end
Debug Mode
# Enable debug logging
client = APIVerve::Mortgagerate::Client.new(
api_key: "YOUR_API_KEY",
debug: true
)
Example Response
{
"status": "ok",
"error": null,
"data": {
"rateType": "30year",
"name": "30-Year Fixed Rate Mortgage",
"term": 30,
"type": "fixed",
"country": "US",
"year": 2023,
"month": 6,
"count": 4,
"rates": [
{
"week": "2023-06-01",
"rate": 6.79
},
{
"week": "2023-06-08",
"rate": 6.71
},
{
"week": "2023-06-15",
"rate": 6.69
},
{
"week": "2023-06-22",
"rate": 6.67
}
],
"change1w": -0.02,
"changeDirection": "down",
"previousRate": 6.69,
"previousDate": "2023-06-15"
}
}
Documentation
For more information, visit the API Documentation.
Support
- Website: https://apiverve.com/marketplace/mortgagerate?utm_source=ruby&utm_medium=readme
- Email: hello@apiverve.com
License
This gem is available under the MIT License.