Sunrise Sunset API - Ruby Gem

Sunrise Sunset is a simple tool for getting the sunrise and sunset times. It returns the sunrise and sunset times for a given location and date.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_sunrisesunset'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_sunrisesunset

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_sunrisesunset'

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

# Make a request
response = client.execute({
  lat: 36.72016,
  lon: -4.42034,
  date: "01-16-2026"
})

# Print the response
puts response

Error Handling

begin
  response = client.execute({ lat: 36.72016, lon: -4.42034, date: "01-16-2026" })
  puts response["data"]
rescue APIVerve::Sunrisesunset::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Sunrisesunset::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

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

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "solarNoon": "2025-12-16T12:14:40.51Z",
    "sunrise": "2025-12-16T07:24:56.165Z",
    "sunset": "2025-12-16T17:04:24.854Z",
    "sunriseEnd": "2025-12-16T07:27:58.828Z",
    "sunsetStart": "2025-12-16T17:01:22.192Z",
    "dawn": "2025-12-16T06:56:02.774Z",
    "dusk": "2025-12-16T17:33:18.245Z",
    "nauticalDawn": "2025-12-16T06:23:38.134Z",
    "nauticalDusk": "2025-12-16T18:05:42.886Z",
    "nightEnd": "2025-12-16T05:52:07.048Z",
    "night": "2025-12-16T18:37:13.971Z",
    "goldenHourEnd": "2025-12-16T08:05:08.406Z",
    "goldenHour": "2025-12-16T16:24:12.613Z"
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.