X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flib%2FTest%2FRest.pm;fp=t%2Flib%2FTest%2FRest.pm;h=581409345aa830ef7a991992003b86f3a2d0937c;hb=7ad87df957f65463dba321ebe616e2581b7ff58f;hp=0000000000000000000000000000000000000000;hpb=256c894fcf95e1a0716676afb8f5732854734672;p=catagits%2FCatalyst-Action-REST.git diff --git a/t/lib/Test/Rest.pm b/t/lib/Test/Rest.pm new file mode 100644 index 0000000..5814093 --- /dev/null +++ b/t/lib/Test/Rest.pm @@ -0,0 +1,86 @@ +# +# Rest.pm +# Created by: Adam Jacob, Marchex, +# Created on: 10/16/2006 11:11:25 AM PDT +# +# $Id: $ + +package Test::Rest; + +use strict; +use warnings; + +use LWP::UserAgent; +use Params::Validate qw(:all); + +sub new { + my $self = shift; + my %p = validate(@_, + { + content_type => { type => SCALAR }, + }, + ); + my $ref = { + 'ua' => LWP::UserAgent->new, + 'content_type' => $p{'content_type'}, + }; + bless $ref, $self; +} + +sub get { + my $self = shift; + my %p = validate(@_, + { + url => { type => SCALAR }, + }, + ); + my $req = HTTP::Request->new('GET' => $p{'url'}); + $req->content_type($self->{'content_type'}); + return $req; +} + +sub delete { + my $self = shift; + my %p = validate(@_, + { + url => { type => SCALAR }, + }, + ); + my $req = HTTP::Request->new('DELETE' => $p{'url'}); + $req->content_type($self->{'content_type'}); + return $req; +} + +sub put { + my $self = shift; + my %p = validate(@_, + { + url => { type => SCALAR }, + data => 1, + }, + ); + my $req = HTTP::Request->new('PUT' => $p{'url'}); + $req->content_type($self->{'content_type'}); + $req->content_length(do { use bytes; length($p{'data'}) }); + $req->content($p{'data'}); + return $req; +} + +sub post { + my $self = shift; + my %p = validate(@_, + { + url => { type => SCALAR }, + data => { required => 1 }, + }, + ); + my $req = HTTP::Request->new('POST' => $p{'url'}); + $req->content_type($self->{'content_type'}); + $req->content_length(do { use bytes; length($p{'data'}) }); + $req->content($p{'data'}); + return $req; +} + + +1; +