ArangoDB2
view release on metacpan or search on metacpan
lib/ArangoDB2/HTTP/LWP.pm view on Meta::CPAN
package ArangoDB2::HTTP::LWP;
use strict;
use warnings;
use base qw(
ArangoDB2::HTTP
);
use Data::Dumper;
use JSON::XS;
use LWP::UserAgent;
use Scalar::Util qw(weaken);
my $JSON = JSON::XS->new->utf8;
sub new
{
my($class, $arango) = @_;
# we do not want to hold this reference if the
# parent goes out of scope
weaken $arango;
# create new instance
my $self = {
arango => $arango,
};
bless($self, $class);
$self->{lwp} = LWP::UserAgent->new(
keep_alive => 1
);
# set authentication is username is specified
if ($self->arango->username) {
$self->lwp->default_headers->authorization_basic(
$self->arango->username,
$self->arango->password,
);
}
return $self;
}
# delete
#
# make a DELETE request using the ArangoDB API uri along with
# the path and any args passed
sub delete
{
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->delete($uri);
# do not process response if raw requested
return $response if $raw;
# process response
return $self->response($response);
}
# get
#
# make a GET request using the ArangoDB API uri along with
# the path and any args passed
sub get
{
my($self, $path, $args, $raw) = @_;
# get copy of ArangoDB API URI
my $uri = $self->arango->uri->clone;
( run in 0.628 second using v1.01-cache-2.11-cpan-39bf76dae61 )