ArangoDB2
view release on metacpan or search on metacpan
lib/ArangoDB2/HTTP/Curl.pm view on Meta::CPAN
# patch
#
# make a PATCH request using the ArangoDB API uri along with
# the path and any args passed
sub patch
{
my($self, $path, $args, $data, $raw) = @_;
return $self->curl("PATCH", $path, $args, $data, $raw);
}
# put
#
# make a PUT request using the ArangoDB API uri along with
# the path and any args passed
sub put
{
my($self, $path, $args, $data, $raw) = @_;
return $self->curl("PUT", $path, $args, $data, $raw);
}
# post
#
# make a POST request using the ArangoDB API uri along with
# the path and any args passed
sub post
{
my($self, $path, $args, $data, $raw) = @_;
return $self->curl("POST", $path, $args, $data, $raw);
}
# curl_response
#
# process a curl response
sub curl_response
{
my($self, $curl, $ret, $response) = @_;
# a curl error occured
if ($ret != 0) {
$self->error($curl->strerror($ret)." ".$curl->errbuf);
return;
}
# get http response code
my $code = $curl->getinfo(CURLINFO_HTTP_CODE);
# require code in 200 range for success
if (!($code >= 200 && $code < 300)) {
$self->error($code);
return;
}
# decode response, assuming JSON
my $res = eval { $JSON->decode($$response) };
# if content is not valid JSON then return entire content
return $$response unless $res;
# res may be array in rare cases
if (!(ref $res eq 'HASH')) {
return $res;
}
# if there is a result object and no error and this is not a
# cursor result then only return the result object
elsif ( ($res->{result} || $res->{graph} || $res->{graphs})
&& !$res->{error} && !defined $res->{hasMore} )
{
return $res->{result} || $res->{graph} || $res->{graphs};
}
# otherwise return entire response
else {
return $res;
}
}
1;
__END__
=head1 NAME
ArangoDB2::HTTP::LWP - ArangoDB HTTP transport layer implemented with LWP
=head1 METHODS
=over 4
=item new
=item curl
=item delete
=item get
=item head
=item patch
=item put
=item post
=item curl_response
=back
=head1 AUTHOR
Ersun Warncke, C<< <ersun.warncke at outlook.com> >>
http://ersun.warnckes.com
=head1 COPYRIGHT
Copyright (C) 2014 Ersun Warncke
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
( run in 0.833 second using v1.01-cache-2.11-cpan-39bf76dae61 )