Google-CloudTasks

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

# NAME

Google::CloudTasks - Perl client library for the Google CloudTasks API (_unofficial_).

# SYNOPSIS

    use Google::CloudTasks;

    my $client = Google::CloudTasks->client(
        version => 'v2',
        credentials_path => '/path/to/credentials.json',
    );

    #  Create task
    my $project_id = 'myproject';
    my $location_id = 'asia-northeast1';
    my $queue_id = 'myqueue';
    my $parent = "projects/$project_id/locations/$location_id/queues/$queue_id";

    my $task = {
        name => "$parent/tasks/mytask-01234567",

README.md  view on Meta::CPAN

    my $ret = $client->create_task($parent, $task);

# DESCRIPTION

Google::CloudTasks [https://cloud.google.com/tasks/docs/reference/rest/](https://cloud.google.com/tasks/docs/reference/rest/)

This is a Perl client library for the Google CloudTasks API.

## AUTHENTICATION

A service account with appropriate roles is required. You need to download JSON file and specify `credentials_path`.
See also: [https://cloud.google.com/docs/authentication/getting-started#creating\_the\_service\_account](https://cloud.google.com/docs/authentication/getting-started#creating_the_service_account)

# METHODS

All methods handle raw hashref (or arrayref of hashref), rather than objects.

## Create a client

    my $client = Google::CloudTasks->client(
        version => 'v2',
        credentials_path => '/path/to/credentials.json',
    );

`version` is an API version. (Currently only `v2` is available)
`credentials_path` is a path to a service account JSON file.

## Location

Refer the detailed representation of location at [https://cloud.google.com/tasks/docs/reference/rest/Shared.Types/ListLocationsResponse#Location](https://cloud.google.com/tasks/docs/reference/rest/Shared.Types/ListLocationsResponse#Location)

### get\_location

Gets information about a location.

    my $location = $client->get_location("projects/$PROJECT_ID/locations/$LOCATION_ID");

lib/Google/CloudTasks.pm  view on Meta::CPAN

=head1 NAME

Google::CloudTasks - Perl client library for the Google CloudTasks API (I<unofficial>).

=head1 SYNOPSIS

    use Google::CloudTasks;

    my $client = Google::CloudTasks->client(
        version => 'v2',
        credentials_path => '/path/to/credentials.json',
    );

    #  Create task
    my $project_id = 'myproject';
    my $location_id = 'asia-northeast1';
    my $queue_id = 'myqueue';
    my $parent = "projects/$project_id/locations/$location_id/queues/$queue_id";

    my $task = {
        name => "$parent/tasks/mytask-01234567",

lib/Google/CloudTasks.pm  view on Meta::CPAN



=head1 DESCRIPTION

Google::CloudTasks L<https://cloud.google.com/tasks/docs/reference/rest/>

This is a Perl client library for the Google CloudTasks API.

=head2 AUTHENTICATION

A service account with appropriate roles is required. You need to download JSON file and specify C<credentials_path>.
See also: L<https://cloud.google.com/docs/authentication/getting-started#creating_the_service_account>

=head1 METHODS

All methods handle raw hashref (or arrayref of hashref), rather than objects.

=head2 Create a client

    my $client = Google::CloudTasks->client(
        version => 'v2',
        credentials_path => '/path/to/credentials.json',
    );

C<version> is an API version. (Currently only C<v2> is available)
C<credentials_path> is a path to a service account JSON file.

=head2 Location

Refer the detailed representation of location at L<https://cloud.google.com/tasks/docs/reference/rest/Shared.Types/ListLocationsResponse#Location>

=head3 get_location

Gets information about a location.

    my $location = $client->get_location("projects/$PROJECT_ID/locations/$LOCATION_ID");

lib/Google/CloudTasks/Client.pm  view on Meta::CPAN

    isa => 'Str',
    default => 'https://cloudtasks.googleapis.com/',
);

has version => (
    is => 'ro',
    isa => 'Str',
    default => 'v2',
);

has credentials_path => (
    is => 'ro',
    isa => 'Str'
);

has auth => (
    is => 'ro',
    lazy_build => 1,
);

has ua => (

lib/Google/CloudTasks/Client.pm  view on Meta::CPAN

    default => 0,
);

no Mouse;

__PACKAGE__->meta->make_immutable;

sub _build_auth {
    my ($self) = @_;

    if (!$self->credentials_path) {
        die "attribute 'credentials_path' is required";
    }
    my $auth = WWW::Google::Cloud::Auth::ServiceAccount->new(
        credentials_path => $self->credentials_path,
    );
    return $auth;
}

sub request {
    my ($self, $method, $path, $content) = @_;

    my $url = $self->base_url . $self->version . '/' . $path;
    my $req = HTTP::Request->new($method, $url);
    $req->header('Content-Type' => 'application/json; charset=utf8');

t/12_location.t  view on Meta::CPAN

use Test::More;
use Test::Deep;
use Google::CloudTasks;

BEGIN {
    unless (defined $ENV{GOOGLE_APPLICATION_CREDENTIALS} && defined $ENV{PROJECT_ID} && defined $ENV{LOCATION_ID}) {
        Test::More::plan(skip_all => 'This test needs GOOGLE_APPLICATION_CREDENTIALS and PROJECT_ID and LOCATION_ID')
    }
}

my $client = Google::CloudTasks->client(credentials_path => $ENV{GOOGLE_APPLICATION_CREDENTIALS});

subtest 'get' => sub {
    my $name = "projects/$ENV{PROJECT_ID}/locations/$ENV{LOCATION_ID}";
    my $res = $client->get_location($name);

    my $expected = {
        'labels' => {
            'cloud.googleapis.com/region' => $ENV{LOCATION_ID},
        },
        'locationId' => $ENV{LOCATION_ID},

t/13_queue.t  view on Meta::CPAN

use Time::HiRes;
use Google::CloudTasks;

BEGIN {
    unless (defined $ENV{GOOGLE_APPLICATION_CREDENTIALS} && defined $ENV{PROJECT_ID} && defined $ENV{LOCATION_ID}) {
        Test::More::plan(skip_all => 'This test needs GOOGLE_APPLICATION_CREDENTIALS and PROJECT_ID and LOCATION_ID')
    }
}

my $client = Google::CloudTasks->client(
    credentials_path => $ENV{GOOGLE_APPLICATION_CREDENTIALS},
    is_debug => 0,
);
my $parent = "projects/$ENV{PROJECT_ID}/locations/$ENV{LOCATION_ID}";

my $queue_id = sprintf('ct-queue-test-%f-%d', Time::HiRes::time(), int(rand(10000)));
$queue_id =~ s/\./-/g;
my $queue_name = "$parent/queues/$queue_id";

subtest 'create' => sub {
    my $queue = {

t/14_task.t  view on Meta::CPAN

use MIME::Base64;
use Google::CloudTasks;

BEGIN {
    unless (defined $ENV{GOOGLE_APPLICATION_CREDENTIALS} && defined $ENV{PROJECT_ID} && defined $ENV{LOCATION_ID}) {
        Test::More::plan(skip_all => 'This test needs GOOGLE_APPLICATION_CREDENTIALS and PROJECT_ID and LOCATION_ID')
    }
}

my $client = Google::CloudTasks->client(
    credentials_path => $ENV{GOOGLE_APPLICATION_CREDENTIALS},
    is_debug => 0,
);
my $queue_id = sprintf('ct-queue-test-%f-%d', Time::HiRes::time(), int(rand(10000)));
$queue_id =~ s/\./-/g;
my $parent_of_queue = "projects/$ENV{PROJECT_ID}/locations/$ENV{LOCATION_ID}";
my $parent = "$parent_of_queue/queues/$queue_id";
my $queue = {
    name => $parent,
};
$client->create_queue($parent_of_queue, $queue);



( run in 0.312 second using v1.01-cache-2.11-cpan-4d50c553e7e )