diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2017-06-07 16:24:05 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2017-06-07 16:35:08 +0300 |
commit | 6f6e3d8ec76c59d6f403725e9b2a22b8f6680714 (patch) | |
tree | 45382bc0e03032ffa09b7b63afdc45e243e60f4f /lib/Web/OpenWeatherMap/API.hs | |
download | openweathermap-6f6e3d8ec76c59d6f403725e9b2a22b8f6680714.tar.gz |
Initial version 0.0.00.0.0
Diffstat (limited to 'lib/Web/OpenWeatherMap/API.hs')
-rw-r--r-- | lib/Web/OpenWeatherMap/API.hs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/Web/OpenWeatherMap/API.hs b/lib/Web/OpenWeatherMap/API.hs new file mode 100644 index 0000000..0c1e282 --- /dev/null +++ b/lib/Web/OpenWeatherMap/API.hs @@ -0,0 +1,45 @@ +{-| +Direct API functions. +For API key (a.k.a appid) refer to <http://openweathermap.org/appid>. +-} + +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE TypeOperators #-} + +module Web.OpenWeatherMap.API ( + weatherByName, + weatherByCoord +) where + +import Data.Proxy (Proxy(..)) + +import Servant.API ((:>), (:<|>)(..), JSON, Get, QueryParam) +import Servant.Client (client) +import Servant.Common.Req (ClientM) + +import Web.OpenWeatherMap.Types.CurrentWeather (CurrentWeather) + + +type GetCurrentWeather = AppId :> Get '[JSON] CurrentWeather +type AppId = QueryParam "appid" String + +type API + = "weather" :> QueryParam "q" String :> GetCurrentWeather + :<|> "weather" :> QueryParam "lat" Double :> QueryParam "lon" Double + :> GetCurrentWeather + +-- | Request current weather in the city. +weatherByName + :: Maybe String -- ^ City name, e. g. \"Moscow\" or \"Moscow,ru\". + -> Maybe String -- ^ API key. + -> ClientM CurrentWeather + +-- | Request current weather at the geographic coordinates (in decimal degrees). +weatherByCoord + :: Maybe Double -- ^ Latitude, e. g. 55.7522200 for Moscow. + -> Maybe Double -- ^ Longitude, e. g. 37.6155600 for Moscow. + -> Maybe String -- ^ API key. + -> ClientM CurrentWeather + +weatherByName :<|> weatherByCoord = client (Proxy :: Proxy API) + |