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/API.hs | |
parent | 3f86e251e8566c36e75bb5b6f8657ad5e0d120dd (diff) | |
download | openweathermap-0b1981ef40404802a828f2a91ecadba3c2453034.tar.gz |
Add forecast weather API
Diffstat (limited to 'lib/Web/OpenWeatherMap/API.hs')
-rw-r--r-- | lib/Web/OpenWeatherMap/API.hs | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/Web/OpenWeatherMap/API.hs b/lib/Web/OpenWeatherMap/API.hs index 8a1690e..6d06421 100644 --- a/lib/Web/OpenWeatherMap/API.hs +++ b/lib/Web/OpenWeatherMap/API.hs @@ -8,6 +8,8 @@ For API key (a.k.a appid) refer to <http://openweathermap.org/appid>. module Web.OpenWeatherMap.API ( weatherByName , weatherByCoord + , forecastByName + , forecastByCoord ) where import Data.Proxy (Proxy(..)) @@ -16,14 +18,22 @@ import Servant.API ((:<|>)(..), (:>), Get, JSON, QueryParam) import Servant.Client (ClientM, client) import Web.OpenWeatherMap.Types.CurrentWeather (CurrentWeather) +import Web.OpenWeatherMap.Types.ForecastWeather (ForecastWeather) type GetCurrentWeather = AppId :> Get '[ JSON] CurrentWeather +type GetForecastWeather = AppId :> Get '[ JSON] ForecastWeather + type AppId = QueryParam "appid" String -type API +type Current = "weather" :> QueryParam "q" String :> GetCurrentWeather :<|> "weather" :> QueryParam "lat" Double :> QueryParam "lon" Double :> GetCurrentWeather +type Forecast + = "forecast" :> QueryParam "q" String :> GetForecastWeather :<|> "forecast" :> QueryParam "lat" Double :> QueryParam "lon" Double :> GetForecastWeather + +type API = Current :<|> Forecast + -- | Request current weather in the city. weatherByName :: Maybe String -- ^ City name, e. g. \"Moscow\" or \"Moscow,ru\". @@ -35,4 +45,16 @@ weatherByCoord :: -> Maybe Double -- ^ Longitude, e. g. 37.6155600 for Moscow. -> Maybe String -- ^ API key. -> ClientM CurrentWeather -weatherByName :<|> weatherByCoord = client (Proxy :: Proxy API) +-- | Request forecast weather in the city. +forecastByName :: + Maybe String -- ^ City name, e. g. \"Moscow\" or \"Moscow,ru\". + -> Maybe String -- ^ API key. + -> ClientM ForecastWeather +-- | Request current weather at the geographic coordinates (in decimal degrees). +forecastByCoord :: + Maybe Double -- ^ Latitude, e. g. 55.7522200 for Moscow. + -> Maybe Double -- ^ Longitude, e. g. 37.6155600 for Moscow. + -> Maybe String -- ^ API key. + -> ClientM ForecastWeather +(weatherByName :<|> weatherByCoord) :<|> (forecastByName :<|> forecastByCoord) = + client (Proxy :: Proxy API) |