Cloudflare-API

 view release on metacpan or  search on metacpan

t/01-client.t  view on Meta::CPAN

use JSON::PP qw(encode_json);
use Cloudflare::API;

my @request;
my $reply_hr={ success => JSON::PP::true, result => { id => 'one' }, result_info => { page => 2 } };
my $api_or=Cloudflare::API->new(
    token      => 'test-token',
    account_id => 'account one',
    transport  => sub {
        push(@request, [@_]);
        return { status => 200, headers => { 'content-type' => 'application/json' },
            content => encode_json($reply_hr) };
    }
);

is_deeply($api_or->request('GET', '/example'), { id => 'one' }, 'result is unwrapped');
is_deeply($api_or->request('GET', '/example', full_response => 1), $reply_hr,
    'full parsed response is available');
is_deeply($api_or->request_full('GET', '/example'), $reply_hr,
    'request_full returns the envelope');
isa_ok($api_or->response('GET', '/example'), 'HTTP::API::Core::Response');

t/05-pagination.t  view on Meta::CPAN

        elsif ($url=~m{/workers/scripts\z}) {
            $body_hr={ success => JSON::PP::true, result => [{id => 'worker'}] };
        }
        elsif ($url=~m{/failure\?page=1\z}) {
            $body_hr={ success => JSON::PP::false,
                errors => [{code => 1000, message => 'failed'}] };
        }
        else {
            die "unexpected test request: $method $url\n";
        }
        return {status => 200, headers => {'content-type' => 'application/json'},
            content => encode_json($body_hr)};
    }
);

my $request_no=@request;
my $page_or=$api_or->zones()->list_page(per_page => 2);
isa_ok($page_or, 'HTTP::API::Core::Pagination');
is(scalar(@request), $request_no, 'list_page is lazy');
is_deeply(scalar($page_or->all()), [{id => 'one'}, {id => 'two'}, {id => 'three'}],
    'page-number pagination returns every item');



( run in 1.987 second using v1.01-cache-2.11-cpan-99fa8243a42 )