AnyEvent-SparkBot
view release on metacpan or search on metacpan
lib/AnyEvent/HTTP/Spark.pm view on Meta::CPAN
=cut
sub build_put_json {
my ($self,$url,$data)=@_;
my $uri=$self->api_url.$url;
my $json=eval {to_json($data)};
return $self->new_false("Failed to convert \$data to json, error was $@") if $@;
my $request=new HTTP::Request(PUT=>$uri,$self->default_headers,$json);
return $self->new_true($request);
}
=item * my $id=$self->que_put_json($cb,$url,$data);
Queue's a json put and returns the id
=cut
sub que_put_json {
t/AnyEvent-HTTP-Spark.t view on Meta::CPAN
cmp_ok($post->content,'eq',to_json({qw(test data)}),'make sure our json serialization works');
cmp_ok($post->method,'eq','POST','Should have a valid post object') or die;
}
{
my $result=$self->build_put_json('test',{qw(test data)});
ok($result,'Should have buid the request without any issues');
my $post=$result->get_data;
cmp_ok($post->uri,'eq',$self->api_url.'test','Should have generated the correct url');
cmp_ok($post->content,'eq',to_json({qw(test data)}),'make sure our json serialization works');
cmp_ok($post->method,'eq','PUT','Should have a valid post object') or die;
}
{
my $result=$self->build_post_form('test',{qw(test data)});
ok($result,'Should have buid the request without any issues');
my $post=$result->get_data;
cmp_ok($post->method,'eq','POST','Should have a valid post object') or die;
cmp_ok($post->uri,'eq',$self->api_url.'test','Should have generated the correct url');
diag $post->as_string;
}
( run in 0.562 second using v1.01-cache-2.11-cpan-4e96b696675 )