Packages

This application provides the current weather data for the given geo coordinates (latitude/longitude) based on openweathermap.org v2.5.

Current section

Files

Jump to
elixir_weather_data lib open_weather_map_api_http_client.ex
Raw

lib/open_weather_map_api_http_client.ex

defmodule ElixirWeatherData.OpenWeatherMapApi.HttpClient do
@behaviour ElixirWeatherData.OpenWeatherMapApi
def send_request(url) do
request_api(url)
end
defp request_api(url) do
case HTTPoison.get(url) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} -> {:ok, body}
{:ok, %HTTPoison.Response{status_code: 404}} -> {:error, :page_not_found}
{:ok, %HTTPoison.Response{status_code: _}} -> {:error, :unknown_error}
{:error, %HTTPoison.Error{reason: reason}} -> {:error, reason}
end
end
end