on develop help sign in
Disambiguating Service configuration
9ee217aBrendan Hay
core/src/Network/Google/Types.hs+34−25
@@ -25,7 +25,7 @@ module Network.Google.Types where
25
25
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
156
155
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)
164 }
163 }
165
164
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
174 }
173 }
175
174
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 })
178
177
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 })
181
180
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 })
184
183
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 })
187
186
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 })
190
189
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))
245 }
244 }
246
245
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 })
249
248
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
251mime p = client (fromStream p) (Just (contentType p))
256mime p = client (fromStream p) (Just (contentType p))
252
257
253−discard :: Method -> [Int] -> Request -> Service -> Client ()
258+discard :: Method
259+ -> [Int]
260+ -> Request
261+ -> ServiceConfig
262+ -> Client ()
254discard = client (\b -> closeResumableSource b >> pure (Right ())) Nothing
263discard = client (\b -> closeResumableSource b >> pure (Right ())) Nothing
255
264
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
259 -> [Int]
268 -> [Int]
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
437
446
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
441
450
442 buildClient Proxy = mime (Proxy :: Proxy c) methodGet [200, 203]
451 buildClient Proxy = mime (Proxy :: Proxy c) methodGet [200, 203]
443
452
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 ()
447
456
448 buildClient Proxy = discard methodGet [204]
457 buildClient Proxy = discard methodGet [204]
449
458
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
453
462
454 buildClient Proxy = mime (Proxy :: Proxy c) methodPost [200, 201]
463 buildClient Proxy = mime (Proxy :: Proxy c) methodPost [200, 201]
455
464
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 ()
459
468
460 buildClient Proxy = discard methodPost [204]
469 buildClient Proxy = discard methodPost [204]
461
470
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
465
474
466 buildClient Proxy = mime (Proxy :: Proxy c) methodPut [200, 201]
475 buildClient Proxy = mime (Proxy :: Proxy c) methodPut [200, 201]
467
476
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 ()
471
480
472 buildClient Proxy = discard methodPut [204]
481 buildClient Proxy = discard methodPut [204]
473
482
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
477
486
478 buildClient Proxy = mime (Proxy :: Proxy c) methodPatch [200, 201]
487 buildClient Proxy = mime (Proxy :: Proxy c) methodPatch [200, 201]
479
488
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 ()
483
492
484 buildClient Proxy = discard methodPatch [204]
493 buildClient Proxy = discard methodPatch [204]
485
494
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
489
498
490 buildClient Proxy = mime (Proxy :: Proxy c) methodDelete [200, 202]
499 buildClient Proxy = mime (Proxy :: Proxy c) methodDelete [200, 202]
491
500
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 ()
495
504
496 buildClient Proxy = discard methodDelete [204]
505 buildClient Proxy = discard methodDelete [204]
497
506
gen/src/Gen/Syntax.hs+1−1
@@ -34,7 +34,7 @@ import Language.Haskell.Exts.SrcLoc
34import Language.Haskell.Exts.Syntax hiding (Alt, Int, Lit)
34import Language.Haskell.Exts.Syntax hiding (Alt, Int, Lit)
35
35
36urlSig :: Name -> Decl
36urlSig :: Name -> Decl
37−urlSig n = TypeSig noLoc [n] (TyCon "Service")
37+urlSig n = TypeSig noLoc [n] (TyCon "ServiceConfig")
38
38
39urlDecl :: Service a -> Name -> Decl
39urlDecl :: Service a -> Name -> Decl
40urlDecl s n = sfun noLoc n [] (UnGuardedRhs rhs) noBinds
40urlDecl s n = sfun noLoc n [] (UnGuardedRhs rhs) noBinds
gen/src/Gen/Text.hs+1
@@ -100,6 +100,7 @@ separator x =
100 || x == '-'
100 || x == '-'
101 || x == '_'
101 || x == '_'
102 || x == '*'
102 || x == '*'
103+ || x == '$'
103
104
104dot :: Char -> Bool
105dot :: Char -> Bool
105dot x = x == '.'
106dot x = x == '.'