module Control.Monad.AWS
( MonadAWS (..)
, send
, paginate
, paginateEither
, await
, EnvT
, runEnvT
, MockT
, runMockT
) where
import Amazonka.Prelude
import Amazonka.Core (AWSPager, AWSRequest, AWSResponse, Error)
import qualified Amazonka.Pager as Pager
import qualified Amazonka.Waiter as Waiter
import qualified Control.Exception as Exception
import Control.Monad.AWS.Class
import Control.Monad.AWS.EnvT
import Control.Monad.AWS.MockT
import Data.Conduit (ConduitM)
import qualified Data.Conduit as Conduit
import Data.Typeable (Typeable)
send
:: ( MonadIO m
, MonadAWS m
, AWSRequest a
, Typeable a
, Typeable (AWSResponse a)
)
=> a
-> m (AWSResponse a)
send :: forall (m :: * -> *) a.
(MonadIO m, MonadAWS m, AWSRequest a, Typeable a,
Typeable (AWSResponse a)) =>
a -> m (AWSResponse a)
send = a -> m (Either Error (AWSResponse a))
forall a.
(AWSRequest a, Typeable a, Typeable (AWSResponse a)) =>
a -> m (Either Error (AWSResponse a))
forall (m :: * -> *) a.
(MonadAWS m, AWSRequest a, Typeable a, Typeable (AWSResponse a)) =>
a -> m (Either Error (AWSResponse a))
sendEither (a -> m (Either Error (AWSResponse a)))
-> (Either Error (AWSResponse a) -> m (AWSResponse a))
-> a
-> m (AWSResponse a)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Either Error (AWSResponse a) -> m (AWSResponse a)
forall (m :: * -> *) a. MonadIO m => Either Error a -> m a
hoistEither
paginateEither
:: (MonadAWS m, AWSPager a, Typeable a, Typeable (AWSResponse a))
=> a
-> ConduitM () (AWSResponse a) m (Either Error ())
paginateEither :: forall (m :: * -> *) a.
(MonadAWS m, AWSPager a, Typeable a, Typeable (AWSResponse a)) =>
a -> ConduitM () (AWSResponse a) m (Either Error ())
paginateEither = a -> ConduitT () (AWSResponse a) m (Either Error ())
forall {m :: * -> *} {a} {i}.
(MonadAWS m, Typeable a, Typeable (AWSResponse a), AWSPager a) =>
a -> ConduitT i (AWSResponse a) m (Either Error ())
go
where
go :: a -> ConduitT i (AWSResponse a) m (Either Error ())
go a
rq =
m (Either Error (AWSResponse a))
-> ConduitT i (AWSResponse a) m (Either Error (AWSResponse a))
forall (m :: * -> *) a.
Monad m =>
m a -> ConduitT i (AWSResponse a) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (a -> m (Either Error (AWSResponse a))
forall a.
(AWSRequest a, Typeable a, Typeable (AWSResponse a)) =>
a -> m (Either Error (AWSResponse a))
forall (m :: * -> *) a.
(MonadAWS m, AWSRequest a, Typeable a, Typeable (AWSResponse a)) =>
a -> m (Either Error (AWSResponse a))
sendEither a
rq) ConduitT i (AWSResponse a) m (Either Error (AWSResponse a))
-> (Either Error (AWSResponse a)
-> ConduitT i (AWSResponse a) m (Either Error ()))
-> ConduitT i (AWSResponse a) m (Either Error ())
forall a b.
ConduitT i (AWSResponse a) m a
-> (a -> ConduitT i (AWSResponse a) m b)
-> ConduitT i (AWSResponse a) m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Left Error
err -> Either Error () -> ConduitT i (AWSResponse a) m (Either Error ())
forall a. a -> ConduitT i (AWSResponse a) m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Error -> Either Error ()
forall a b. a -> Either a b
Left Error
err)
Right AWSResponse a
rs -> do
AWSResponse a -> ConduitT i (AWSResponse a) m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
Conduit.yield AWSResponse a
rs
ConduitT i (AWSResponse a) m (Either Error ())
-> (a -> ConduitT i (AWSResponse a) m (Either Error ()))
-> Maybe a
-> ConduitT i (AWSResponse a) m (Either Error ())
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Either Error () -> ConduitT i (AWSResponse a) m (Either Error ())
forall a. a -> ConduitT i (AWSResponse a) m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (() -> Either Error ()
forall a b. b -> Either a b
Right ())) a -> ConduitT i (AWSResponse a) m (Either Error ())
go (a -> AWSResponse a -> Maybe a
forall a. AWSPager a => a -> AWSResponse a -> Maybe a
Pager.page a
rq AWSResponse a
rs)
paginate
:: ( MonadIO m
, MonadAWS m
, AWSPager a
, Typeable a
, Typeable (AWSResponse a)
)
=> a
-> ConduitM () (AWSResponse a) m ()
paginate :: forall (m :: * -> *) a.
(MonadIO m, MonadAWS m, AWSPager a, Typeable a,
Typeable (AWSResponse a)) =>
a -> ConduitM () (AWSResponse a) m ()
paginate =
a -> ConduitM () (AWSResponse a) m (Either Error ())
forall (m :: * -> *) a.
(MonadAWS m, AWSPager a, Typeable a, Typeable (AWSResponse a)) =>
a -> ConduitM () (AWSResponse a) m (Either Error ())
paginateEither (a -> ConduitM () (AWSResponse a) m (Either Error ()))
-> (Either Error () -> ConduitT () (AWSResponse a) m ())
-> a
-> ConduitT () (AWSResponse a) m ()
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Either Error () -> ConduitT () (AWSResponse a) m ()
forall (m :: * -> *) a. MonadIO m => Either Error a -> m a
hoistEither
await
:: (MonadIO m, MonadAWS m, AWSRequest a, Typeable a)
=> Waiter.Wait a
-> a
-> m Waiter.Accept
await :: forall (m :: * -> *) a.
(MonadIO m, MonadAWS m, AWSRequest a, Typeable a) =>
Wait a -> a -> m Accept
await Wait a
wait = Wait a -> a -> m (Either Error Accept)
forall a.
(AWSRequest a, Typeable a) =>
Wait a -> a -> m (Either Error Accept)
forall (m :: * -> *) a.
(MonadAWS m, AWSRequest a, Typeable a) =>
Wait a -> a -> m (Either Error Accept)
awaitEither Wait a
wait (a -> m (Either Error Accept))
-> (Either Error Accept -> m Accept) -> a -> m Accept
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Either Error Accept -> m Accept
forall (m :: * -> *) a. MonadIO m => Either Error a -> m a
hoistEither
hoistEither :: MonadIO m => Either Error a -> m a
hoistEither :: forall (m :: * -> *) a. MonadIO m => Either Error a -> m a
hoistEither = (Error -> m a) -> (a -> m a) -> Either Error a -> m a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (IO a -> m a
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO a -> m a) -> (Error -> IO a) -> Error -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Error -> IO a
forall e a. Exception e => e -> IO a
Exception.throwIO) a -> m a
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure