V4/CompletionClient.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« V4/CompanyServiceClient.pm ↑ Summary V4/EventServiceClient.pm »
1 package Google::Cloud::Talent::V4::CompletionClient;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 0 ▶use Google::gRPC::Client;
Subroutine BEGIN: called CC=1 SCAR=2.6
7 use Google::Cloud::REST::Client;
8 use Google::Auth;
9 use Carp qw(croak);
10  
11 use Protobuf;
12 use Google::Api::Common;
13 use Google::Cloud::Talent::V4::Histogram;
14 use Google::Cloud::Talent::V4::Event;
15 use Google::Cloud::Talent::V4::Common;
16 use Google::Cloud::Talent::V4::Tenant;
17 use Google::Cloud::Talent::V4::EventService;
18 use Google::Cloud::Talent::V4::Company;
19 use Google::Cloud::Talent::V4::CompletionService;
20 use Google::Cloud::Talent::V4::Filters;
21 use Google::Cloud::Talent::V4::Job;
22 use Google::Cloud::Talent::V4::TenantService;
23 use Google::Cloud::Talent::V4::CompanyService;
24 use Google::Cloud::Talent::V4::JobService;
25  
26 our $VERSION = '0.06';
27  
28 has credentials => ( is => 'ro', required => 0 );
29 has transport => ( is => 'rw' );
30  
31 sub BUILD {
32 my ($self) = @_;
33  
34 my $auth = $self->credentials;
35 if (!defined $auth) {
36 $auth = Google::Auth->default();
37 } elsif (!eval { $auth->can('get_token') }) {
38 croak 'Invalid credentials object: must implement get_token()';
39 }
40 my $token = $auth->get_token();
41  
42 my $target = 'jobs.googleapis.com:443';
43 my $t = $self->transport || 'grpc';
44  
45 if (ref($t) && eval { $t->can('call') }) {
46 # Already a transport object
47 } elsif (lc($t) eq 'rest') {
48 my $client = Google::Cloud::REST::Client->new(
49 target => $target,
50 auth_token => $token,
51 );
52 $self->transport($client);
53 } else {
54 my $client = Google::gRPC::Client->new(
55 target => $target,
56 auth_token => $token,
57 );
58 $self->transport($client);
59 }
60 }
61  
62 sub complete_query {
63 my ($self, %params) = @_;
64  
65 my $request_class = 'Google::Cloud::Talent::V4::CompletionService::CompleteQueryRequest';
66 my $request = eval { $request_class->new(\%params) };
67 my $new_err = $@;
68 if (!$request) {
69 $request = eval { $request_class->new(%params) };
70 $new_err ||= $@;
71 }
72 if (!$request) {
73 croak 'Failed to construct ' . $request_class . ': ' . ($new_err || 'unknown error');
74 }
75  
76 my $response_class = 'Google::Cloud::Talent::V4::CompletionService::CompleteQueryResponse';
77 if (eval { $self->transport->isa('Google::Cloud::REST::Client') }) {
78 return $self->transport->call({
79 http_method => 'POST',
80 path => '/google.cloud.talent.v4.Completion/CompleteQuery',
81 request => $request,
82 response_class => $response_class,
83 });
84 }
85  
86 my $response = $self->transport->call({
87 service => 'google.cloud.talent.v4.Completion',
88 method => 'CompleteQuery',
89 request => $request,
90 response_class => $response_class,
91 });
92  
93 return $response;
94 }
95 1; # End of Google::Cloud::Talent::V4::CompletionClient
96  
97 __END__
« V4/CompanyServiceClient.pm ↑ Summary V4/EventServiceClient.pm »