aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2023-01-05 12:41:39 +0200
committerIgor Pashev <pashev.igor@gmail.com>2023-01-05 12:41:39 +0200
commitd625bb9213bc78730f98c556d59813b444235fc4 (patch)
tree3f6cca6fafd965e60deaba5b8f8c1cd36e8bd1d6 /lib
parentda04a198a6c6806aa9502121c3a8ae52767229e0 (diff)
downloadopenweathermap-d625bb9213bc78730f98c556d59813b444235fc4.tar.gz
Switch to servant 0.19
That has switched from Text to ByteString in appendToQueryString. Co-authored-by: Nikolai Oplachko <magnickolas@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Web/OpenWeatherMap/Types/Location.hs19
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/Web/OpenWeatherMap/Types/Location.hs b/lib/Web/OpenWeatherMap/Types/Location.hs
index 85b4ca6..2393641 100644
--- a/lib/Web/OpenWeatherMap/Types/Location.hs
+++ b/lib/Web/OpenWeatherMap/Types/Location.hs
@@ -9,25 +9,28 @@ module Web.OpenWeatherMap.Types.Location
( Location(..)
) where
+import Data.ByteString (ByteString)
import Data.Proxy (Proxy(..))
-
+import Data.Text (Text)
+import Data.Text.Encoding (encodeUtf8)
import Servant.API ((:>))
import Servant.Client (Client, HasClient, clientWithRoute, hoistClientMonad)
-import Servant.Client.Core.Request (appendToQueryString)
-import Web.HttpApiData (toQueryParam)
+import Servant.Client.Core.Request (Request, appendToQueryString)
+import Web.HttpApiData (ToHttpApiData, toQueryParam)
-- | Various ways to specify location.
data Location
= Name String -- ^ City name.
| Coord Double Double -- ^ Geographic coordinates: latitude and longitude.
+addParam :: ToHttpApiData a => Text -> a -> Request -> Request
+addParam name = appendToQueryString name . Just . encodeUtf8 . toQueryParam
+
instance HasClient m api => HasClient m (Location :> api) where
type Client m (Location :> api) = Location -> Client m api
+ hoistClientMonad pm _ f cl = hoistClientMonad pm (Proxy :: Proxy api) f . cl
clientWithRoute pm Proxy req loc =
clientWithRoute pm (Proxy :: Proxy api) (addParams loc req)
where
- addParams (Name q) = appendToQueryString "q" (Just $ toQueryParam q)
- addParams (Coord lat lon) =
- appendToQueryString "lat" (Just $ toQueryParam lat) .
- appendToQueryString "lon" (Just $ toQueryParam lon)
- hoistClientMonad pm _ f cl = hoistClientMonad pm (Proxy :: Proxy api) f . cl
+ addParams (Name q) = addParam "q" q
+ addParams (Coord lat lon) = addParam "lat" lat . addParam "lon" lon