@@ -1,8 +1,10 @@
1{-# LANGUAGE DataKinds #-}
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE FunctionalDependencies #-}
4{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5{-# LANGUAGE MultiParamTypeClasses #-}
6{-# LANGUAGE MultiParamTypeClasses #-}
7+{-# LANGUAGE PolyKinds #-}
6{-# LANGUAGE ScopedTypeVariables #-}
8{-# LANGUAGE ScopedTypeVariables #-}
7{-# LANGUAGE TypeFamilies #-}
9{-# LANGUAGE TypeFamilies #-}
8{-# LANGUAGE UndecidableInstances #-}
10{-# LANGUAGE UndecidableInstances #-}
@@ -24,71 +26,75 @@
24-- A 'MonadGoogle' typeclass is used as a function constraint to provide automatic
26-- A 'MonadGoogle' typeclass is used as a function constraint to provide automatic
25-- lifting of functions when embedding 'Google' as a layer inside your own
27-- lifting of functions when embedding 'Google' as a layer inside your own
26-- application stack.
28-- application stack.
27−module Network.Google where
29+module Network.Google
29− -- -- * Running Google Actions
31+ -- * Running Google Actions
30− -- Google (..)
32+ Google (..)
31− -- , MonadGoogle (..)
33+ , MonadGoogle (..)
32− -- , runGoogle
34+ , runGoogle
33− -- , runResourceT
35+ , runResourceT
35− -- -- * Authentication and Environment
37+ -- * Authentication and Environment
38− -- , HasEnv (..)
39+ , HasEnv (..)
40− -- -- * Sending Requests
42+ -- ** Customized Environment
41− -- , send
43+ , newEnvWith
44+ , getApplicationDefault
43− -- -- ** Media Downloads
46+ -- * Sending Requests
44− -- , download
47+ , send
46− -- -- ** Media Uploads
49+ -- ** Media Downloads
47− -- , upload
50+ , download
49− -- , ToBody (..)
52+ -- ** Media Uploads
50− -- , RequestBody
53+ , upload
53− -- -- ** Service Configuration
55+ , ToBody (..)
54− -- -- ** Overriding Defaults
56+ , RequestBody
55− -- , configure
57+ , sourceBody
58− -- -- *** Scoped Actions
59+ -- ** Service Configuration
59− -- , reconfigure
60+ -- ** Overriding Defaults
60− -- , timeout
61+ , configure
62− -- -- * Running Asynchronous Actions
64+ -- *** Scoped Actions
63− -- -- $async
65+ , reconfigure
65− -- -- * Handling Errors
68+ -- * Running Asynchronous Actions
66− -- , AsError (..)
69+ -- $async
67− -- , AsAuthError (..)
69− -- , trying
71+ -- * Handling Errors
70− -- , catching
72+ , AsError (..)
72− -- -- * Logging
75+ , trying
73− -- -- $logging
76+ , catching
75− -- , Logger
78+ -- * Logging
76− -- , LogLevel (..)
79+ -- $logging
78− -- -- ** Constructing a Logger
81+ , Logger
79− -- , newLogger
82+ , LogLevel (..)
81− -- -- * Constructing a HTTP Manager
84+ -- ** Constructing a Logger
82− -- , newManager
85+ , newLogger
83− -- , tlsManagerSettings
87+ -- * Constructing a HTTP Manager
85− -- -- * Re-exported Types
91+ -- * Re-exported Types
86− -- , Proxy (..)
92+ , Proxy (..)
87− -- , OctetStream
93+ , OctetStream
88− -- , PlainText
94+ , PlainText
90− -- , module Network.Google.Types
96+ , module Network.Google.Types
91− -- ) where
97+ ) where
93import Control.Applicative
99import Control.Applicative
94import Control.Exception.Lens
100import Control.Exception.Lens
@@ -129,131 +135,120 @@ newtype Google s a = Google { unGoogle :: ReaderT (Env s) (ResourceT IO) a }
129 , MonadCatch
135 , MonadCatch
130 , MonadMask
136 , MonadMask
131 , MonadBase IO
137 , MonadBase IO
132−-- , MonadReader (Env s)
138+ , MonadReader (Env s)
133 , MonadResource
139 , MonadResource
136−-- | Run a 'Google' aciton using the specified environment.
142+-- | Run a 'Google' aciton using the specified environment containing
143+-- credentials with sufficient authorization scopes.
137−-- runGoogle :: (MonadResource m, HasEnv s r) => r -> Google s a -> m a
144+runGoogle :: (MonadResource m, HasEnv s r) => r -> Google s a -> m a
138−-- runGoogle e m = liftResourceT $ runReaderT (unGoogle m) (e ^. environment)
145+runGoogle e m = liftResourceT $ runReaderT (unGoogle m) (e ^. environment)
140−runGoogle :: MonadResource m => Env s -> Google s a -> m a
141−runGoogle e m = liftResourceT $ runReaderT (unGoogle m) e
144−test = runResourceT $ do
150−send :: (GoogleRequest a, IsSubList s (Ss a)) => a -> Google s (Rs a)
161−instance GoogleRequest Foo where
163− type Ss Foo = '[Foo]
165− requestClient = undefined
168−-- instance MonadBaseControl IO Google where
169−-- type StM Google a = StM (ReaderT Env (ResourceT IO)) a
171−-- liftBaseWith f = Google . liftBaseWith $ \g -> f (g . unGoogle)
172−-- restoreM = Google . restoreM
174−-- -- | Monads in which 'Google' actions may be embedded.
147+-- | Monads in which 'Google' actions may be embedded.
175−-- class ( Functor m
149+ , Functor m
176−-- , Applicative m
150+ , Applicative m
177−-- , Monad m
151+ , Monad m
178−-- , MonadIO m
152+ , MonadIO m
179−-- , MonadCatch m
153+ , MonadCatch m
180−-- ) => MonadGoogle m where
154+ ) => MonadGoogle s m | m -> s where
181−-- -- | Lift a computation to the 'Google' monad.
155+ -- | Lift a computation to the 'Google' monad.
182−-- liftGoogle :: Google a -> m a
156+ liftGoogle :: Google s a -> m a
184−-- instance MonadGoogle Google where
158+instance Allow s => MonadGoogle s (Google s) where
185−-- liftGoogle = id
159+ liftGoogle = id
161+instance MonadBaseControl IO (Google s) where
162+ type StM (Google s) a = StM (ReaderT (Env s) (ResourceT IO)) a
164+ liftBaseWith f = Google . liftBaseWith $ \g -> f (g . unGoogle)
165+ restoreM = Google . restoreM
187−-- instance MonadGoogle m => MonadGoogle (IdentityT m) where liftGoogle = lift . liftGoogle
167+instance MonadGoogle s m => MonadGoogle s (IdentityT m) where
168+ liftGoogle = lift . liftGoogle
188−-- instance MonadGoogle m => MonadGoogle (ListT m) where liftGoogle = lift . liftGoogle
170+instance MonadGoogle s m => MonadGoogle s (ListT m) where
171+ liftGoogle = lift . liftGoogle
189−-- instance MonadGoogle m => MonadGoogle (MaybeT m) where liftGoogle = lift . liftGoogle
173+instance MonadGoogle s m => MonadGoogle s (MaybeT m) where
174+ liftGoogle = lift . liftGoogle
190−-- instance MonadGoogle m => MonadGoogle (ExceptT e m) where liftGoogle = lift . liftGoogle
176+instance MonadGoogle s m => MonadGoogle s (ExceptT e m) where
177+ liftGoogle = lift . liftGoogle
191−-- instance MonadGoogle m => MonadGoogle (ReaderT r m) where liftGoogle = lift . liftGoogle
179+instance MonadGoogle s m => MonadGoogle s (ReaderT r m) where
180+ liftGoogle = lift . liftGoogle
192−-- instance MonadGoogle m => MonadGoogle (S.StateT s m) where liftGoogle = lift . liftGoogle
182+instance MonadGoogle s m => MonadGoogle s (S.StateT s' m) where
183+ liftGoogle = lift . liftGoogle
193−-- instance MonadGoogle m => MonadGoogle (LS.StateT s m) where liftGoogle = lift . liftGoogle
185+instance MonadGoogle s m => MonadGoogle s (LS.StateT s' m) where
194−
186+ liftGoogle = lift . liftGoogle
195−-- instance (Monoid w, MonadGoogle m) => MonadGoogle (W.WriterT w m) where
188+instance (Monoid w, MonadGoogle s m) => MonadGoogle s (W.WriterT w m) where
196−-- liftGoogle = lift . liftGoogle
189+ liftGoogle = lift . liftGoogle
198−-- instance (Monoid w, MonadGoogle m) => MonadGoogle (LW.WriterT w m) where
191+instance (Monoid w, MonadGoogle s m) => MonadGoogle s (LW.WriterT w m) where
199−-- liftGoogle = lift . liftGoogle
192+ liftGoogle = lift . liftGoogle
201−-- instance (Monoid w, MonadGoogle m) => MonadGoogle (RW.RWST r w s m) where
194+instance (Monoid w, MonadGoogle s m) => MonadGoogle s (RW.RWST r w s' m) where
202−-- liftGoogle = lift . liftGoogle
195+ liftGoogle = lift . liftGoogle
204−-- instance (Monoid w, MonadGoogle m) => MonadGoogle (LRW.RWST r w s m) where
197+instance (Monoid w, MonadGoogle s m) => MonadGoogle s (LRW.RWST r w s' m) where
205−-- liftGoogle = lift . liftGoogle
198+ liftGoogle = lift . liftGoogle
207−-- -- | Run a 'Google' aciton using the specified environment.
208−-- runGoogle :: (MonadResource m, HasEnv r) => r -> Google a -> m a
209−-- runGoogle e m = liftResourceT $ runReaderT (unGoogle m) (e ^. environment)
211−-- -- | Send a request, returning the associated response if successful.
200+-- | Send a request, returning the associated response if successful.
213−-- -- Throws 'Error'.
202+-- Throws 'Error'.
214−-- send :: (MonadGoogle m, GoogleRequest a) => a -> m (Rs a)
203+send :: (MonadGoogle s m, Authorize s a, GoogleRequest a) => a -> m (Rs a)
215−-- send x = liftGoogle $ do
204+send x = liftGoogle $ do
216−-- e <- ask
205+ e <- ask
217−-- r <- perform e x
206+ r <- perform e x
218−-- hoistError r
207+ hoistError r
220−-- -- | Send a request returning the associated streaming media response if successful.
209+-- | Send a request returning the associated streaming media response if successful.
222−-- -- Some request data types have two possible responses, the JSON metadata and
211+-- Some request data types have two possible responses, the JSON metadata and
223−-- -- a streaming media response. Use 'send' to retrieve the metadata and 'download'
212+-- a streaming media response. Use 'send' to retrieve the metadata and 'download'
224−-- -- to retrieve the streaming media.
213+-- to retrieve the streaming media.
226−-- -- Throws 'Error'.
215+-- Throws 'Error'.
216+download :: ( MonadGoogle s m
217+ , Authorize s (MediaDownload a)
227−-- download :: (MonadGoogle m, GoogleRequest (MediaDownload a))
218+ , GoogleRequest (MediaDownload a)
229−-- -> m (Rs (MediaDownload a))
221+ -> m (Rs (MediaDownload a))
230−-- download = send . MediaDownload
222+download = send . MediaDownload
232−-- -- | Send a request with an attached multipart/related media upload.
224+-- | Send a request with an attached multipart/related media upload.
234−-- -- Throws 'Error'.
226+-- Throws 'Error'.
227+upload :: ( MonadGoogle s m
228+ , Authorize s (MediaUpload a)
235−-- upload :: (MonadGoogle m, GoogleRequest (MediaUpload a))
229+ , GoogleRequest (MediaUpload a)
237−-- -> RequestBody
232+ -> RequestBody
238−-- -> m (Rs (MediaUpload a))
233+ -> m (Rs (MediaUpload a))
239−-- upload x = send . MediaUpload x
234+upload x = send . MediaUpload x
241−-- hoistError :: MonadThrow m => Either Error a -> m a
236+hoistError :: MonadThrow m => Either Error a -> m a
242−-- hoistError = either (throwingM _Error) return
237+hoistError = either (throwingM _Error) return
244−-- {- $async
239+{- $async
245−-- Requests can be sent asynchronously, but due to guarantees about resource closure
240+Requests can be sent asynchronously, but due to guarantees about resource closure
246−-- require the use of <http://hackage.haskell.org/package/lifted-async lifted-async>.
241+require the use of <http://hackage.haskell.org/package/lifted-async lifted-async>.
249−-- {- $logging
244+{- $logging
250−-- The exposed logging interface is a primitive 'Logger' function which gets
245+The exposed logging interface is a primitive 'Logger' function which gets
251−-- threaded through service calls and serialisation routines. This allows the
246+threaded through service calls and serialisation routines. This allows the
252−-- library to output useful information and diagnostics.
247+library to output useful information and diagnostics.
254−-- The 'newLogger' function can be used to construct a simple logger which writes
249+The 'newLogger' function can be used to construct a simple logger which writes
255−-- output to a 'Handle', but in most production code you should probably consider
250+output to a 'Handle', but in most production code you should probably consider
256−-- using a more robust logging library such as
251+using a more robust logging library such as
257−-- <http://hackage.haskell.org/package/tiny-log tiny-log> or
252+<http://hackage.haskell.org/package/tiny-log tiny-log> or
258−-- <http://hackage.haskell.org/package/fast-logger fast-logger>.
253+<http://hackage.haskell.org/package/fast-logger fast-logger>.