| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Google::CloudTasks; | 
| 2 | 4 |  |  | 4 |  | 259115 | use 5.008001; | 
|  | 4 |  |  |  |  | 43 |  | 
| 3 | 4 |  |  | 4 |  | 21 | use strict; | 
|  | 4 |  |  |  |  | 7 |  | 
|  | 4 |  |  |  |  | 76 |  | 
| 4 | 4 |  |  | 4 |  | 17 | use warnings; | 
|  | 4 |  |  |  |  | 6 |  | 
|  | 4 |  |  |  |  | 112 |  | 
| 5 | 4 |  |  | 4 |  | 606 | use utf8; | 
|  | 4 |  |  |  |  | 18 |  | 
|  | 4 |  |  |  |  | 25 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 4 |  |  | 4 |  | 1576 | use Google::CloudTasks::Client; | 
|  | 4 |  |  |  |  | 12 |  | 
|  | 4 |  |  |  |  | 538 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | our $VERSION = "0.01"; | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | sub client { | 
| 12 | 0 |  |  | 0 | 1 |  | my ($class, @args) = @_; | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 0 |  |  |  |  |  | my %args = @args; | 
| 15 | 0 | 0 | 0 |  |  |  | if ($args{version} and $args{version} ne 'v2') { | 
| 16 | 0 |  |  |  |  |  | die "Currently only version 'v2' of CloudTasks is suppoted."; | 
| 17 |  |  |  |  |  |  | } | 
| 18 | 0 |  |  |  |  |  | return Google::CloudTasks::Client->new(@args); | 
| 19 |  |  |  |  |  |  | } | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | 1; | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | __END__ | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | =encoding utf-8 | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | =head1 NAME | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | Google::CloudTasks - Perl client library for the Google CloudTasks API (I<unofficial>). | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | use Google::CloudTasks; | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | my $client = Google::CloudTasks->client( | 
| 36 |  |  |  |  |  |  | version => 'v2', | 
| 37 |  |  |  |  |  |  | credentials_path => '/path/to/credentials.json', | 
| 38 |  |  |  |  |  |  | ); | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | #  Create task | 
| 41 |  |  |  |  |  |  | my $project_id = 'myproject'; | 
| 42 |  |  |  |  |  |  | my $location_id = 'asia-northeast1'; | 
| 43 |  |  |  |  |  |  | my $queue_id = 'myqueue'; | 
| 44 |  |  |  |  |  |  | my $parent = "projects/$project_id/locations/$location_id/queues/$queue_id"; | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | my $task = { | 
| 47 |  |  |  |  |  |  | name => "$parent/tasks/mytask-01234567", | 
| 48 |  |  |  |  |  |  | appEngineHttpRequest => { | 
| 49 |  |  |  |  |  |  | relativeUri => '/do_task', | 
| 50 |  |  |  |  |  |  | }, | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  | my $ret = $client->create_task($parent, $task); | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | Google::CloudTasks L<https://cloud.google.com/tasks/docs/reference/rest/> | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | This is a Perl client library for the Google CloudTasks API. | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =head2 AUTHENTICATION | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | A service account with appropriate roles is required. You need to download JSON file and specify C<credentials_path>. | 
| 64 |  |  |  |  |  |  | See also: L<https://cloud.google.com/docs/authentication/getting-started#creating_the_service_account> | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | =head1 METHODS | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | All methods handle raw hashref (or arrayref of hashref), rather than objects. | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | =head2 Create a client | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | my $client = Google::CloudTasks->client( | 
| 73 |  |  |  |  |  |  | version => 'v2', | 
| 74 |  |  |  |  |  |  | credentials_path => '/path/to/credentials.json', | 
| 75 |  |  |  |  |  |  | ); | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | C<version> is an API version. (Currently only C<v2> is available) | 
| 78 |  |  |  |  |  |  | C<credentials_path> is a path to a service account JSON file. | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | =head2 Location | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | Refer the detailed representation of location at L<https://cloud.google.com/tasks/docs/reference/rest/Shared.Types/ListLocationsResponse#Location> | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | =head3 get_location | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | Gets information about a location. | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | my $location = $client->get_location("projects/$PROJECT_ID/locations/$LOCATION_ID"); | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | =head3 list_locations | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | Lists information about all locations under project. | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | my $ret = $client->list_locations("projects/$PROJECT_ID"); | 
| 95 |  |  |  |  |  |  | my $locations = $ret->{locations}; | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | =head2 Queue | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | Refer the detailed representation of queue at L<https://cloud.google.com/tasks/docs/reference/rest/v2/projects.locations.queues#Queue> | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | =head3 create_queue | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | Creates a queue. | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | my $queue = { | 
| 106 |  |  |  |  |  |  | name => 'queue-name', | 
| 107 |  |  |  |  |  |  | }; | 
| 108 |  |  |  |  |  |  | my $created = $client->create_queue("projects/$PROJECT_ID/locations/$LOCATION_ID", $queue); | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | =head3 delete_queue | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | Deletes a queue. | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | $client->delete_queue("projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID") | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | =head3 get_queue | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | Gets information of a queue. | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | my $queue = $client->get_queue("projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID"); | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | =head3 list_queues | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | Lists information of all queues. | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | my $ret = $client->list_queues("projects/$PROJECT_ID/locations/$LOCATION_ID"); | 
| 127 |  |  |  |  |  |  | my $queues = $ret->{queues}; | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | =head3 patch_queue | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | Updates a queue. | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | my $queue = { | 
| 134 |  |  |  |  |  |  | retryConfig => { | 
| 135 |  |  |  |  |  |  | maxAttempts => 5, | 
| 136 |  |  |  |  |  |  | }, | 
| 137 |  |  |  |  |  |  | }; | 
| 138 |  |  |  |  |  |  | my $update_mask = { updateMask => 'retryConfig.maxAttempts' }; | 
| 139 |  |  |  |  |  |  | my $updated = $client->patch_queue( | 
| 140 |  |  |  |  |  |  | "projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID", | 
| 141 |  |  |  |  |  |  | $queue, | 
| 142 |  |  |  |  |  |  | $update_mask,   # optional | 
| 143 |  |  |  |  |  |  | ); | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | =head3 pause_queue | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | Pauses a queue. | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | my $queue = $client->pause_queue("projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID"); | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | =head3 resume_queue | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | Resumes a queue. | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | my $queue = $client->resume_queue("projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID"); | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | =head3 get_iam_policy_queue | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | Gets the access control policy for a queue. | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | my $policy = $client->get_iam_policy_queue("projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID"); | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  | =head3 set_iam_policy_queue | 
| 164 |  |  |  |  |  |  |  | 
| 165 |  |  |  |  |  |  | Sets the access control policy for a queue. | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | my $policy = { | 
| 168 |  |  |  |  |  |  | bindings => [ | 
| 169 |  |  |  |  |  |  | +{ | 
| 170 |  |  |  |  |  |  | role => 'roles/viewer', | 
| 171 |  |  |  |  |  |  | members => [ | 
| 172 |  |  |  |  |  |  | 'serviceAccount:service-account-name@myproject.gserviceaccount.com', | 
| 173 |  |  |  |  |  |  | ], | 
| 174 |  |  |  |  |  |  | } | 
| 175 |  |  |  |  |  |  | ], | 
| 176 |  |  |  |  |  |  | etag => $etag,  # got via get_iam_policy_queue | 
| 177 |  |  |  |  |  |  | }; | 
| 178 |  |  |  |  |  |  | $policy = $client->set_iam_policy_queue( | 
| 179 |  |  |  |  |  |  | "projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID", | 
| 180 |  |  |  |  |  |  | $policy, | 
| 181 |  |  |  |  |  |  | ); | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | =head2 Task | 
| 184 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  | Refer the detailed representation of task at L<https://cloud.google.com/tasks/docs/reference/rest/v2/projects.locations.queues.tasks#Task> | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | =head3 create_task | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | Creates a task. Note that a request body in C<appEngineHttpRequest> should be base64-encoded. | 
| 190 |  |  |  |  |  |  |  | 
| 191 |  |  |  |  |  |  | use MIME::Base64; | 
| 192 |  |  |  |  |  |  |  | 
| 193 |  |  |  |  |  |  | my $body = encode_base64('{"name": "TaskTest"}'); | 
| 194 |  |  |  |  |  |  | chomp($body); | 
| 195 |  |  |  |  |  |  |  | 
| 196 |  |  |  |  |  |  | my $task = { | 
| 197 |  |  |  |  |  |  | name => "projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID", | 
| 198 |  |  |  |  |  |  | appEngineHttpRequest => { | 
| 199 |  |  |  |  |  |  | relativeUri => '/path', | 
| 200 |  |  |  |  |  |  | headers => [ | 
| 201 |  |  |  |  |  |  | 'Content-Type' => 'application/json', | 
| 202 |  |  |  |  |  |  | ], | 
| 203 |  |  |  |  |  |  | body => $body, | 
| 204 |  |  |  |  |  |  | }, | 
| 205 |  |  |  |  |  |  | }; | 
| 206 |  |  |  |  |  |  | my $created = $client->create_task( | 
| 207 |  |  |  |  |  |  | "projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID", | 
| 208 |  |  |  |  |  |  | $task | 
| 209 |  |  |  |  |  |  | ); | 
| 210 |  |  |  |  |  |  |  | 
| 211 |  |  |  |  |  |  | =head3 delete_task | 
| 212 |  |  |  |  |  |  |  | 
| 213 |  |  |  |  |  |  | Deletes a task. | 
| 214 |  |  |  |  |  |  |  | 
| 215 |  |  |  |  |  |  | $client->delete_task("projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID/tasks/$TASK_ID"); | 
| 216 |  |  |  |  |  |  |  | 
| 217 |  |  |  |  |  |  | =head3 get_task | 
| 218 |  |  |  |  |  |  |  | 
| 219 |  |  |  |  |  |  | Gets information of a task. | 
| 220 |  |  |  |  |  |  |  | 
| 221 |  |  |  |  |  |  | my $task = $client->get_task("projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID/tasks/$TASK_ID"); | 
| 222 |  |  |  |  |  |  |  | 
| 223 |  |  |  |  |  |  | =head3 list_tasks | 
| 224 |  |  |  |  |  |  |  | 
| 225 |  |  |  |  |  |  | Lists information of all tasks. | 
| 226 |  |  |  |  |  |  |  | 
| 227 |  |  |  |  |  |  | my $ret = $client->list_tasks("projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID"); | 
| 228 |  |  |  |  |  |  | my $tasks = $ret->{tasks}; | 
| 229 |  |  |  |  |  |  |  | 
| 230 |  |  |  |  |  |  | =head3 run_task | 
| 231 |  |  |  |  |  |  |  | 
| 232 |  |  |  |  |  |  | Runs a task. | 
| 233 |  |  |  |  |  |  |  | 
| 234 |  |  |  |  |  |  | my $ret = $client->run_task("projects/$PROJECT_ID/locations/$LOCATION_ID/queues/$QUEUE_ID/tasks/$TASK_ID"); | 
| 235 |  |  |  |  |  |  |  | 
| 236 |  |  |  |  |  |  | =head1 TODO | 
| 237 |  |  |  |  |  |  |  | 
| 238 |  |  |  |  |  |  | The following methods has implemented, but not tested nor documented yet. | 
| 239 |  |  |  |  |  |  |  | 
| 240 |  |  |  |  |  |  | C<Queue.testIamPermissions> | 
| 241 |  |  |  |  |  |  |  | 
| 242 |  |  |  |  |  |  | =head1 LICENSE | 
| 243 |  |  |  |  |  |  |  | 
| 244 |  |  |  |  |  |  | Copyright (C) egawata. | 
| 245 |  |  |  |  |  |  |  | 
| 246 |  |  |  |  |  |  | This library is free software; you can redistribute it and/or modify | 
| 247 |  |  |  |  |  |  | it under the same terms as Perl itself. | 
| 248 |  |  |  |  |  |  |  | 
| 249 |  |  |  |  |  |  | =head1 AUTHOR | 
| 250 |  |  |  |  |  |  |  | 
| 251 |  |  |  |  |  |  | egawata (egawa dot takashi at gmail.com) | 
| 252 |  |  |  |  |  |  |  | 
| 253 |  |  |  |  |  |  | =cut |