package Sunflower::Queue;

use strict;
use warnings;
use Amazon::SQS::Simple;

our $VERSION = '0.01';

sub new {
    my ( $class, $access_key, $secret_key ) = ( shift, shift, shift );

    $access_key ||= 'somekey';
    $secret_key ||= 'secretkey';
    
    my $self = {};	
	bless( $self, $class );
	
	# create and instance of SQS 
    $self->queue_service( 
        Amazon::SQS::Simple->new( $access_key, $secret_key ) 
    );
    
    return $self;
}

sub run_tests {
    my $class = shift;

    require Test::Builder;
    
    my $test = Test::Builder->new();
    $test->no_plan;        
    $test->diag( 'testing ' . __PACKAGE__ );    
            
    my $o = __PACKAGE__->new();
    
    for ( 1 .. 10 ) {
        $test->is_eq( $o->test_method, 'tim', "testing for tim" );
    }
    
}

sub test_method {
    my $self = shift;
    return 'tim';
}

# Queue stuff
sub ListQueues {
    my $self = shift;    
    $self->queue_service->ListQueues( @_ );
}

sub GetQueue {
    my $self = shift;    
    $self->queue_service->GetQueue( @_ );
}

sub CreateQueue {
    my $self = shift;        
    $self->queue_service->CreateQueue( @_ );
}

# Messages
sub ReceiveMessage {
    my $self = shift;        
    return $self->queue_service->ReceiveMessage( @_ );
}

# alias for ReceiveMessage 
sub get_message {
    my $self = shift;        
    return $self->queue_service->ReceiveMessage( @_ );
}

# delete the message
sub DeleteMessage {
    my $self = shift;        
    return $self->queue_service->DeleteMessage( @_ );
}

# delete the queue
sub Delete {
    my $self = shift;        
    return $self->queue_service->Delete( @_ );
}

sub queue_service {
    my( $self, $obj ) = @_;

    if ( defined $obj ) {
        $self->{_queue_service} = $obj;
    }

    return $self->{_queue_service};
}

1;
__END__

=head1 NAME

Sunflower::Queue 

=head1 SYNOPSIS

  use Sunflower::Queue;
  
  my $service = Sunflower::Queue->new( $access_key, $secret_key );
 
  $service->CreateQueue
  $service->ListQueues
  
=head1 DESCRIPTION

With this class you can instantiate a custom object using the Amazon::SQS 
queuing service. 

Also, See Amazon::SQS for more detailed documentation
 
=head2 Tests

perl -Ilib -mSunflower::Queue -e 'Sunflower::Queue->run_tests;'

=head1 SEE ALSO

Test::Builder, Amazon::SQS

=head1 AUTHOR

Tim Keefer, E<lt>tim@timkeefer.comE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2007 by Timotheus Keefer

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.6 or,
at your option, any later version of Perl 5 you may have available.

=cut
