module Aws.Sns.Commands.CreateTopic
( CreateTopic(..)
, CreateTopicResponse(..)
, CreateTopicErrors(..)
) where
import Aws.Core
import Aws.General
import Aws.Sns.Core
import Control.Applicative
import Control.Monad.Trans.Resource (throwM)
import Data.Monoid
import qualified Data.Text as T
import Data.Typeable
import Text.XML.Cursor (($//), (&/))
import qualified Text.XML.Cursor as CU
createTopicAction :: SnsAction
createTopicAction = SnsActionCreateTopic
data CreateTopic = CreateTopic
{ createTopicName :: !T.Text
}
deriving (Show, Read, Eq, Ord, Typeable)
data CreateTopicResponse = CreateTopicResponse
{ createTopicResTopicArn :: !Arn
}
deriving (Show, Read, Eq, Ord, Typeable)
instance ResponseConsumer r CreateTopicResponse where
type ResponseMetadata CreateTopicResponse = SnsMetadata
responseConsumer _ = snsXmlResponseConsumer p
where
p el = CreateTopicResponse <$> arn el
arn el = do
t <- force "Missing topic ARN" $ el
$// CU.laxElement "CreateTopicResult"
&/ CU.laxElement "TopicArn"
&/ CU.content
case fromText t of
Right a -> return a
Left e -> throwM $ SnsResponseDecodeError $
"failed to parse topic ARN (" <> t <> "): " <> (T.pack . show) e
instance SignQuery CreateTopic where
type ServiceConfiguration CreateTopic = SnsConfiguration
signQuery CreateTopic{..} = snsSignQuery SnsQuery
{ snsQueryMethod = Get
, snsQueryAction = createTopicAction
, snsQueryParameters = [("Name", Just createTopicName)]
, snsQueryBody = Nothing
}
instance Transaction CreateTopic CreateTopicResponse
instance AsMemoryResponse CreateTopicResponse where
type MemoryResponse CreateTopicResponse = CreateTopicResponse
loadToMemory = return
data CreateTopicErrors
= CreateTopicAuthorizationError
| CreateTopicInternalError
| CreateTopicInvalidParameter
| CreateTopicTopicLimitExceeded
deriving (Show, Read, Eq, Ord, Enum, Bounded, Typeable)