Weather API - Ruby Gem
Weather is a simple tool for getting the current weather. It returns the temperature, humidity, and more for a given location.
Installation
Add this line to your application's Gemfile:
gem 'apiverve_weatherforecast'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install apiverve_weatherforecast
Getting Started
Get your API key at APIVerve
Basic Usage
require 'apiverve_weatherforecast'
# Initialize the client
client = APIVerve::Weatherforecast::Client.new(api_key: "YOUR_API_KEY")
# Make a request
response = client.execute({ city: "San Francisco" })
# Print the response
puts response
Error Handling
begin
response = client.execute({ city: "San Francisco" })
puts response["data"]
rescue APIVerve::Weatherforecast::ValidationError => e
puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Weatherforecast::APIError => e
puts "API error: #{e.}"
puts "Status code: #{e.status_code}"
end
Debug Mode
# Enable debug logging
client = APIVerve::Weatherforecast::Client.new(
api_key: "YOUR_API_KEY",
debug: true
)
Example Response
{
"status": "ok",
"error": null,
"data": {
"tempC": 13.3,
"tempF": 55.9,
"windMph": 4.7,
"windKph": 7.6,
"windDegree": 273,
"windDir": "W",
"pressureMb": 1022,
"pressureIn": 30.17,
"precipMm": 0,
"precipIn": 0,
"feelslikeC": 13,
"feelslikeF": 55.3,
"visKm": 16,
"visMiles": 9,
"gustMph": 7.2,
"gustKph": 11.6
}
}
Documentation
For more information, visit the API Documentation.
Support
- Website: https://weatherforecast.apiverve.com?utm_source=ruby&utm_medium=readme
- Email: hello@apiverve.com
License
This gem is available under the MIT License.