@@ -25,7 +25,7 @@ module Network.Google.Types where
2525
2626import Control.Applicative
2727import Control.Exception.Lens (exception)
28−import Control.Lens hiding (coerce)
28+import Control.Lens
2929import Control.Monad.Catch
3030import Control.Monad.Trans.Resource
3131import Data.Aeson
@@ -43,7 +43,6 @@ import Data.Foldable (foldl')
4343import Data.Monoid
4444import Data.String
4545import Data.Text (Text)
46−import qualified Data.Text as Text
4746import qualified Data.Text.Encoding as Text
4847import Data.Text.Lazy.Builder (Builder)
4948import qualified Data.Text.Lazy.Builder as Build
@@ -154,7 +153,7 @@ instance AsError Error where
154153 ServiceError e -> Right e
155154 x -> Left x
156155
157−data Service = Service
156+data ServiceConfig = ServiceConfig
158157 { _svcId :: !ServiceId
159158 , _svcHost :: !ByteString
160159 , _svcPath :: !Builder
@@ -163,8 +162,8 @@ data Service = Service
163162 , _svcTimeout :: !(Maybe Seconds)
164163 }
165164
166−defaultService :: ServiceId -> ByteString -> Service
167−defaultService i h = Service
165+defaultService :: ServiceId -> ByteString -> ServiceConfig
166+defaultService i h = ServiceConfig
168167 { _svcId = i
169168 , _svcHost = h
170169 , _svcPath = mempty
@@ -173,19 +172,19 @@ defaultService i h = Service
173172 , _svcTimeout = Just 70
174173 }
175174
176−serviceHost :: Lens' Service ByteString
175+serviceHost :: Lens' ServiceConfig ByteString
177176serviceHost = lens _svcHost (\s a -> s { _svcHost = a })
178177
179−servicePath :: Lens' Service Builder
178+servicePath :: Lens' ServiceConfig Builder
180179servicePath = lens _svcPath (\s a -> s { _svcPath = a })
181180
182−servicePort :: Lens' Service Int
181+servicePort :: Lens' ServiceConfig Int
183182servicePort = lens _svcPort (\s a -> s { _svcPort = a })
184183
185−serviceSecure :: Lens' Service Bool
184+serviceSecure :: Lens' ServiceConfig Bool
186185serviceSecure = lens _svcSecure (\s a -> s { _svcSecure = a })
187186
188−serviceTimeout :: Lens' Service (Maybe Seconds)
187+serviceTimeout :: Lens' ServiceConfig (Maybe Seconds)
189188serviceTimeout = lens _svcTimeout (\s a -> s { _svcTimeout = a })
190189
191190-- | A single part of a multipart message.
@@ -239,18 +238,28 @@ data Client a = Client
239238 { _cliAccept :: !(Maybe MediaType)
240239 , _cliMethod :: !Method
241240 , _cliCheck :: !(Status -> Bool)
242− , _cliService :: !Service
241+ , _cliService :: !ServiceConfig
243242 , _cliRequest :: !Request
244243 , _cliResponse :: !(Stream -> ResourceT IO (Either (String, LBS.ByteString) a))
245244 }
246245
247−clientService :: Lens' (Client a) Service
246+clientService :: Lens' (Client a) ServiceConfig
248247clientService = lens _cliService (\s a -> s { _cliService = a })
249248
250−mime :: FromStream c a => Proxy c -> Method -> [Int] -> Request -> Service -> Client a
249+mime :: FromStream c a
250+ => Proxy c
251+ -> Method
252+ -> [Int]
253+ -> Request
254+ -> ServiceConfig
255+ -> Client a
251256mime p = client (fromStream p) (Just (contentType p))
252257
253−discard :: Method -> [Int] -> Request -> Service -> Client ()
258+discard :: Method
259+ -> [Int]
260+ -> Request
261+ -> ServiceConfig
262+ -> Client ()
254263discard = client (\b -> closeResumableSource b >> pure (Right ())) Nothing
255264
256265client :: (Stream -> ResourceT IO (Either (String, LBS.ByteString) a))
@@ -258,7 +267,7 @@ client :: (Stream -> ResourceT IO (Either (String, LBS.ByteString) a))
258267 -> Method
259268 -> [Int]
260269 -> Request
261− -> Service
270+ -> ServiceConfig
262271 -> Client a
263272client f cs m ns rq s = Client
264273 { _cliAccept = cs
@@ -437,61 +446,61 @@ instance ( ToBody c a
437446
438447instance {-# OVERLAPPABLE #-}
439448 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
441450
442451 buildClient Proxy = mime (Proxy :: Proxy c) methodGet [200, 203]
443452
444453instance {-# OVERLAPPING #-}
445454 GoogleClient (Get (c ': cs) ()) where
446− type Fn (Get (c ': cs) ()) = Service -> Client ()
455+ type Fn (Get (c ': cs) ()) = ServiceConfig -> Client ()
447456
448457 buildClient Proxy = discard methodGet [204]
449458
450459instance {-# OVERLAPPABLE #-}
451460 (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
453462
454463 buildClient Proxy = mime (Proxy :: Proxy c) methodPost [200, 201]
455464
456465instance {-# OVERLAPPING #-}
457466 GoogleClient (Post cs ()) where
458− type Fn (Post cs ()) = Service -> Client ()
467+ type Fn (Post cs ()) = ServiceConfig -> Client ()
459468
460469 buildClient Proxy = discard methodPost [204]
461470
462471instance {-# OVERLAPPABLE #-}
463472 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
465474
466475 buildClient Proxy = mime (Proxy :: Proxy c) methodPut [200, 201]
467476
468477instance {-# OVERLAPPING #-}
469478 GoogleClient (Put (c ': cs) ()) where
470− type Fn (Put (c ': cs) ()) = Service -> Client ()
479+ type Fn (Put (c ': cs) ()) = ServiceConfig -> Client ()
471480
472481 buildClient Proxy = discard methodPut [204]
473482
474483instance {-# OVERLAPPABLE #-}
475484 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
477486
478487 buildClient Proxy = mime (Proxy :: Proxy c) methodPatch [200, 201]
479488
480489instance {-# OVERLAPPING #-}
481490 GoogleClient (Patch (c ': cs) ()) where
482− type Fn (Patch (c ': cs) ()) = Service -> Client ()
491+ type Fn (Patch (c ': cs) ()) = ServiceConfig -> Client ()
483492
484493 buildClient Proxy = discard methodPatch [204]
485494
486495instance {-# OVERLAPPABLE #-}
487496 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
489498
490499 buildClient Proxy = mime (Proxy :: Proxy c) methodDelete [200, 202]
491500
492501instance {-# OVERLAPPING #-}
493502 GoogleClient (Delete (c ': cs) ()) where
494− type Fn (Delete (c ': cs) ()) = Service -> Client ()
503+ type Fn (Delete (c ': cs) ()) = ServiceConfig -> Client ()
495504
496505 buildClient Proxy = discard methodDelete [204]
497506