@@ -54,12 +54,13 @@ import Network.HTTP.Media hiding (Accept)
5454import Network.HTTP.Types hiding (Header)
5555import qualified Network.HTTP.Types as HTTP
5656import Servant.API
57+import Web.HttpApiData
5758
5859data AltJSON = AltJSON deriving (Eq, Ord, Show, Read, Generic, Typeable)
5960data AltMedia = AltMedia deriving (Eq, Ord, Show, Read, Generic, Typeable)
6061
61−instance ToText AltJSON where toText = const "json"
62−instance ToText AltMedia where toText = const "multipart"
62+instance ToHttpApiData AltJSON where toQueryParam = const "json"
63+instance ToHttpApiData AltMedia where toQueryParam = const "multipart"
6364
6465newtype OAuthScope = OAuthScope Text
6566 deriving
@@ -70,8 +71,8 @@ newtype OAuthScope = OAuthScope Text
7071 , IsString
7172 , Generic
7273 , Typeable
73− , FromText
74− , ToText
74+ , FromHttpApiData
75+ , ToHttpApiData
7576 , FromJSON
7677 , ToJSON
7778 )
@@ -85,8 +86,8 @@ newtype AccessToken = AccessToken Text
8586 , IsString
8687 , Generic
8788 , Typeable
88− , FromText
89− , ToText
89+ , FromHttpApiData
90+ , ToHttpApiData
9091 , FromJSON
9192 , ToJSON
9293 )
@@ -100,8 +101,8 @@ newtype RefreshToken = RefreshToken Text
100101 , IsString
101102 , Generic
102103 , Typeable
103− , FromText
104− , ToText
104+ , FromHttpApiData
105+ , ToHttpApiData
105106 , FromJSON
106107 , ToJSON
107108 )
@@ -115,8 +116,8 @@ newtype ClientId = ClientId Text
115116 , IsString
116117 , Generic
117118 , Typeable
118− , FromText
119− , ToText
119+ , FromHttpApiData
120+ , ToHttpApiData
120121 , FromJSON
121122 , ToJSON
122123 )
@@ -130,8 +131,8 @@ newtype Secret = Secret Text
130131 , IsString
131132 , Generic
132133 , Typeable
133− , FromText
134− , ToText
134+ , FromHttpApiData
135+ , ToHttpApiData
135136 , FromJSON
136137 , ToJSON
137138 )
@@ -145,8 +146,8 @@ newtype ServiceId = ServiceId Text
145146 , IsString
146147 , Generic
147148 , Typeable
148− , FromText
149− , ToText
149+ , FromHttpApiData
150+ , ToHttpApiData
150151 , FromJSON
151152 , ToJSON
152153 )
@@ -286,7 +287,7 @@ instance Monoid Request where
286287appendPath :: Request -> Builder -> Request
287288appendPath rq x = rq { _rqPath = _rqPath rq <> "/" <> x }
288289
289−appendPaths :: ToText a => Request -> [a] -> Request
290+appendPaths :: ToHttpApiData a => Request -> [a] -> Request
290291appendPaths rq = appendPath rq . foldMap (mappend "/" . buildText)
291292
292293appendQuery :: Request -> ByteString -> Maybe Text -> Request
@@ -437,9 +438,9 @@ instance (GoogleClient a, GoogleClient b) => GoogleClient (a :<|> b) where
437438 buildClient (Proxy :: Proxy a) rq
438439 :<|> buildClient (Proxy :: Proxy b) rq
439440
440−instance ( KnownSymbol s
441− , ToText a
442− , GoogleClient fn
441+instance ( KnownSymbol s
442+ , ToHttpApiData a
443+ , GoogleClient fn
443444 ) => GoogleClient (Capture s a :> fn) where
444445 type Fn (Capture s a :> fn) = a -> Fn fn
445446
@@ -447,19 +448,19 @@ instance ( KnownSymbol s
447448 . appendPath rq
448449 . buildText
449450
450−instance ( KnownSymbol s
451− , ToText a
452− , GoogleClient fn
451+instance ( KnownSymbol s
452+ , ToHttpApiData a
453+ , GoogleClient fn
453454 ) => GoogleClient (Captures s a :> fn) where
454455 type Fn (Captures s a :> fn) = [a] -> Fn fn
455456
456457 buildClient Proxy rq = buildClient (Proxy :: Proxy fn)
457458 . appendPaths rq
458459
459−instance ( KnownSymbol s
460− , KnownSymbol m
461− , ToText a
462− , GoogleClient fn
460+instance ( KnownSymbol s
461+ , KnownSymbol m
462+ , ToHttpApiData a
463+ , GoogleClient fn
463464 ) => GoogleClient (CaptureMode s m a :> fn) where
464465 type Fn (CaptureMode s m a :> fn) = a -> Fn fn
465466
@@ -467,9 +468,9 @@ instance ( KnownSymbol s
467468 . appendPath rq
468469 $ buildText x <> buildSymbol (Proxy :: Proxy m)
469470
470−instance ( KnownSymbol s
471− , ToText a
472− , GoogleClient fn
471+instance ( KnownSymbol s
472+ , ToHttpApiData a
473+ , GoogleClient fn
473474 ) => GoogleClient (QueryParam s a :> fn) where
474475 type Fn (QueryParam s a :> fn) = Maybe a -> Fn fn
475476
@@ -479,23 +480,23 @@ instance ( KnownSymbol s
479480 Just x -> appendQuery rq k v
480481 where
481482 k = byteSymbol (Proxy :: Proxy s)
482− v = Just (toText x)
483+ v = Just (toQueryParam x)
483484
484−instance ( KnownSymbol s
485− , ToText a
486− , GoogleClient fn
485+instance ( KnownSymbol s
486+ , ToHttpApiData a
487+ , GoogleClient fn
487488 ) => GoogleClient (QueryParams s a :> fn) where
488489 type Fn (QueryParams s a :> fn) = [a] -> Fn fn
489490
490491 buildClient Proxy rq = buildClient (Proxy :: Proxy fn) . foldl' go rq
491492 where
492− go r = appendQuery r k . Just . toText
493+ go r = appendQuery r k . Just . toQueryParam
493494
494495 k = byteSymbol (Proxy :: Proxy s)
495496
496−instance ( KnownSymbol s
497− , ToText a
498− , GoogleClient fn
497+instance ( KnownSymbol s
498+ , ToHttpApiData a
499+ , GoogleClient fn
499500 ) => GoogleClient (Header s a :> fn) where
500501 type Fn (Header s a :> fn) = Maybe a -> Fn fn
501502
@@ -505,7 +506,7 @@ instance ( KnownSymbol s
505506 Just x -> appendHeader rq (CI.mk k) v
506507 where
507508 k = byteSymbol (Proxy :: Proxy s)
508− v = Just (toText x)
509+ v = Just (toQueryParam x)
509510
510511instance ( ToBody c a
511512 , GoogleClient fn
@@ -573,7 +574,7 @@ instance {-# OVERLAPPABLE #-}
573574 buildClient Proxy = mime (Proxy :: Proxy c) methodDelete [200, 202]
574575
575576instance {-# OVERLAPPING #-}
576− GoogleClient (Delete (c ': cs) ()) where
577+ GoogleClient (Delete (c ': cs) ()) where
577578 type Fn (Delete (c ': cs) ()) = ServiceConfig -> Client ()
578579
579580 buildClient Proxy = discard methodDelete [204]
@@ -581,8 +582,8 @@ instance {-# OVERLAPPING #-}
581582sinkLBS :: Stream -> ResourceT IO LBS.ByteString
582583sinkLBS = fmap LBS.fromChunks . ($$+- CL.consume)
583584
584−buildText :: ToText a => a -> Builder
585−buildText = Build.fromText . toText
585+buildText :: ToHttpApiData a => a -> Builder
586+buildText = Build.fromText . toQueryParam
586587
587588buildSymbol :: forall n proxy. KnownSymbol n => proxy n -> Builder
588589buildSymbol = Build.fromString . symbolVal