Moon Phases API - Ruby Gem

Moon Phases is a simple tool for getting the moon phases. It returns the moon phase for a given date.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_moonphases'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_moonphases

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_moonphases'

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

# Make a request
response = client.execute({ today: true })

# Print the response
puts response

Error Handling

begin
  response = client.execute({ today: true })
  puts response["data"]
rescue APIVerve::Moonphases::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Moonphases::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

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

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "phase": "Waning Crescent",
    "phaseEmoji": "🌘",
    "illumination": 9.9,
    "waxing": false,
    "waning": true,
    "lunarAge": 26.61193415670738,
    "lunarAgePercent": 0.9011650706672754,
    "lunationNumber": 1274,
    "lunarDistance": 63.77810628163608,
    "nextFullMoon": "2026-01-16T00:00:00Z",
    "lastFullMoon": "2025-11-17T00:00:00Z",
    "daysToFullMoon": 28,
    "daysSinceFullMoon": 2
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.