Email-ExactTarget
view release on metacpan or search on metacpan
lib/Email/ExactTarget.pm view on Meta::CPAN
return $soap_results->{'Result'};
}
=head1 INTERNAL METHODS
=head2 soap_call()
Internal, formats the SOAP call with the arguments provided and checks the
reply.
my ( $error, $response_data ) = $exact_target->soap_call(
'action' => $method,
'arguments' => $arguments,
);
=cut
sub soap_call
{
my ( $self, %args ) = @_;
my $verbose = $self->verbose();
my $use_test_environment = $self->use_test_environment();
my $endpoint = $use_test_environment
? $ENDPOINT_TEST
: $ENDPOINT_LIVE;
# Check the parameters.
confess 'You must define a SOAP action'
if !defined( $args{'action'} ) || ( $args{'action'} eq '' );
confess 'You must define a SOAP method'
if !defined( $args{'method'} ) || ( $args{'method'} eq '' );
$args{'arguments'} ||= [];
# Do not forget to specify the soapaction (on_action), you will find it in the
# wsdl.
# - uri is the target namespace in the wsdl
# - proxy is the endpoint address
my $soap = SOAP::Lite
->uri( $NAMESPACE )
->on_action( sub { return '"' . $args{'action'} . '"' } )
->proxy( $endpoint )
->readable( ( $verbose ? 1 : 0 ) );
# You must define the namespace used in the wsdl, as an attribute to the
# method without namespace prefix for compatibility with .NET
# (document/literal).
my $method = SOAP::Data->name( $args{'method'} )
->attr( { xmlns => $NAMESPACE } );
# SOAP envelope headers. SOAP API requires addressing, security extensions.
#
# <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
# <wsse:UsernameToken>
# <wsse:Username>username</wsse:Username>
# <wsse:Password>password</wsse:Password>
# </wsse:UsernameToken>
# </wsse:Security>
my @header = (
SOAP::Header
->name( Action => $args{'action'} )
->uri( 'http://schemas.xmlsoap.org/ws/2004/08/addressing' )
->prefix( 'wsa' ),
SOAP::Header
->name( To => $endpoint )
->uri( 'http://schemas.xmlsoap.org/ws/2004/08/addressing' )
->prefix( 'wsa' ),
SOAP::Header
->name(
Security => \SOAP::Data->value(
SOAP::Data->name(
UsernameToken => \SOAP::Data->value(
SOAP::Data->name( Username => $self->{'username'} )->prefix( 'wsse' ),
SOAP::Data->name( Password => $self->{'password'} )->prefix( 'wsse' )
)
)->prefix('wsse')
)
)
->uri( 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' )
->prefix( 'wsse' )
);
# Make the call to the webservice.
my $soap_response = $soap->call(
@header,
$method,
@{ $args{'arguments'} }
);
# Print some debugging information if requested.
if ( $verbose )
{
carp 'Fault: ' . Dumper( $soap_response->fault() )
if defined( $soap_response->fault() );
carp 'Result: ' . Dumper( [ $soap_response->result() ] )
if defined( $soap_response->result() );
carp 'Params out: ' . Dumper( $soap_response->paramsout() )
if defined( $soap_response->paramsout() );
}
return $soap_response;
}
=head1 RUNNING TESTS
By default, only basic tests that do not require a connection to ExactTarget's
platform are run in t/.
To run the developer tests, you will need to do the following:
=over 4
=item *
Request access to the test environment from ExactTarget (recommended) unless
you want to run the tests in your production environment (definitely NOT
recommended).
=item *
Ask ExactTarget to enable the webservice access for you, if not already set up.
It appears to be a customer-level property only ExactTarget can change.
=item *
( run in 1.856 second using v1.01-cache-2.11-cpan-39bf76dae61 )