diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2020-04-19 12:26:49 +0200 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2020-04-19 16:30:08 +0200 |
commit | 0b1981ef40404802a828f2a91ecadba3c2453034 (patch) | |
tree | 4471665b7598940cf75b954e78d49cfcce8d4453 /lib/Web/OpenWeatherMap/Client.hs | |
parent | 3f86e251e8566c36e75bb5b6f8657ad5e0d120dd (diff) | |
download | openweathermap-0b1981ef40404802a828f2a91ecadba3c2453034.tar.gz |
Add forecast weather API
Diffstat (limited to 'lib/Web/OpenWeatherMap/Client.hs')
-rw-r--r-- | lib/Web/OpenWeatherMap/Client.hs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/Web/OpenWeatherMap/Client.hs b/lib/Web/OpenWeatherMap/Client.hs index c7ad7b6..445e2a4 100644 --- a/lib/Web/OpenWeatherMap/Client.hs +++ b/lib/Web/OpenWeatherMap/Client.hs @@ -4,6 +4,7 @@ High-level client functions perfoming requests to OpenWeatherMap API. module Web.OpenWeatherMap.Client ( Location(..) , getWeather + , getForecast ) where import Network.HTTP.Client (defaultManagerSettings, newManager) @@ -11,7 +12,6 @@ import Servant.Client ( BaseUrl(BaseUrl) , ClientEnv , ClientError - , ClientM , Scheme(Http) , mkClientEnv , runClientM @@ -19,6 +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 @@ -33,13 +34,20 @@ getWeather :: -> Location -> IO (Either ClientError CurrentWeather) getWeather appid loc = defaultEnv >>= runClientM (api loc appid) + where + api (Name city) = API.weatherByName (Just city) . Just + api (Coord lat lon) = API.weatherByCoord (Just lat) (Just lon) . Just -api :: - Location - -> String -- ^ API key. - -> ClientM CurrentWeather -api (Name city) = API.weatherByName (Just city) . Just -api (Coord lat lon) = API.weatherByCoord (Just lat) (Just lon) . Just +-- | Make a request to OpenWeatherMap API +-- and return forecast weather in given location. +getForecast :: + String -- ^ API key. + -> Location + -> IO (Either ClientError ForecastWeather) +getForecast appid loc = defaultEnv >>= runClientM (api loc appid) + where + api (Name city) = API.forecastByName (Just city) . Just + api (Coord lat lon) = API.forecastByCoord (Just lat) (Just lon) . Just defaultEnv :: IO ClientEnv defaultEnv = do |