Skip to content

Commit

Permalink
made simpleAws much simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
aristidb committed Aug 23, 2012
1 parent 5b37776 commit f607903
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
12 changes: 4 additions & 8 deletions Aws/Aws.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ awsRef = unsafeAwsRef
--
-- Note that this is potentially less efficient than using 'aws', because HTTP connections cannot be re-used.
--
-- All errors are caught and wrapped in the 'Response' value.
--
-- Usage:
-- @
-- resp <- simpleAws cfg serviceCfg request
Expand All @@ -143,12 +141,10 @@ simpleAws :: (Transaction r a, AsMemoryResponse a, MonadIO io)
=> Configuration
-> ServiceConfiguration r NormalQuery
-> r
-> io (Response (ResponseMetadata a) (MemoryResponse a))
simpleAws cfg scfg request = liftIO $ HTTP.withManager $ \manager -> do
Response m x <- aws cfg scfg manager request
Response m <$> case x of
Failure f -> return (Failure f)
Success a -> Success <$> loadToMemory a
-> io (MemoryResponse a)
simpleAws cfg scfg request
= liftIO $ HTTP.withManager $ \manager ->
loadToMemory =<< readResponseIO =<< aws cfg scfg manager request

-- | Run an AWS transaction, /without/ HTTP manager and with metadata returned in an 'IORef'.
--
Expand Down
11 changes: 3 additions & 8 deletions Examples/SimpleDb.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import qualified Aws
import qualified Aws.SimpleDb as Sdb
import Data.Attempt
import Control.Exception
import qualified Data.Text as T
import qualified Data.Text.IO as T

Expand All @@ -15,11 +13,8 @@ main = do

{- Make request -}
let req = Sdb.listDomains { Sdb.ldMaxNumberOfDomains = Just 10 }
Aws.Response _metadata resp <- Aws.simpleAws cfg sdbCfg req
Sdb.ListDomainsResponse names _token <- Aws.simpleAws cfg sdbCfg req

{- Analyze response -}
case resp of
Success (Sdb.ListDomainsResponse names _token) -> do
putStrLn "First 10 domains:"
mapM_ (T.putStrLn . T.cons '\t') names
Failure err -> print (toException err)
putStrLn "First 10 domains:"
mapM_ (T.putStrLn . T.cons '\t') names

0 comments on commit f607903

Please sign in to comment.