@@ -23,6 +23,7 @@
23module Network.Google.Types where
23module Network.Google.Types where
25import Control.Lens hiding (coerce)
25import Control.Lens hiding (coerce)
26import Control.Monad.Catch
27import Control.Monad.Catch
27import Control.Monad.Trans.Resource
28import Control.Monad.Trans.Resource
28import Data.Aeson
29import Data.Aeson
@@ -200,26 +201,16 @@ data Client a = Client
200 , _cliCheck :: Status -> Bool
201 , _cliCheck :: Status -> Bool
201 , _cliService :: Service
202 , _cliService :: Service
202 , _cliRequest :: Request
203 , _cliRequest :: Request
203− , _cliResponse :: Stream -> ResourceT IO (Either SerializeError a)
204+ , _cliResponse :: Stream -> ResourceT IO (Either String a)
206−mime :: FromStream c a
207+mime :: FromStream c a => Proxy c -> Method -> [Int] -> Request -> Service -> Client a
213mime p = client (fromStream p) (Just (contentType p))
208mime p = client (fromStream p) (Just (contentType p))
215−discard :: Method
210+discard :: Method -> [Int] -> Request -> Service -> Client ()
220discard = client (\b -> closeResumableSource b >> pure (Right ())) Nothing
211discard = client (\b -> closeResumableSource b >> pure (Right ())) Nothing
222−client :: (Stream -> ResourceT IO (Either SerializeError a))
213+client :: (Stream -> ResourceT IO (Either String a))
223 -> Maybe MediaType
214 -> Maybe MediaType
224 -> Method
215 -> Method
@@ -253,19 +244,13 @@ instance ToBody JSON Value where
253 toBody Proxy = RequestBodyLBS . encode
244 toBody Proxy = RequestBodyLBS . encode
255class Accept c => FromStream c a where
246class Accept c => FromStream c a where
256− fromStream :: Proxy c
247+ fromStream :: Proxy c -> Stream -> ResourceT IO (Either String a)
258− -> ResourceT IO (Either SerializeError a)
260instance FromStream OctetStream Stream where
249instance FromStream OctetStream Stream where
261 fromStream Proxy = pure . Right
250 fromStream Proxy = pure . Right
263instance FromJSON a => FromStream JSON a where
252instance FromJSON a => FromStream JSON a where
264− fromStream Proxy b = do
253+ fromStream Proxy = sinkLBS >=> pure . eitherDecode
266− case eitherDecode lbs of
268− Right x -> pure (Right x)
270class GoogleAuth a where
255class GoogleAuth a where
271 _AuthKey :: Traversal' a AuthKey
256 _AuthKey :: Traversal' a AuthKey
@@ -496,48 +481,6 @@ instance {-# OVERLAPPING #-}
497 buildClient Proxy = discard methodDelete [204]
482 buildClient Proxy = discard methodDelete [204]
500−-- -> (Stream -> Client (Either SerializeError a))
505−-- perform a meth ns f rq = undefined -- do
507− -- x <- lift . try $ Client.http m (client meth a rq)
508− -- either (failure . TransportError) success x
510− -- failure = pure . Left
513− -- let s = Client.responseStatus rs
514− -- b = Client.responseBody rs
515− -- hs = Client.responseHeaders rs
516− -- case content hs of
517− -- unless (matches respCT (acceptCT)) $
518− -- left $ UnsupportedContentType respCT respBody
520− -- Nothing -> failure (SerializeError' (SerializeError hs))
522− -- Just _ | statusInvalid s -> do
524− -- failure (ServiceError' (ServiceError s c hs lbs))
526− -- Just c | contentInvalid c -> do
528− -- failure (SerializeError' (SerializeError s c hs lbs))
531− -- Just c -> first SerializeError' <$> f b
533− -- content :: [Header] -> Maybe c
534− -- content = parseAccept
535− -- . fromMaybe "application/octet-stream"
536− -- . lookup hContentType
538− -- statusCheck s = fromEnum s `elem` ns
539− -- contentCheck = matches a
541sinkLBS :: Stream -> ResourceT IO LBS.ByteString
484sinkLBS :: Stream -> ResourceT IO LBS.ByteString
542sinkLBS = fmap LBS.fromChunks . ($$+- CL.consume)
485sinkLBS = fmap LBS.fromChunks . ($$+- CL.consume)