@@ -54,12 +54,13 @@ import Network.HTTP.Media hiding (Accept)
54import Network.HTTP.Types hiding (Header)
54import Network.HTTP.Types hiding (Header)
55import qualified Network.HTTP.Types as HTTP
55import qualified Network.HTTP.Types as HTTP
56import Servant.API
56import Servant.API
57+import Web.HttpApiData
58data AltJSON = AltJSON deriving (Eq, Ord, Show, Read, Generic, Typeable)
59data AltJSON = AltJSON deriving (Eq, Ord, Show, Read, Generic, Typeable)
59data AltMedia = AltMedia deriving (Eq, Ord, Show, Read, Generic, Typeable)
60data AltMedia = AltMedia deriving (Eq, Ord, Show, Read, Generic, Typeable)
61−instance ToText AltJSON where toText = const "json"
62+instance ToHttpApiData AltJSON where toQueryParam = const "json"
62−instance ToText AltMedia where toText = const "multipart"
63+instance ToHttpApiData AltMedia where toQueryParam = const "multipart"
64newtype OAuthScope = OAuthScope Text
65newtype OAuthScope = OAuthScope Text
@@ -70,8 +71,8 @@ newtype OAuthScope = OAuthScope Text
70 , IsString
71 , IsString
72 , Typeable
73 , Typeable
73− , FromText
74+ , FromHttpApiData
74− , ToText
75+ , ToHttpApiData
75 , FromJSON
76 , FromJSON
@@ -85,8 +86,8 @@ newtype AccessToken = AccessToken Text
85 , IsString
86 , IsString
87 , Typeable
88 , Typeable
88− , FromText
89+ , FromHttpApiData
89− , ToText
90+ , ToHttpApiData
90 , FromJSON
91 , FromJSON
@@ -100,8 +101,8 @@ newtype RefreshToken = RefreshToken Text
100 , IsString
101 , IsString
101 , Generic
102 , Generic
102 , Typeable
103 , Typeable
103− , FromText
104+ , FromHttpApiData
104− , ToText
105+ , ToHttpApiData
105 , FromJSON
106 , FromJSON
@@ -115,8 +116,8 @@ newtype ClientId = ClientId Text
115 , IsString
116 , IsString
116 , Generic
117 , Generic
117 , Typeable
118 , Typeable
118− , FromText
119+ , FromHttpApiData
119− , ToText
120+ , ToHttpApiData
120 , FromJSON
121 , FromJSON
@@ -130,8 +131,8 @@ newtype Secret = Secret Text
130 , IsString
131 , IsString
131 , Generic
132 , Generic
132 , Typeable
133 , Typeable
133− , FromText
134+ , FromHttpApiData
134− , ToText
135+ , ToHttpApiData
135 , FromJSON
136 , FromJSON
@@ -145,8 +146,8 @@ newtype ServiceId = ServiceId Text
145 , IsString
146 , IsString
146 , Generic
147 , Generic
147 , Typeable
148 , Typeable
148− , FromText
149+ , FromHttpApiData
149− , ToText
150+ , ToHttpApiData
150 , FromJSON
151 , FromJSON
@@ -286,7 +287,7 @@ instance Monoid Request where
286appendPath :: Request -> Builder -> Request
287appendPath :: Request -> Builder -> Request
287appendPath rq x = rq { _rqPath = _rqPath rq <> "/" <> x }
288appendPath rq x = rq { _rqPath = _rqPath rq <> "/" <> x }
289−appendPaths :: ToText a => Request -> [a] -> Request
290+appendPaths :: ToHttpApiData a => Request -> [a] -> Request
290appendPaths rq = appendPath rq . foldMap (mappend "/" . buildText)
291appendPaths rq = appendPath rq . foldMap (mappend "/" . buildText)
292appendQuery :: Request -> ByteString -> Maybe Text -> Request
293appendQuery :: Request -> ByteString -> Maybe Text -> Request
@@ -437,9 +438,9 @@ instance (GoogleClient a, GoogleClient b) => GoogleClient (a :<|> b) where
437 buildClient (Proxy :: Proxy a) rq
438 buildClient (Proxy :: Proxy a) rq
438 :<|> buildClient (Proxy :: Proxy b) rq
439 :<|> buildClient (Proxy :: Proxy b) rq
440−instance ( KnownSymbol s
441+instance ( KnownSymbol s
441− , ToText a
442+ , ToHttpApiData a
442− , GoogleClient fn
443+ , GoogleClient fn
443 ) => GoogleClient (Capture s a :> fn) where
444 ) => GoogleClient (Capture s a :> fn) where
444 type Fn (Capture s a :> fn) = a -> Fn fn
445 type Fn (Capture s a :> fn) = a -> Fn fn
@@ -447,19 +448,19 @@ instance ( KnownSymbol s
447 . appendPath rq
448 . appendPath rq
448 . buildText
449 . buildText
450−instance ( KnownSymbol s
451+instance ( KnownSymbol s
451− , ToText a
452+ , ToHttpApiData a
452− , GoogleClient fn
453+ , GoogleClient fn
453 ) => GoogleClient (Captures s a :> fn) where
454 ) => GoogleClient (Captures s a :> fn) where
454 type Fn (Captures s a :> fn) = [a] -> Fn fn
455 type Fn (Captures s a :> fn) = [a] -> Fn fn
456 buildClient Proxy rq = buildClient (Proxy :: Proxy fn)
457 buildClient Proxy rq = buildClient (Proxy :: Proxy fn)
457 . appendPaths rq
458 . appendPaths rq
459−instance ( KnownSymbol s
460+instance ( KnownSymbol s
460− , KnownSymbol m
461+ , KnownSymbol m
461− , ToText a
462+ , ToHttpApiData a
462− , GoogleClient fn
463+ , GoogleClient fn
463 ) => GoogleClient (CaptureMode s m a :> fn) where
464 ) => GoogleClient (CaptureMode s m a :> fn) where
464 type Fn (CaptureMode s m a :> fn) = a -> Fn fn
465 type Fn (CaptureMode s m a :> fn) = a -> Fn fn
@@ -467,9 +468,9 @@ instance ( KnownSymbol s
467 . appendPath rq
468 . appendPath rq
468 $ buildText x <> buildSymbol (Proxy :: Proxy m)
469 $ buildText x <> buildSymbol (Proxy :: Proxy m)
470−instance ( KnownSymbol s
471+instance ( KnownSymbol s
471− , ToText a
472+ , ToHttpApiData a
472− , GoogleClient fn
473+ , GoogleClient fn
473 ) => GoogleClient (QueryParam s a :> fn) where
474 ) => GoogleClient (QueryParam s a :> fn) where
474 type Fn (QueryParam s a :> fn) = Maybe a -> Fn fn
475 type Fn (QueryParam s a :> fn) = Maybe a -> Fn fn
@@ -479,23 +480,23 @@ instance ( KnownSymbol s
479 Just x -> appendQuery rq k v
480 Just x -> appendQuery rq k v
481 k = byteSymbol (Proxy :: Proxy s)
482 k = byteSymbol (Proxy :: Proxy s)
482− v = Just (toText x)
483+ v = Just (toQueryParam x)
484−instance ( KnownSymbol s
485+instance ( KnownSymbol s
485− , ToText a
486+ , ToHttpApiData a
486− , GoogleClient fn
487+ , GoogleClient fn
487 ) => GoogleClient (QueryParams s a :> fn) where
488 ) => GoogleClient (QueryParams s a :> fn) where
488 type Fn (QueryParams s a :> fn) = [a] -> Fn fn
489 type Fn (QueryParams s a :> fn) = [a] -> Fn fn
490 buildClient Proxy rq = buildClient (Proxy :: Proxy fn) . foldl' go rq
491 buildClient Proxy rq = buildClient (Proxy :: Proxy fn) . foldl' go rq
492− go r = appendQuery r k . Just . toText
493+ go r = appendQuery r k . Just . toQueryParam
494 k = byteSymbol (Proxy :: Proxy s)
495 k = byteSymbol (Proxy :: Proxy s)
496−instance ( KnownSymbol s
497+instance ( KnownSymbol s
497− , ToText a
498+ , ToHttpApiData a
498− , GoogleClient fn
499+ , GoogleClient fn
499 ) => GoogleClient (Header s a :> fn) where
500 ) => GoogleClient (Header s a :> fn) where
500 type Fn (Header s a :> fn) = Maybe a -> Fn fn
501 type Fn (Header s a :> fn) = Maybe a -> Fn fn
@@ -505,7 +506,7 @@ instance ( KnownSymbol s
505 Just x -> appendHeader rq (CI.mk k) v
506 Just x -> appendHeader rq (CI.mk k) v
507 k = byteSymbol (Proxy :: Proxy s)
508 k = byteSymbol (Proxy :: Proxy s)
508− v = Just (toText x)
509+ v = Just (toQueryParam x)
510instance ( ToBody c a
511instance ( ToBody c a
511 , GoogleClient fn
512 , GoogleClient fn
@@ -573,7 +574,7 @@ instance {-# OVERLAPPABLE #-}
573 buildClient Proxy = mime (Proxy :: Proxy c) methodDelete [200, 202]
574 buildClient Proxy = mime (Proxy :: Proxy c) methodDelete [200, 202]
575instance {-# OVERLAPPING #-}
576instance {-# OVERLAPPING #-}
576− GoogleClient (Delete (c ': cs) ()) where
577+ GoogleClient (Delete (c ': cs) ()) where
577 type Fn (Delete (c ': cs) ()) = ServiceConfig -> Client ()
578 type Fn (Delete (c ': cs) ()) = ServiceConfig -> Client ()
579 buildClient Proxy = discard methodDelete [204]
580 buildClient Proxy = discard methodDelete [204]
@@ -581,8 +582,8 @@ instance {-# OVERLAPPING #-}
581sinkLBS :: Stream -> ResourceT IO LBS.ByteString
582sinkLBS :: Stream -> ResourceT IO LBS.ByteString
582sinkLBS = fmap LBS.fromChunks . ($$+- CL.consume)
583sinkLBS = fmap LBS.fromChunks . ($$+- CL.consume)
584−buildText :: ToText a => a -> Builder
585+buildText :: ToHttpApiData a => a -> Builder
585−buildText = Build.fromText . toText
586+buildText = Build.fromText . toQueryParam
587buildSymbol :: forall n proxy. KnownSymbol n => proxy n -> Builder
588buildSymbol :: forall n proxy. KnownSymbol n => proxy n -> Builder
588buildSymbol = Build.fromString . symbolVal
589buildSymbol = Build.fromString . symbolVal