| 1 | package Google::CloudTasks::Client; | ||||||||||||
| 2 | |||||||||||||
| 3 | 4 | ▶ | use Mouse; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 4 | ▶ | use WWW::Google::Cloud::Auth::ServiceAccount; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 4 | ▶ | use LWP::UserAgent; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 4 | ▶ | use HTTP::Request; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 4 | ▶ | use URI; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 4 | ▶ | use URI::QueryParam; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 4 | ▶ | use JSON::XS; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 4 | our $VERSION = "0.01"; | |||||||||||
| 12 | |||||||||||||
| 13 | 4 | has base_url => ( | |||||||||||
| 14 | is => 'ro', | ||||||||||||
| 15 | isa => 'Str', | ||||||||||||
| 16 | default => 'https://cloudtasks.googleapis.com/', | ||||||||||||
| 17 | ); | ||||||||||||
| 18 | |||||||||||||
| 19 | 4 | has version => ( | |||||||||||
| 20 | is => 'ro', | ||||||||||||
| 21 | isa => 'Str', | ||||||||||||
| 22 | default => 'v2', | ||||||||||||
| 23 | ); | ||||||||||||
| 24 | |||||||||||||
| 25 | 4 | has credentials_path => ( | |||||||||||
| 26 | is => 'ro', | ||||||||||||
| 27 | isa => 'Str' | ||||||||||||
| 28 | ); | ||||||||||||
| 29 | |||||||||||||
| 30 | 4 | has auth => ( | |||||||||||
| 31 | is => 'ro', | ||||||||||||
| 32 | lazy_build => 1, | ||||||||||||
| 33 | ); | ||||||||||||
| 34 | |||||||||||||
| 35 | has ua => ( | ||||||||||||
| 36 | is => 'ro', | ||||||||||||
| 37 | lazy => 1, | ||||||||||||
| 38 | 0 | ▶ | default => sub { LWP::UserAgent->new() }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 39 | 4 | ); | |||||||||||
| 40 | |||||||||||||
| 41 | 4 | has is_debug => ( | |||||||||||
| 42 | is => 'ro', | ||||||||||||
| 43 | isa => 'Bool', | ||||||||||||
| 44 | default => 0, | ||||||||||||
| 45 | ); | ||||||||||||
| 46 | |||||||||||||
| 47 | 4 | ▶ | no Mouse; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 48 | |||||||||||||
| 49 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 50 | |||||||||||||
| 51 | 0 | ▶ | sub _build_auth { | ||||||||||
|
Subroutine
_build_auth: not called CC=2 SCAR=17.9
| |||||||||||||
| 52 | 0 | my ($self) = @_; | |||||||||||
| 53 | |||||||||||||
| 54 | 0 | ▶ | if (!$self->credentials_path) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | 0 | die "attribute 'credentials_path' is required"; | |||||||||||
| 56 | } | ||||||||||||
| 57 | 0 | my $auth = WWW::Google::Cloud::Auth::ServiceAccount->new( | |||||||||||
| 58 | credentials_path => $self->credentials_path, | ||||||||||||
| 59 | ); | ||||||||||||
| 60 | 0 | return $auth; | |||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | 0 | ▶ | sub request { | ||||||||||
|
Subroutine
request: not called CC=4 SCAR=26.9
Pod
undocumented
| |||||||||||||
| 64 | 0 | my ($self, $method, $path, $content) = @_; | |||||||||||
| 65 | |||||||||||||
| 66 | 0 | my $url = $self->base_url . $self->version . '/' . $path; | |||||||||||
| 67 | 0 | my $req = HTTP::Request->new($method, $url); | |||||||||||
| 68 | 0 | $req->header('Content-Type' => 'application/json; charset=utf8'); | |||||||||||
| 69 | 0 | $req->header('Authorization' => 'Bearer ' . $self->auth->get_token); | |||||||||||
| 70 | 0 | ▶ | if ($content) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 71 | 0 | my $encoded_body = encode_json($content); | |||||||||||
| 72 | 0 | $req->header('Content-Length' => length($encoded_body)); | |||||||||||
| 73 | 0 | $req->content($encoded_body); | |||||||||||
| 74 | } | ||||||||||||
| 75 | |||||||||||||
| 76 | 0 | ▶ | if ($self->is_debug) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 77 | 4 | ▶ | use Data::Dumper; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 78 | 0 | print "Request : " . Dumper($req); | |||||||||||
| 79 | } | ||||||||||||
| 80 | |||||||||||||
| 81 | 0 | my $res = $self->ua->request($req); | |||||||||||
| 82 | |||||||||||||
| 83 | 0 | ▶ | if ($res->is_success) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 84 | 0 | return decode_json($res->content); | |||||||||||
| 85 | } | ||||||||||||
| 86 | else { | ||||||||||||
| 87 | 0 | die "Fail: " . $res->content; | |||||||||||
| 88 | } | ||||||||||||
| 89 | } | ||||||||||||
| 90 | |||||||||||||
| 91 | 0 | ▶ | sub request_get { | ||||||||||
|
Subroutine
request_get: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 92 | 0 | my ($self, $path) = @_; | |||||||||||
| 93 | 0 | return $self->request(GET => $path); | |||||||||||
| 94 | } | ||||||||||||
| 95 | |||||||||||||
| 96 | 0 | ▶ | sub request_post { | ||||||||||
|
Subroutine
request_post: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 97 | 0 | my ($self, $path, $content) = @_; | |||||||||||
| 98 | 0 | ▶ | $content //= {}; | ||||||||||
|
Condition0%0/2
$content //= {}
MC/DC0%0/1
$content //= {}
$content
Truth table0%0/2
A
A= $content
| |||||||||||||
| 99 | 0 | return $self->request(POST => $path, $content); | |||||||||||
| 100 | } | ||||||||||||
| 101 | |||||||||||||
| 102 | 0 | ▶ | sub request_delete { | ||||||||||
|
Subroutine
request_delete: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 103 | 0 | my ($self, $path) = @_; | |||||||||||
| 104 | 0 | return $self->request(DELETE => $path); | |||||||||||
| 105 | } | ||||||||||||
| 106 | |||||||||||||
| 107 | 0 | ▶ | sub request_patch { | ||||||||||
|
Subroutine
request_patch: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 108 | 0 | my ($self, $path, $content) = @_; | |||||||||||
| 109 | 0 | return $self->request(PATCH => $path, $content); | |||||||||||
| 110 | } | ||||||||||||
| 111 | |||||||||||||
| 112 | 0 | ▶ | sub _make_query_param { | ||||||||||
|
Subroutine
_make_query_param: not called CC=4 SCAR=30.0
| |||||||||||||
| 113 | 0 | my ($args, @keys) = @_; | |||||||||||
| 114 | |||||||||||||
| 115 | 0 | my $u = URI->new(); | |||||||||||
| 116 | 0 | for (@keys) { | |||||||||||
| 117 | 0 | ▶ | if (defined $args->{$_}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 118 | 0 | $u->query_param($_ => $args->{$_}); | |||||||||||
| 119 | } | ||||||||||||
| 120 | } | ||||||||||||
| 121 | |||||||||||||
| 122 | 0 | ▶ | return $u->query ? '?' . $u->query : ''; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 123 | } | ||||||||||||
| 124 | |||||||||||||
| 125 | 0 | ▶ | sub get_location { | ||||||||||
|
Subroutine
get_location: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 126 | 0 | my ($self, $name) = @_; | |||||||||||
| 127 | 0 | my $path = $name; | |||||||||||
| 128 | |||||||||||||
| 129 | 0 | return $self->request_get($path); | |||||||||||
| 130 | } | ||||||||||||
| 131 | |||||||||||||
| 132 | 0 | ▶ | sub list_locations { | ||||||||||
|
Subroutine
list_locations: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 133 | 0 | my ($self, $name, $opts) = @_; | |||||||||||
| 134 | 0 | my $path = $name . '/locations'; | |||||||||||
| 135 | 0 | $path .= _make_query_param($opts, qw/filter pageSize pageToken/); | |||||||||||
| 136 | |||||||||||||
| 137 | 0 | return $self->request_get($path); | |||||||||||
| 138 | } | ||||||||||||
| 139 | |||||||||||||
| 140 | 0 | ▶ | sub create_queue { | ||||||||||
|
Subroutine
create_queue: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 141 | 0 | my ($self, $parent, $queue) = @_; | |||||||||||
| 142 | 0 | my $path = $parent . '/queues'; | |||||||||||
| 143 | |||||||||||||
| 144 | 0 | return $self->request_post($path, $queue); | |||||||||||
| 145 | } | ||||||||||||
| 146 | |||||||||||||
| 147 | 0 | ▶ | sub delete_queue { | ||||||||||
|
Subroutine
delete_queue: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 148 | 0 | my ($self, $name) = @_; | |||||||||||
| 149 | 0 | my $path = $name; | |||||||||||
| 150 | |||||||||||||
| 151 | 0 | return $self->request_delete($path); | |||||||||||
| 152 | } | ||||||||||||
| 153 | |||||||||||||
| 154 | 0 | ▶ | sub get_iam_policy_queue { | ||||||||||
|
Subroutine
get_iam_policy_queue: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 155 | 0 | my ($self, $resource) = @_; | |||||||||||
| 156 | 0 | my $path = $resource . ':getIamPolicy'; | |||||||||||
| 157 | |||||||||||||
| 158 | 0 | return $self->request_post($path); | |||||||||||
| 159 | } | ||||||||||||
| 160 | |||||||||||||
| 161 | 0 | ▶ | sub set_iam_policy_queue { | ||||||||||
|
Subroutine
set_iam_policy_queue: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 162 | 0 | my ($self, $resource, $policy) = @_; | |||||||||||
| 163 | 0 | my $path = $resource . ':setIamPolicy'; | |||||||||||
| 164 | |||||||||||||
| 165 | 0 | return $self->request_post($path, { policy => $policy }); | |||||||||||
| 166 | } | ||||||||||||
| 167 | |||||||||||||
| 168 | 0 | ▶ | sub list_queues { | ||||||||||
|
Subroutine
list_queues: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 169 | 0 | my ($self, $parent, $opts) = @_; | |||||||||||
| 170 | 0 | my $path = $parent . '/queues'; | |||||||||||
| 171 | 0 | $path .= _make_query_param($opts, qw/filter pageSize pageToken/); | |||||||||||
| 172 | |||||||||||||
| 173 | 0 | return $self->request_get($path); | |||||||||||
| 174 | } | ||||||||||||
| 175 | |||||||||||||
| 176 | 0 | ▶ | sub get_queue { | ||||||||||
|
Subroutine
get_queue: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 177 | 0 | my ($self, $name) = @_; | |||||||||||
| 178 | 0 | my $path = $name; | |||||||||||
| 179 | |||||||||||||
| 180 | 0 | return $self->request_get($path); | |||||||||||
| 181 | } | ||||||||||||
| 182 | |||||||||||||
| 183 | 0 | ▶ | sub patch_queue { | ||||||||||
|
Subroutine
patch_queue: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 184 | 0 | my ($self, $name, $queue, $opts) = @_; | |||||||||||
| 185 | 0 | my $path = $name; | |||||||||||
| 186 | 0 | $path .= _make_query_param($opts, qw/updateMask/); | |||||||||||
| 187 | |||||||||||||
| 188 | 0 | return $self->request_patch($path, $queue); | |||||||||||
| 189 | } | ||||||||||||
| 190 | |||||||||||||
| 191 | 0 | ▶ | sub pause_queue { | ||||||||||
|
Subroutine
pause_queue: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 192 | 0 | my ($self, $name) = @_; | |||||||||||
| 193 | 0 | my $path = $name . ':pause'; | |||||||||||
| 194 | 0 | return $self->request_post($path); | |||||||||||
| 195 | } | ||||||||||||
| 196 | |||||||||||||
| 197 | 0 | ▶ | sub purge_queue { | ||||||||||
|
Subroutine
purge_queue: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 198 | 0 | my ($self, $name) = @_; | |||||||||||
| 199 | 0 | my $path = $name . ':purge'; | |||||||||||
| 200 | 0 | return $self->request_post($path); | |||||||||||
| 201 | } | ||||||||||||
| 202 | |||||||||||||
| 203 | 0 | ▶ | sub resume_queue { | ||||||||||
|
Subroutine
resume_queue: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 204 | 0 | my ($self, $name) = @_; | |||||||||||
| 205 | 0 | my $path = $name . ':resume'; | |||||||||||
| 206 | 0 | return $self->request_post($path); | |||||||||||
| 207 | } | ||||||||||||
| 208 | |||||||||||||
| 209 | 0 | ▶ | sub test_iam_permissions { | ||||||||||
|
Subroutine
test_iam_permissions: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 210 | 0 | my ($self, $resource, $permissions) = @_; | |||||||||||
| 211 | 0 | my $path = $resource . ':testIamPermissions'; | |||||||||||
| 212 | 0 | return $self->request_post($path, { permissions => $permissions }); | |||||||||||
| 213 | } | ||||||||||||
| 214 | |||||||||||||
| 215 | 0 | ▶ | sub create_task { | ||||||||||
|
Subroutine
create_task: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 216 | 0 | my ($self, $parent, $task, $opts) = @_; | |||||||||||
| 217 | 0 | my $path = $parent . '/tasks'; | |||||||||||
| 218 | |||||||||||||
| 219 | 0 | my %param = ( | |||||||||||
| 220 | task => $task, | ||||||||||||
| 221 | ); | ||||||||||||
| 222 | 0 | ▶ | defined $opts->{responseView} and $param{responseView} = $opts->{responseView}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 223 | |||||||||||||
| 224 | 0 | return $self->request_post($path, \%param); | |||||||||||
| 225 | } | ||||||||||||
| 226 | |||||||||||||
| 227 | 0 | ▶ | sub delete_task { | ||||||||||
|
Subroutine
delete_task: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 228 | 0 | my ($self, $name) = @_; | |||||||||||
| 229 | 0 | my $path = $name; | |||||||||||
| 230 | |||||||||||||
| 231 | 0 | return $self->request_delete($path); | |||||||||||
| 232 | } | ||||||||||||
| 233 | |||||||||||||
| 234 | 0 | ▶ | sub get_task { | ||||||||||
|
Subroutine
get_task: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 235 | 0 | my ($self, $name, $opts) = @_; | |||||||||||
| 236 | 0 | my $path = $name; | |||||||||||
| 237 | |||||||||||||
| 238 | 0 | $path .= _make_query_param($opts, qw/responseView/); | |||||||||||
| 239 | |||||||||||||
| 240 | 0 | return $self->request_get($path); | |||||||||||
| 241 | } | ||||||||||||
| 242 | |||||||||||||
| 243 | 0 | ▶ | sub list_tasks { | ||||||||||
|
Subroutine
list_tasks: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 244 | 0 | my ($self, $parent, $opts) = @_; | |||||||||||
| 245 | 0 | my $path = $parent . '/tasks'; | |||||||||||
| 246 | |||||||||||||
| 247 | 0 | $path .= _make_query_param($opts, qw/responseView pageSize pageToken/); | |||||||||||
| 248 | |||||||||||||
| 249 | 0 | return $self->request_get($path); | |||||||||||
| 250 | } | ||||||||||||
| 251 | |||||||||||||
| 252 | 0 | ▶ | sub run_task { | ||||||||||
|
Subroutine
run_task: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 253 | 0 | my ($self, $name, $opts) = @_; | |||||||||||
| 254 | 0 | my $path = $name . ':run'; | |||||||||||
| 255 | |||||||||||||
| 256 | 0 | my %param = (); | |||||||||||
| 257 | 0 | ▶ | defined $opts->{responseView} and $param{responseView} = $opts->{responseView}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 258 | |||||||||||||
| 259 | 0 | return $self->request_post($path, \%param); | |||||||||||
| 260 | } | ||||||||||||
| 261 | |||||||||||||
| 262 | 4 | 1; | |||||||||||