Amazon-SNS-V4

 view release on metacpan or  search on metacpan

lib/Amazon/SNS/V4.pm  view on Meta::CPAN

	if ($arn =~ m{\.fifo$}) {
		return GetFifoTopic( @_ );
	}

	return Amazon::SNS::V4::Topic->new({
		'sns' => $self,
		'arn' => $arn,
	});
}

sub GetFifoTopic
{
	my ($self, $arn) = @_;

	return Amazon::SNS::V4::FifoTopic->new({
		'sns' => $self,
		'arn' => $arn,
	});
}

sub GetTarget
{
	my ($self, $arn) = @_;

	return Amazon::SNS::V4::Target->new({
		'sns' => $self,
		'arn' => $arn,
	});
}

sub DeleteTopic
{
	my ($self, $arn) = @_;

	return $self->dispatch({
		'Action'	=> 'DeleteTopic',
		'TopicArn'	=> $arn,
	});
}

sub ListTopics
{
	my ($self, $name) = @_;

	my $r = $self->dispatch({
		'Action'	=> 'ListTopics',
	});

	return map {

		Amazon::SNS::V4::Topic->new({
			'sns' => $self,
			'arn' => $_->{'TopicArn'},
		})

	} @{$r->{'ListTopicsResult'}{'Topics'}[0]{'member'}};
}

sub Subscribe
{
	my ($self, $protocol, $topicarn, $endpoint) = @_;

	$self->dispatch({
		'Action'	=> 'Subscribe',
		'Protocol'	=> $protocol,
		'TopicArn'	=> $topicarn,
		'Endpoint'	=> $endpoint,
	});
}

sub Unsubscribe
{
	my ($self, $arn) = @_;

	$self->dispatch({
		'Action'		=> 'Unsubscribe',
		'SubscriptionArn'	=> $arn,
	});
}

sub dispatch
{
	my ($self, $args) = @_;

	$self->error(undef);
	$self->error_response(undef);

	$self->service('https://sns.eu-west-1.amazonaws.com')
		unless defined $self->service;
	$self->signer( AWS::Signature4->new(
		-access_key => scalar $self->key,
		-secret_key => scalar $self->secret,
	)) unless defined $self->signer;
	my $signer = $self->signer;

	# sanitize args
	do { delete $args->{$_} unless defined $args->{$_} } for (keys %$args);

	$args->{'Version'} = '2010-03-31';

	if (defined($args->{'Attributes'}) and ref($args->{'Attributes'}) eq 'HASH') {
		foreach my $attr (keys %{$args->{'Attributes'}}) {
			$args->{$attr} = $args->{'Attributes'}->{$attr};
		}
		delete $args->{'Attributes'};
	}

	my $post = POST $self->service, [%$args];
	$signer->sign( $post );
	
	my $response = LWP::UserAgent->new->request( $post );

	$self->status_code($response->code);

	if ($response->is_success) {
		return XMLin($response->content,
				'SuppressEmpty' => 1,
#				'KeyAttr' => { },
				'ForceArray' => [ qw/ Topics member / ],
		);
	} else {
		$self->error_response( $response->content );
		$self->error(
			($response->content =~ /^<.+>/)
				? eval { XMLin($response->content)->{'Error'}{'Message'} || $response->status_line }
				: $response->status_line
		);



( run in 1.136 second using v1.01-cache-2.11-cpan-524268b4103 )