Class: WeatherGemKg::Clients::OpenMeteo

Inherits:
WeatherGemKg::Client show all
Defined in:
lib/weather_gem_kg/clients/open_meteo.rb

Constant Summary collapse

GEOCODING_URL =
"https://geocoding-api.open-meteo.com/v1/search"
FORECAST_URL =
"https://api.open-meteo.com/v1/forecast"
WEATHER_CODES =
{
  0 => "Clear sky",
  1 => "Mainly clear",
  2 => "Partly cloudy",
  3 => "Overcast",
  45 => "Fog",
  48 => "Depositing rime fog",
  51 => "Light drizzle",
  53 => "Moderate drizzle",
  55 => "Dense drizzle",
  56 => "Light freezing drizzle",
  57 => "Dense freezing drizzle",
  61 => "Slight rain",
  63 => "Moderate rain",
  65 => "Heavy rain",
  66 => "Light freezing rain",
  67 => "Heavy freezing rain",
  71 => "Slight snow",
  73 => "Moderate snow",
  75 => "Heavy snow",
  77 => "Snow grains",
  80 => "Slight rain showers",
  81 => "Moderate rain showers",
  82 => "Violent rain showers",
  85 => "Slight snow showers",
  86 => "Heavy snow showers",
  95 => "Thunderstorm",
  96 => "Thunderstorm with slight hail",
  99 => "Thunderstorm with heavy hail"
}.freeze

Instance Method Summary collapse

Instance Method Details

#forecast(city:, days:) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/weather_gem_kg/clients/open_meteo.rb', line 45

def forecast(city:, days:)
  days = Integer(days)
  raise InvalidArgumentError, "days must be between 1 and 16" unless days.between?(1, 16)

  location = geocode(city)
  payload = fetch_forecast(location.fetch(:latitude), location.fetch(:longitude), days)
  parse_forecast(payload)
end