diff options
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 |