@@ -25,7 +25,7 @@ module Network.Google.Types where
26import Control.Applicative
26import Control.Applicative
27import Control.Exception.Lens (exception)
27import Control.Exception.Lens (exception)
28−import Control.Lens hiding (coerce)
28+import Control.Lens
29import Control.Monad.Catch
29import Control.Monad.Catch
30import Control.Monad.Trans.Resource
30import Control.Monad.Trans.Resource
31import Data.Aeson
31import Data.Aeson
@@ -43,7 +43,6 @@ import Data.Foldable (foldl')
43import Data.Monoid
43import Data.Monoid
44import Data.String
44import Data.String
45import Data.Text (Text)
45import Data.Text (Text)
46−import qualified Data.Text as Text
47import qualified Data.Text.Encoding as Text
46import qualified Data.Text.Encoding as Text
48import Data.Text.Lazy.Builder (Builder)
47import Data.Text.Lazy.Builder (Builder)
49import qualified Data.Text.Lazy.Builder as Build
48import qualified Data.Text.Lazy.Builder as Build
@@ -154,7 +153,7 @@ instance AsError Error where
154 ServiceError e -> Right e
153 ServiceError e -> Right e
155 x -> Left x
154 x -> Left x
157−data Service = Service
156+data ServiceConfig = ServiceConfig
158 { _svcId :: !ServiceId
157 { _svcId :: !ServiceId
159 , _svcHost :: !ByteString
158 , _svcHost :: !ByteString
160 , _svcPath :: !Builder
159 , _svcPath :: !Builder
@@ -163,8 +162,8 @@ data Service = Service
163 , _svcTimeout :: !(Maybe Seconds)
162 , _svcTimeout :: !(Maybe Seconds)
166−defaultService :: ServiceId -> ByteString -> Service
165+defaultService :: ServiceId -> ByteString -> ServiceConfig
167−defaultService i h = Service
166+defaultService i h = ServiceConfig
168 { _svcId = i
167 { _svcId = i
169 , _svcHost = h
168 , _svcHost = h
170 , _svcPath = mempty
169 , _svcPath = mempty
@@ -173,19 +172,19 @@ defaultService i h = Service
173 , _svcTimeout = Just 70
172 , _svcTimeout = Just 70
176−serviceHost :: Lens' Service ByteString
175+serviceHost :: Lens' ServiceConfig ByteString
177serviceHost = lens _svcHost (\s a -> s { _svcHost = a })
176serviceHost = lens _svcHost (\s a -> s { _svcHost = a })
179−servicePath :: Lens' Service Builder
178+servicePath :: Lens' ServiceConfig Builder
180servicePath = lens _svcPath (\s a -> s { _svcPath = a })
179servicePath = lens _svcPath (\s a -> s { _svcPath = a })
182−servicePort :: Lens' Service Int
181+servicePort :: Lens' ServiceConfig Int
183servicePort = lens _svcPort (\s a -> s { _svcPort = a })
182servicePort = lens _svcPort (\s a -> s { _svcPort = a })
185−serviceSecure :: Lens' Service Bool
184+serviceSecure :: Lens' ServiceConfig Bool
186serviceSecure = lens _svcSecure (\s a -> s { _svcSecure = a })
185serviceSecure = lens _svcSecure (\s a -> s { _svcSecure = a })
188−serviceTimeout :: Lens' Service (Maybe Seconds)
187+serviceTimeout :: Lens' ServiceConfig (Maybe Seconds)
189serviceTimeout = lens _svcTimeout (\s a -> s { _svcTimeout = a })
188serviceTimeout = lens _svcTimeout (\s a -> s { _svcTimeout = a })
191-- | A single part of a multipart message.
190-- | A single part of a multipart message.
@@ -239,18 +238,28 @@ data Client a = Client
239 { _cliAccept :: !(Maybe MediaType)
238 { _cliAccept :: !(Maybe MediaType)
240 , _cliMethod :: !Method
239 , _cliMethod :: !Method
241 , _cliCheck :: !(Status -> Bool)
240 , _cliCheck :: !(Status -> Bool)
242− , _cliService :: !Service
241+ , _cliService :: !ServiceConfig
243 , _cliRequest :: !Request
242 , _cliRequest :: !Request
244 , _cliResponse :: !(Stream -> ResourceT IO (Either (String, LBS.ByteString) a))
243 , _cliResponse :: !(Stream -> ResourceT IO (Either (String, LBS.ByteString) a))
247−clientService :: Lens' (Client a) Service
246+clientService :: Lens' (Client a) ServiceConfig
248clientService = lens _cliService (\s a -> s { _cliService = a })
247clientService = lens _cliService (\s a -> s { _cliService = a })
250−mime :: FromStream c a => Proxy c -> Method -> [Int] -> Request -> Service -> Client a
249+mime :: FromStream c a
251mime p = client (fromStream p) (Just (contentType p))
256mime p = client (fromStream p) (Just (contentType p))
253−discard :: Method -> [Int] -> Request -> Service -> Client ()
258+discard :: Method
254discard = client (\b -> closeResumableSource b >> pure (Right ())) Nothing
263discard = client (\b -> closeResumableSource b >> pure (Right ())) Nothing
256client :: (Stream -> ResourceT IO (Either (String, LBS.ByteString) a))
265client :: (Stream -> ResourceT IO (Either (String, LBS.ByteString) a))
@@ -258,7 +267,7 @@ client :: (Stream -> ResourceT IO (Either (String, LBS.ByteString) a))
258 -> Method
267 -> Method
260 -> Request
269 -> Request
261− -> Service
270+ -> ServiceConfig
262 -> Client a
271 -> Client a
263client f cs m ns rq s = Client
272client f cs m ns rq s = Client
264 { _cliAccept = cs
273 { _cliAccept = cs
@@ -437,61 +446,61 @@ instance ( ToBody c a
438instance {-# OVERLAPPABLE #-}
447instance {-# OVERLAPPABLE #-}
439 FromStream c a => GoogleClient (Get (c ': cs) a) where
448 FromStream c a => GoogleClient (Get (c ': cs) a) where
440− type Fn (Get (c ': cs) a) = Service -> Client a
449+ type Fn (Get (c ': cs) a) = ServiceConfig -> Client a
442 buildClient Proxy = mime (Proxy :: Proxy c) methodGet [200, 203]
451 buildClient Proxy = mime (Proxy :: Proxy c) methodGet [200, 203]
444instance {-# OVERLAPPING #-}
453instance {-# OVERLAPPING #-}
445 GoogleClient (Get (c ': cs) ()) where
454 GoogleClient (Get (c ': cs) ()) where
446− type Fn (Get (c ': cs) ()) = Service -> Client ()
455+ type Fn (Get (c ': cs) ()) = ServiceConfig -> Client ()
448 buildClient Proxy = discard methodGet [204]
457 buildClient Proxy = discard methodGet [204]
450instance {-# OVERLAPPABLE #-}
459instance {-# OVERLAPPABLE #-}
451 (FromStream c a, cs' ~ (c ': cs)) => GoogleClient (Post cs' a) where
460 (FromStream c a, cs' ~ (c ': cs)) => GoogleClient (Post cs' a) where
452− type Fn (Post cs' a) = Service -> Client a
461+ type Fn (Post cs' a) = ServiceConfig -> Client a
454 buildClient Proxy = mime (Proxy :: Proxy c) methodPost [200, 201]
463 buildClient Proxy = mime (Proxy :: Proxy c) methodPost [200, 201]
456instance {-# OVERLAPPING #-}
465instance {-# OVERLAPPING #-}
457 GoogleClient (Post cs ()) where
466 GoogleClient (Post cs ()) where
458− type Fn (Post cs ()) = Service -> Client ()
467+ type Fn (Post cs ()) = ServiceConfig -> Client ()
460 buildClient Proxy = discard methodPost [204]
469 buildClient Proxy = discard methodPost [204]
462instance {-# OVERLAPPABLE #-}
471instance {-# OVERLAPPABLE #-}
463 FromStream c a => GoogleClient (Put (c ': cs) a) where
472 FromStream c a => GoogleClient (Put (c ': cs) a) where
464− type Fn (Put (c ': cs) a) = Service -> Client a
473+ type Fn (Put (c ': cs) a) = ServiceConfig -> Client a
466 buildClient Proxy = mime (Proxy :: Proxy c) methodPut [200, 201]
475 buildClient Proxy = mime (Proxy :: Proxy c) methodPut [200, 201]
468instance {-# OVERLAPPING #-}
477instance {-# OVERLAPPING #-}
469 GoogleClient (Put (c ': cs) ()) where
478 GoogleClient (Put (c ': cs) ()) where
470− type Fn (Put (c ': cs) ()) = Service -> Client ()
479+ type Fn (Put (c ': cs) ()) = ServiceConfig -> Client ()
472 buildClient Proxy = discard methodPut [204]
481 buildClient Proxy = discard methodPut [204]
474instance {-# OVERLAPPABLE #-}
483instance {-# OVERLAPPABLE #-}
475 FromStream c a => GoogleClient (Patch (c ': cs) a) where
484 FromStream c a => GoogleClient (Patch (c ': cs) a) where
476− type Fn (Patch (c ': cs) a) = Service -> Client a
485+ type Fn (Patch (c ': cs) a) = ServiceConfig -> Client a
478 buildClient Proxy = mime (Proxy :: Proxy c) methodPatch [200, 201]
487 buildClient Proxy = mime (Proxy :: Proxy c) methodPatch [200, 201]
480instance {-# OVERLAPPING #-}
489instance {-# OVERLAPPING #-}
481 GoogleClient (Patch (c ': cs) ()) where
490 GoogleClient (Patch (c ': cs) ()) where
482− type Fn (Patch (c ': cs) ()) = Service -> Client ()
491+ type Fn (Patch (c ': cs) ()) = ServiceConfig -> Client ()
484 buildClient Proxy = discard methodPatch [204]
493 buildClient Proxy = discard methodPatch [204]
486instance {-# OVERLAPPABLE #-}
495instance {-# OVERLAPPABLE #-}
487 FromStream c a => GoogleClient (Delete (c ': cs) a) where
496 FromStream c a => GoogleClient (Delete (c ': cs) a) where
488− type Fn (Delete (c ': cs) a) = Service -> Client a
497+ type Fn (Delete (c ': cs) a) = ServiceConfig -> Client a
490 buildClient Proxy = mime (Proxy :: Proxy c) methodDelete [200, 202]
499 buildClient Proxy = mime (Proxy :: Proxy c) methodDelete [200, 202]
492instance {-# OVERLAPPING #-}
501instance {-# OVERLAPPING #-}
493 GoogleClient (Delete (c ': cs) ()) where
502 GoogleClient (Delete (c ': cs) ()) where
494− type Fn (Delete (c ': cs) ()) = Service -> Client ()
503+ type Fn (Delete (c ': cs) ()) = ServiceConfig -> Client ()
496 buildClient Proxy = discard methodDelete [204]
505 buildClient Proxy = discard methodDelete [204]