diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2020-06-28 17:36:49 +0200 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2020-06-28 17:36:49 +0200 |
commit | 27b29703a46bcde319961c2b52d38da3513a1da8 (patch) | |
tree | 474c50433763dd491e4ab213c24072f6f06ecc1d /lib/Web/OpenWeatherMap/Client.hs | |
parent | e7a5255ed66162cebea785af30d3b534649ab24b (diff) | |
download | openweathermap-27b29703a46bcde319961c2b52d38da3513a1da8.tar.gz |
Make location a part of API
Diffstat (limited to 'lib/Web/OpenWeatherMap/Client.hs')
-rw-r--r-- | lib/Web/OpenWeatherMap/Client.hs | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/lib/Web/OpenWeatherMap/Client.hs b/lib/Web/OpenWeatherMap/Client.hs index d760812..31719bb 100644 --- a/lib/Web/OpenWeatherMap/Client.hs +++ b/lib/Web/OpenWeatherMap/Client.hs @@ -2,8 +2,7 @@ High-level client functions perfoming requests to OpenWeatherMap API. -} module Web.OpenWeatherMap.Client - ( Location(..) - , getWeather + ( getWeather , getForecast ) where @@ -20,12 +19,7 @@ import Servant.Client import qualified Web.OpenWeatherMap.API as API import Web.OpenWeatherMap.Types.CurrentWeather (CurrentWeather) import Web.OpenWeatherMap.Types.ForecastWeather (ForecastWeather) - --- | Various way to specify location. -data Location - = Name String -- ^ City name. - | Coord Double - Double -- ^ Geographic coordinates: latitude and longitude. +import Web.OpenWeatherMap.Types.Location (Location) -- | Make a request to OpenWeatherMap API -- and return current weather in given location. @@ -33,10 +27,7 @@ getWeather :: String -- ^ API key. -> Location -> IO (Either ClientError CurrentWeather) -getWeather appid loc = defaultEnv >>= runClientM (api loc appid) - where - api (Name city) = API.weatherByName city - api (Coord lat lon) = API.weatherByCoord lat lon +getWeather appid loc = defaultEnv >>= runClientM (API.currentWeather appid loc) -- | Make a request to OpenWeatherMap API -- and return forecast weather in given location. @@ -44,10 +35,8 @@ getForecast :: String -- ^ API key. -> Location -> IO (Either ClientError ForecastWeather) -getForecast appid loc = defaultEnv >>= runClientM (api loc appid) - where - api (Name city) = API.forecastByName city - api (Coord lat lon) = API.forecastByCoord lat lon +getForecast appid loc = + defaultEnv >>= runClientM (API.forecastWeather appid loc) defaultEnv :: IO ClientEnv defaultEnv = do |