on develop help sign in
Aligning generated syntax and core library types
93feb6dBrendan Hay
core/src/Network/Google/Types.hs+37−21
@@ -22,6 +22,7 @@
22--
22--
23module Network.Google.Types where
23module Network.Google.Types where
24
24
25+import Control.Applicative
25import Control.Exception.Lens (exception)
26import Control.Exception.Lens (exception)
26import Control.Lens hiding (coerce)
27import Control.Lens hiding (coerce)
27import Control.Monad
28import Control.Monad
@@ -38,13 +39,9 @@ import qualified Data.Conduit.List as CL
38import Data.Data
39import Data.Data
39import Data.DList (DList)
40import Data.DList (DList)
40import qualified Data.DList as DList
41import qualified Data.DList as DList
41−import Data.Foldable (foldMap, foldl')
42+import Data.Foldable (foldl')
42−import Data.List (intersperse)
43−import Data.Maybe
44import Data.Monoid
43import Data.Monoid
45−import Data.Proxy
46import Data.Text (Text)
44import Data.Text (Text)
47−import qualified Data.Text as Text
48import qualified Data.Text.Encoding as Text
45import qualified Data.Text.Encoding as Text
49import Data.Text.Lazy.Builder (Builder)
46import Data.Text.Lazy.Builder (Builder)
50import qualified Data.Text.Lazy.Builder as Build
47import qualified Data.Text.Lazy.Builder as Build
@@ -55,38 +52,41 @@ import Network.HTTP.Media hiding (Accept)
55import Network.HTTP.Types hiding (Header)
52import Network.HTTP.Types hiding (Header)
56import qualified Network.HTTP.Types as HTTP
53import qualified Network.HTTP.Types as HTTP
57import Servant.API
54import Servant.API
58−import Servant.Utils.Links
59
55
60data AltJSON = AltJSON
56data AltJSON = AltJSON
61− deriving (Eq, Ord, Show, Read, Generic, Data, Typeable)
57+ deriving (Eq, Ord, Show, Read, Generic, Typeable)
62
58
63instance ToText AltJSON where
59instance ToText AltJSON where
64 toText = const "json"
60 toText = const "json"
65
61
66data AltMedia = AltMedia
62data AltMedia = AltMedia
67− deriving (Eq, Ord, Show, Read, Generic, Data, Typeable)
63+ deriving (Eq, Ord, Show, Read, Generic, Typeable)
68
64
69instance ToText AltMedia where
65instance ToText AltMedia where
70 toText = const "media"
66 toText = const "media"
71
67
72newtype AuthKey = AuthKey Text
68newtype AuthKey = AuthKey Text
73− deriving (Eq, Ord, Show, Read, Generic, Data, Typeable, ToText)
69+ deriving (Eq, Ord, Show, Read, Generic, Typeable, ToText)
74
70
75newtype OAuthToken = OAuthToken Text
71newtype OAuthToken = OAuthToken Text
76− deriving (Eq, Ord, Show, Read, Generic, Data, Typeable)
72+ deriving (Eq, Ord, Show, Read, Generic, Typeable)
77
73
78instance ToText OAuthToken where
74instance ToText OAuthToken where
79− toText (OAuthToken t) = "Bearer " <> t
75+ toText (OAuthToken t) = t
76+
77+newtype OAuthScope = OAuthScope Text
78+ deriving (Eq, Ord, Show, Read, Generic, Typeable, ToText)
79+
80+newtype Bearer a = Bearer a
81+
82+instance ToText a => ToText (Bearer a) where
83+ toText = mappend "Bearer " . toText
80
84
81newtype MediaDownload a = MediaDownload a
85newtype MediaDownload a = MediaDownload a
82
86
83_MediaDownload :: Iso' (MediaDownload a) a
87_MediaDownload :: Iso' (MediaDownload a) a
84_MediaDownload = iso (\(MediaDownload x) -> x) MediaDownload
88_MediaDownload = iso (\(MediaDownload x) -> x) MediaDownload
85
89
86−instance GoogleAuth a => GoogleAuth (MediaDownload a) where
87− _AuthKey = _MediaDownload . _AuthKey
88− _AuthToken = _MediaDownload . _AuthToken
89−
90_Coerce :: (Coercible a b, Coercible b a) => Iso' a b
90_Coerce :: (Coercible a b, Coercible b a) => Iso' a b
91_Coerce = iso coerce coerce
91_Coerce = iso coerce coerce
92
92
@@ -101,7 +101,7 @@ _Default = iso f Just
101type Stream = ResumableSource (ResourceT IO) ByteString
101type Stream = ResumableSource (ResourceT IO) ByteString
102
102
103newtype ServiceId = ServiceId Text
103newtype ServiceId = ServiceId Text
104− deriving (Eq, Show, Data, Typeable)
104+ deriving (Eq, Show, Typeable)
105
105
106data Error
106data Error
107 = TransportError HttpException
107 = TransportError HttpException
@@ -168,6 +168,18 @@ data Service = Service
168 , _svcPort :: !Int
168 , _svcPort :: !Int
169 , _svcSecure :: !Bool
169 , _svcSecure :: !Bool
170 , _svcTimeout :: !(Maybe Seconds)
170 , _svcTimeout :: !(Maybe Seconds)
171+ , _svcScopes :: ![OAuthScope]
172+ }
173+
174+defaultService :: ServiceId -> ByteString -> Builder -> Service
175+defaultService i h p = Service
176+ { _svcId = i
177+ , _svcHost = h
178+ , _svcPath = p
179+ , _svcPort = 443
180+ , _svcSecure = True
181+ , _svcTimeout = Just 70
182+ , _svcScopes = []
171 }
183 }
172
184
173-- | An intermediary request builder.
185-- | An intermediary request builder.
@@ -178,6 +190,14 @@ data Request = Request
178 , _rqBody :: Maybe (MediaType, RequestBody)
190 , _rqBody :: Maybe (MediaType, RequestBody)
179 }
191 }
180
192
193+instance Monoid Request where
194+ mempty = Request mempty mempty mempty Nothing
195+ mappend a b = Request
196+ (_rqPath a <> "/" <> _rqPath b)
197+ (_rqQuery a <> _rqQuery b)
198+ (_rqHeaders a <> _rqHeaders b)
199+ (_rqBody b <|> _rqBody a)
200+
181appendPath :: Request -> Builder -> Request
201appendPath :: Request -> Builder -> Request
182appendPath rq x = rq { _rqPath = _rqPath rq <> "/" <> x }
202appendPath rq x = rq { _rqPath = _rqPath rq <> "/" <> x }
183
203
@@ -256,11 +276,7 @@ instance FromStream OctetStream Stream where
256instance FromJSON a => FromStream JSON a where
276instance FromJSON a => FromStream JSON a where
257 fromStream Proxy = sinkLBS >=> pure . eitherDecode
277 fromStream Proxy = sinkLBS >=> pure . eitherDecode
258
278
259−class GoogleAuth a where
260− _AuthKey :: Traversal' a AuthKey
261− _AuthToken :: Traversal' a OAuthToken
262−
263−class GoogleAuth a => GoogleRequest a where
279+class GoogleRequest a where
264 type Rs a :: *
280 type Rs a :: *
265
281
266 requestClient :: a -> Client (Rs a)
282 requestClient :: a -> Client (Rs a)
gen/src/Gen/Syntax.hs+1−1
@@ -203,7 +203,7 @@ googleRequestDecl g n assoc alt p api url fields m pat prec =
203
203
204 decls = BDecls
204 decls = BDecls
205 [ patBind noLoc pat $
205 [ patBind noLoc pat $
206− appFun (var "clientBuild") $
206+ appFun (var "buildClient") $
207 [ ExpTypeSig noLoc (var "Proxy") $
207 [ ExpTypeSig noLoc (var "Proxy") $
208 TyApp (TyCon "Proxy") (TyCon (UnQual api))
208 TyApp (TyCon "Proxy") (TyCon (UnQual api))
209 , var "mempty"
209 , var "mempty"