API-Client
view release on metacpan or search on metacpan
t/API_Client.t view on Meta::CPAN
=cut
=method process
The process method acts as an C<after> hook triggered after each response where
you can modify the transactor objects.
=signature process
process(Object $ua, Object $tx, Any %args) : Object
=example-1 process
# given: synopsis
require Mojo::UserAgent;
require Mojo::Transaction::HTTP;
$client->process(
Mojo::UserAgent->new,
Mojo::Transaction::HTTP->new
);
=cut
=method resource
The resource method returns a new instance of the object for the API resource
endpoint specified.
=signature resource
resource(Str @segments) : Object
=example-1 resource
# given: synopsis
$client->resource('status', 200);
=cut
=method serialize
The serialize method serializes and returns the object as a C<hashref>.
=signature serialize
serialize() : HashRef
=example-1 serialize
# given: synopsis
$client->serialize;
=cut
=method update
The update method issues a C<PUT> request to the API resource represented by
the object.
=signature update
update(Any %args) : InstanceOf["Mojo::Transaction"]
=example-1 update
# given: synopsis
$client->resource('put')->update(
json => {active => 1}
);
=cut
package main;
use Mojo::UserAgent;
SKIP: {
my $skip_tests = do {
my $tx = Mojo::UserAgent->new->get('https://httpbin.org/anything');
!eval{$tx->result->is_success};
};
unless ($skip_tests) {
my $test = testauto(__FILE__);
my $subs = $test->standard;
$subs->synopsis(fun($tryable) {
ok my $result = $tryable->result;
$result
});
$subs->scenario('building', fun($tryable) {
require Scalar::Util;
ok my $result = $tryable->result;
my $get = $result->[0];
my $head = $result->[1];
my $patch = $result->[2];
isnt Scalar::Util::refaddr($get), Scalar::Util::refaddr($head);
isnt Scalar::Util::refaddr($get), Scalar::Util::refaddr($patch);
isnt Scalar::Util::refaddr($head), Scalar::Util::refaddr($patch);
is $get->req->method, 'get';
is $head->req->method, 'head';
is $patch->req->method, 'patch';
});
$subs->scenario('chaining', fun($tryable) {
require Scalar::Util;
ok my $result = $tryable->result;
my $users = $result->[0];
( run in 0.474 second using v1.01-cache-2.11-cpan-140bd7fdf52 )