API-Client
view release on metacpan or search on metacpan
Changelog for API-Client
debug(Bool)
This attribute is read-only, accepts (Bool) values, and is optional.
fatal
fatal(Bool)
This attribute is read-only, accepts (Bool) values, and is optional.
logger
logger(InstanceOf["FlightRecorder"])
This attribute is read-only, accepts (InstanceOf["FlightRecorder"])
values, and is optional.
name
name(Str)
This attribute is read-only, accepts (Str) values, and is optional.
debug(Bool)
This attribute is read-only, accepts `(Bool)` values, and is optional.
## fatal
fatal(Bool)
This attribute is read-only, accepts `(Bool)` values, and is optional.
## logger
logger(InstanceOf["FlightRecorder"])
This attribute is read-only, accepts `(InstanceOf["FlightRecorder"])` values, and is optional.
## name
name(Str)
This attribute is read-only, accepts `(Str)` values, and is optional.
## retries
lib/API/Client.pm view on Meta::CPAN
isa => 'Bool',
def => 0,
);
has 'fatal' => (
is => 'ro',
isa => 'Bool',
def => 0,
);
has 'logger' => (
is => 'ro',
isa => 'InstanceOf["FlightRecorder"]',
new => 1,
);
fun new_logger($self) {
FlightRecorder->new
}
has 'name' => (
is => 'ro',
isa => 'Str',
new => 1,
);
fun new_name($self) {
lib/API/Client.pm view on Meta::CPAN
return $self->dispatch(%args, method => 'post');
}
method delete(Any %args) {
return $self->dispatch(%args, method => 'delete');
}
method dispatch(Str :$method = 'get', Any %args) {
my $log = $self->logger->info("@{[uc($method)]} @{[$self->url->to_string]}");
my $result = $self->execute(%args, method => $method);
$log->end;
return $result;
}
method fetch(Any %args) {
return $self->dispatch(%args, method => 'get');
}
method patch(Any %args) {
lib/API/Client.pm view on Meta::CPAN
$tx = $ua->start($ua->build_tx($method, $url, $headers, @args));
$self->process($ua, $tx, %args);
# transaction objects
$req = $tx->req;
$res = $tx->res;
# determine success/failure
$ok = $res->code ? $res->code !~ /(4|5)\d\d/ : 0;
# log activity
if ($req && $res) {
my $log = $self->logger;
my $msg = join " ", "attempt", ("#".($i+1)), ": $method", $url->to_string;
$log->debug("req: $msg")->data({
request => $req->to_string =~ s/\s*$/\n\n\n/r
});
$log->debug("res: $msg")->data({
response => $res->to_string =~ s/\s*$/\n\n\n/r
});
# output to the console where applicable
$log->info("res: $msg [@{[$res->code]}]");
$log->output if $self->debug;
}
# no retry necessary
last if $ok;
}
# throw exception if fatal is truthy
if ($req && $res && $self->fatal && !$ok) {
my $code = $res->code;
lib/API/Client.pm view on Meta::CPAN
=cut
=head2 fatal
fatal(Bool)
This attribute is read-only, accepts C<(Bool)> values, and is optional.
=cut
=head2 logger
logger(InstanceOf["FlightRecorder"])
This attribute is read-only, accepts C<(InstanceOf["FlightRecorder"])> values, and is optional.
=cut
=head2 name
name(Str)
This attribute is read-only, accepts C<(Str)> values, and is optional.
t/API_Client.t view on Meta::CPAN
Data::Object::Role::Buildable
Data::Object::Role::Stashable
Data::Object::Role::Throwable
=cut
=attributes
debug: ro, opt, Bool
fatal: ro, opt, Bool
logger: ro, opt, InstanceOf["FlightRecorder"]
name: ro, opt, Str
retries: ro, opt, Int
timeout: ro, opt, Int
url: ro, opt, InstanceOf["Mojo::URL"]
user_agent: ro, opt, InstanceOf["Mojo::UserAgent"]
version: ro, opt, Str
=cut
=description
( run in 1.157 second using v1.01-cache-2.11-cpan-49f99fa48dc )