Daylight Duration Calculator API - Ruby Gem

Daylight Duration Calculator computes sunrise, sunset times, and total daylight hours for any geographic location and date using astronomical algorithms.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_daylightduration'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_daylightduration

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_daylightduration'

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

# Make a request
response = client.execute({
  latitude: 40.7128,
  longitude: -74.006,
  date: "2024-06-21"
})

# Print the response
puts response

Error Handling

begin
  response = client.execute({ latitude: 40.7128, longitude: -74.006, date: "2024-06-21" })
  puts response["data"]
rescue APIVerve::Daylightduration::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Daylightduration::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

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

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "date": "2024-06-21",
    "location": {
      "latitude": 40.7128,
      "longitude": -74.006
    },
    "condition": "Normal",
    "description": "Standard sunrise and sunset",
    "sunrise": "09:25:09",
    "sunset": "24:30:44",
    "daylight_duration": {
      "total_minutes": 905.58,
      "hours": 15,
      "minutes": 5,
      "formatted": "15:05:00"
    },
    "day_of_year": 173,
    "is_valid": true
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.