ExOwm.Client (ExOwm v2.0.0)

Copy Markdown View Source

Unified client for making OpenWeatherMap API requests.

This module replaces the old Coordinator/Worker pattern with a simpler approach using direct function calls and Task.async_stream for batching.

Summary

Functions

Fetches weather data for a single location.

Fetches weather data for multiple locations concurrently.

Types

endpoint()

@type endpoint() ::
  :current_weather
  | :one_call
  | :forecast_5day
  | :forecast_hourly
  | :forecast_16day
  | :historical
  | :air_pollution
  | :air_pollution_forecast
  | :air_pollution_history
  | :geocode
  | :reverse_geocode

options()

@type options() :: keyword()

result()

@type result() :: {:ok, map()} | {:error, term()} | {:error, term(), term()}

Functions

fetch(endpoint, location, opts \\ [])

@spec fetch(endpoint(), ExOwm.Location.t() | map(), options()) :: result()

Fetches weather data for a single location.

Parameters

  • endpoint - The API endpoint to call (:current_weather, :one_call, etc.)
  • location - A %ExOwm.Location{} struct or location map
  • opts - Request options (units, lang, cnt, etc.)

Returns

  • {:ok, data} - Successfully fetched weather data
  • {:error, reason} - API error (not_found, bad_request, etc.)
  • {:error, reason, details} - API error with response details

fetch_batch(endpoint, locations, opts \\ [])

@spec fetch_batch(endpoint(), [ExOwm.Location.t() | map()], options()) :: [result()]

Fetches weather data for multiple locations concurrently.

Parameters

  • endpoint - The API endpoint to call
  • locations - List of %ExOwm.Location{} structs or location maps
  • opts - Request options

Returns

List of results, each being {:ok, data} or {:error, reason}.