ArangoDB2
view release on metacpan or search on metacpan
lib/ArangoDB2/HTTP/LWP.pm view on Meta::CPAN
# make request
my $response = $self->lwp->get($uri);
# do not process response if raw requested
return $response if $raw;
# process response
return $self->response($response);
}
# head
#
# make a HEAD request using the ArangoDB API uri along with
# the path and any args passed
sub head
{
my($self, $path, $args, $raw) = @_;
# get copy of ArangoDB API URI
my $uri = $self->arango->uri->clone;
# set path for request
$uri->path($path);
# set query params on URI if passed
$uri->query_form($args) if $args;
# make request
my $response = $self->lwp->head($uri);
# do not process response if raw requested
return $response if $raw;
# return code
return $response->code;
}
# lwp
#
# LWP::UserAgent instance
sub lwp { $_[0]->{lwp} }
# patch
#
# make a PATCH request using the ArangoDB API uri along with
# the path and any args passed
sub patch
{
my($self, $path, $args, $patch, $raw) = @_;
# get copy of ArangoDB API URI
my $uri = $self->arango->uri->clone;
# set path for request
$uri->path($path);
# set query params on URI if passed
$uri->query_form($args) if $args;
# build HTTP::Request
my $request = HTTP::Request->new('PATCH', $uri);
$request->content($patch);
# make request
my $response = $self->lwp->request($request);
# do not process response if raw requested
return $response if $raw;
# process response
return $self->response($response);
}
# put
#
# make a PUT request using the ArangoDB API uri along with
# the path and any args passed
sub put
{
my($self, $path, $args, $put, $raw) = @_;
# get copy of ArangoDB API URI
my $uri = $self->arango->uri->clone;
# set path for request
$uri->path($path);
# set query params on URI if passed
$uri->query_form($args) if $args;
# make request
my $response = ref $put
# if put is hashref then treat as key/value pairs
# to be form encoded
? $self->lwp->put($uri, $put)
# if put is string then put raw data
: $self->lwp->put($uri, Content => $put);
# do not process response if raw requested
return $response if $raw;
# process response
return $self->response($response);
}
# post
#
# make a POST request using the ArangoDB API uri along with
# the path and any args passed
sub post
{
my($self, $path, $args, $post, $raw) = @_;
# get copy of ArangoDB API URI
my $uri = $self->arango->uri->clone;
# set path for request
$uri->path($path);
# set query params on URI if passed
$uri->query_form($args) if $args;
# make request
my $response = ref $post
# if post is hashref then treat as key/value pairs
# to be form encoded
? $self->lwp->post($uri, $post)
# if post is string then post raw data
: $self->lwp->post($uri, Content => $post);
# do not process response if raw requested
return $response if $raw;
# process response
return $self->response($response);
}
# response
#
# process LWP::UserAgent response
sub response
{
my($self, $response) = @_;
if ($response->is_success) {
my $res = eval { $JSON->decode($response->content) };
# if content is not valid JSON then return entire content
return $response->content unless $res;
( run in 1.688 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )