diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2020-04-23 13:37:51 +0200 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2020-04-23 13:37:51 +0200 |
commit | e7a5255ed66162cebea785af30d3b534649ab24b (patch) | |
tree | 84f206d12df28466fc4de96ea8805e5f1286c706 | |
parent | 9c9cd8bf92bc6276811c38a0f9cedb0815af7add (diff) | |
download | openweathermap-e7a5255ed66162cebea785af30d3b534649ab24b.tar.gz |
Make required all the query parameters
-rw-r--r-- | lib/Web/OpenWeatherMap/API.hs | 24 | ||||
-rw-r--r-- | lib/Web/OpenWeatherMap/Client.hs | 8 |
2 files changed, 17 insertions, 15 deletions
diff --git a/lib/Web/OpenWeatherMap/API.hs b/lib/Web/OpenWeatherMap/API.hs index b9624f8..516845c 100644 --- a/lib/Web/OpenWeatherMap/API.hs +++ b/lib/Web/OpenWeatherMap/API.hs @@ -14,12 +14,14 @@ module Web.OpenWeatherMap.API import Data.Proxy (Proxy(..)) -import Servant.API ((:<|>)(..), (:>), Get, JSON, QueryParam) +import Servant.API ((:<|>)(..), (:>), Get, JSON, QueryParam', Required, Strict) import Servant.Client (ClientM, client) import Web.OpenWeatherMap.Types.CurrentWeather (CurrentWeather) import Web.OpenWeatherMap.Types.ForecastWeather (ForecastWeather) +type QueryParam = QueryParam' '[ Required, Strict] + type GetCurrentWeather = AppId :> Get '[ JSON] CurrentWeather type GetForecastWeather = AppId :> Get '[ JSON] ForecastWeather @@ -36,25 +38,25 @@ type API = Current :<|> Forecast -- | Request current weather in the city. weatherByName :: - Maybe String -- ^ City name, e. g. \"Moscow\" or \"Moscow,ru\". - -> Maybe String -- ^ API key. + String -- ^ City name, e. g. \"Moscow\" or \"Moscow,ru\". + -> 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. + Double -- ^ Latitude, e. g. 55.7522200 for Moscow. + -> Double -- ^ Longitude, e. g. 37.6155600 for Moscow. + -> String -- ^ API key. -> ClientM CurrentWeather -- | Request forecast weather in the city. forecastByName :: - Maybe String -- ^ City name, e. g. \"Moscow\" or \"Moscow,ru\". - -> Maybe String -- ^ API key. + String -- ^ City name, e. g. \"Moscow\" or \"Moscow,ru\". + -> 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. + Double -- ^ Latitude, e. g. 55.7522200 for Moscow. + -> Double -- ^ Longitude, e. g. 37.6155600 for Moscow. + -> String -- ^ API key. -> ClientM ForecastWeather (weatherByName :<|> weatherByCoord) :<|> (forecastByName :<|> forecastByCoord) = client (Proxy :: Proxy API) diff --git a/lib/Web/OpenWeatherMap/Client.hs b/lib/Web/OpenWeatherMap/Client.hs index 445e2a4..d760812 100644 --- a/lib/Web/OpenWeatherMap/Client.hs +++ b/lib/Web/OpenWeatherMap/Client.hs @@ -35,8 +35,8 @@ getWeather :: -> 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 (Name city) = API.weatherByName city + api (Coord lat lon) = API.weatherByCoord lat lon -- | Make a request to OpenWeatherMap API -- and return forecast weather in given location. @@ -46,8 +46,8 @@ getForecast :: -> 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 + api (Name city) = API.forecastByName city + api (Coord lat lon) = API.forecastByCoord lat lon defaultEnv :: IO ClientEnv defaultEnv = do |