Email-ExactTarget
view release on metacpan or search on metacpan
lib/Email/ExactTarget/SubscriberOperations.pm view on Meta::CPAN
},
$class,
);
return $self;
}
=head2 exact_target()
Returns the main Exact Target object.
my $exact_target = $subscriber_operations->exact_target();
=cut
sub exact_target
{
my ( $self ) = @_;
return $self->{'exact_target'};
}
=head2 create()
Creates a new subscriber in ExactTarget's database using the staged changes on
the subscriber objects passed as parameter.
$subscriber_operations->create(
\@subscribers
);
=cut
sub create
{
my ( $self, $subscribers ) = @_;
return $self->_update_create(
'subscribers' => $subscribers,
'soap_action' => 'Create',
'soap_method' => 'CreateRequest',
'options' => undef,
);
}
=head2 update_or_create()
Creates a new subscriber in ExactTarget's database using the staged changes on
the subscriber objects passed as parameter. If the subscriber already exists in
the database, updates it.
$subscriber_operations->update_or_create(
\@subscribers
);
=cut
sub update_or_create
{
my ( $self, $subscribers ) = @_;
return $self->_update_create(
'subscribers' => $subscribers,
'soap_action' => 'Create',
'soap_method' => 'CreateRequest',
'options' => SOAP::Data->name(
'Options' => \SOAP::Data->value(
SOAP::Data->name(
'SaveOptions' => \SOAP::Data->value(
SOAP::Data->name(
'SaveOption' => \SOAP::Data->value(
SOAP::Data->name(
'PropertyName' => '*',
),
SOAP::Data->name(
'SaveAction' => 'UpdateAdd',
),
),
),
),
),
),
),
);
}
=head2 update()
Applies to ExactTarget's database any staged changes on the subscriber objects
passed as parameter.
$subscriber_operations->update(
\@subscribers
);
=cut
sub update
{
my ( $self, $subscribers ) = @_;
return $self->_update_create(
'subscribers' => $subscribers,
'soap_action' => 'Update',
'soap_method' => 'UpdateRequest',
'options' => SOAP::Data->name(
'Options' => \SOAP::Data->value(),
),
);
}
=head2 retrieve()
Retrieves from ExactTarget's database the subscribers corresponding to the
unique identifiers passed as parameter.
my $subscribers = $subscriber_operations->retrieve(
'email' => [ $email1, $email2 ],
);
=cut
sub retrieve
{
my ( $self, %args ) = @_;
my $email = delete( $args{'email'} );
# Check parameters.
confess 'Emails identifying the subscribers to retrieve were not passed.'
if !defined( $email );
confess "The 'email' parameter must be an arrayref"
if !Data::Validate::Type::is_arrayref( $email );
confess 'Emails identifying the subscribers to retrieve were not passed.'
if scalar( @$email ) == 0;
# The 'IN' operator in ExactTarget requires at least 2 emails.
# If only one email is passed, we're simply going to send it twice and get one
# result back.
$email = [ $email->[0], $email->[0] ]
if scalar( @$email ) == 1;
# Shortcuts.
my $exact_target = $self->exact_target() || confess 'Email::ExactTarget object is not defined';
my $verbose = $exact_target->verbose();
# Prepare SOAP content.
my $soap_args =
[
SOAP::Data->name(
RetrieveRequest => \SOAP::Data->value(
SOAP::Data->name(
ObjectType => 'Subscriber',
),
SOAP::Data->name(
Properties => ( 'ID', 'EmailTypePreference', 'EmailAddress' ),
( run in 0.504 second using v1.01-cache-2.11-cpan-d7f47b0818f )