module SuiteTalk.SOAP where
import Network.HTTP.Client.TLS ( tlsManagerSettings )
import Network.SOAP ( ResponseParser(DocumentParser)
, invokeWS
)
import Network.SOAP.Transport.HTTP ( initTransportWithM
, printBody
, printRequest
)
import Text.XML ( Document )
import Text.XML.Writer ( ToXML )
import SuiteTalk.WSDL ( WSDL(..)
, mkEndpointURL
)
data Error =
InvalidAction
deriving (Show)
send
:: (ToXML header, ToXML body)
=> WSDL
-> String
-> header
-> (String -> body)
-> IO (Either Error Document)
send (WSDL endpoint operations) soapAction header body = do
transport <- initTransportWithM managerSettings
endpointURL
printRequest
printBody
if soapAction `elem` operations
then
Right
<$> invokeWS transport
soapAction
header
(body soapAction)
documentParser
else pure $ Left InvalidAction
where
endpointURL = mkEndpointURL endpoint
managerSettings = tlsManagerSettings
documentParser = DocumentParser id