Amazon-SimpleDB

 view release on metacpan or  search on metacpan

lib/Amazon/SimpleDB.pm  view on Meta::CPAN

package Amazon::SimpleDB;
use strict;
use warnings;

our $VERSION = '0.03';

use URI;
use LWP::UserAgent;
use Digest::HMAC_SHA1;
use MIME::Base64 qw(encode_base64);
use Carp qw( croak );

use Amazon::SimpleDB::Domain;
use Amazon::SimpleDB::Response;

use constant SERVICE_URI          => 'http://sdb.amazonaws.com/';
use constant KEEP_ALIVE_CACHESIZE => 10;

sub new {
    my $class = shift;
    my $args  = shift || {};
    my $self  = bless $args, $class;
    croak "No aws_access_key_id"     unless $self->{aws_access_key_id};
    croak "No aws_secret_access_key" unless $self->{aws_secret_access_key};
    unless ($self->{agent}) {
        my $agent = LWP::UserAgent->new(keep_alive => KEEP_ALIVE_CACHESIZE);
        $agent->timeout(10);
        $agent->env_proxy;
        $self->{agent} = $agent;
    }
    return $self;
}

sub domains {
    my $self   = shift;
    my $args   = shift || {};
    my $params = {};
    $params->{MaxNumberOfDomains} = $args->{'limit'} if $args->{'limit'};
    $params->{NextToken}          = $args->{'next'}  if $args->{'next'};
    my $res = $self->request('ListDomains', $params);
    return
      Amazon::SimpleDB::Response->new(
                                      {
                                       http_response => $res,
                                       account       => $self
                                      }
      );
}

sub domain {
    return Amazon::SimpleDB::Domain->new({name => $_[1], account => $_[0]});
}

sub create_domain {    # note no more than 100 per account.
    my ($self, $name) = @_;
    my $res = $self->request('CreateDomain', {DomainName => $name});
    return
      Amazon::SimpleDB::Response->new(
                                      {
                                       http_response => $res,
                                       account       => $self
                                      }
      );
}

sub delete_domain {
    my ($self, $name) = @_;
    my $res = $self->request('DeleteDomain', {DomainName => $name});
    return
      Amazon::SimpleDB::Response->new(
                                      {
                                       http_response => $res,
                                       account       => $self
                                      }
      );
}

#--- utility methods

sub request {    # returns "raw" HTTP Response from SimpleDB
    my ($self, $action, $params) = @_;
    croak "No Action parameter" unless $action;



( run in 0.448 second using v1.01-cache-2.11-cpan-39bf76dae61 )