| 1 | package Google::Cloud::Talent::V4beta1::TenantServiceClient; | ||
| 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::V4beta1::Batch; | ||
| 14 | use Google::Cloud::Talent::V4beta1::Histogram; | ||
| 15 | use Google::Cloud::Talent::V4beta1::Event; | ||
| 16 | use Google::Cloud::Talent::V4beta1::Tenant; | ||
| 17 | use Google::Cloud::Talent::V4beta1::Common; | ||
| 18 | use Google::Cloud::Talent::V4beta1::EventService; | ||
| 19 | use Google::Cloud::Talent::V4beta1::CompletionService; | ||
| 20 | use Google::Cloud::Talent::V4beta1::Job; | ||
| 21 | use Google::Cloud::Talent::V4beta1::Filters; | ||
| 22 | use Google::Cloud::Talent::V4beta1::TenantService; | ||
| 23 | use Google::Cloud::Talent::V4beta1::Company; | ||
| 24 | use Google::Cloud::Talent::V4beta1::JobService; | ||
| 25 | use Google::Cloud::Talent::V4beta1::CompanyService; | ||
| 26 | |||
| 27 | our $VERSION = '0.06'; | ||
| 28 | |||
| 29 | has credentials => ( is => 'ro', required => 0 ); | ||
| 30 | has transport => ( is => 'rw' ); | ||
| 31 | |||
| 32 | sub BUILD { | ||
| 33 | my ($self) = @_; | ||
| 34 | |||
| 35 | my $auth = $self->credentials; | ||
| 36 | if (!defined $auth) { | ||
| 37 | $auth = Google::Auth->default(); | ||
| 38 | } elsif (!eval { $auth->can('get_token') }) { | ||
| 39 | croak 'Invalid credentials object: must implement get_token()'; | ||
| 40 | } | ||
| 41 | my $token = $auth->get_token(); | ||
| 42 | |||
| 43 | my $target = 'jobs.googleapis.com:443'; | ||
| 44 | my $t = $self->transport || 'grpc'; | ||
| 45 | |||
| 46 | if (ref($t) && eval { $t->can('call') }) { | ||
| 47 | # Already a transport object | ||
| 48 | } elsif (lc($t) eq 'rest') { | ||
| 49 | my $client = Google::Cloud::REST::Client->new( | ||
| 50 | target => $target, | ||
| 51 | auth_token => $token, | ||
| 52 | ); | ||
| 53 | $self->transport($client); | ||
| 54 | } else { | ||
| 55 | my $client = Google::gRPC::Client->new( | ||
| 56 | target => $target, | ||
| 57 | auth_token => $token, | ||
| 58 | ); | ||
| 59 | $self->transport($client); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | sub create_tenant { | ||
| 64 | my ($self, %params) = @_; | ||
| 65 | |||
| 66 | my $request_class = 'Google::Cloud::Talent::V4beta1::TenantService::CreateTenantRequest'; | ||
| 67 | my $request = eval { $request_class->new(\%params) }; | ||
| 68 | my $new_err = $@; | ||
| 69 | if (!$request) { | ||
| 70 | $request = eval { $request_class->new(%params) }; | ||
| 71 | $new_err ||= $@; | ||
| 72 | } | ||
| 73 | if (!$request) { | ||
| 74 | croak 'Failed to construct ' . $request_class . ': ' . ($new_err || 'unknown error'); | ||
| 75 | } | ||
| 76 | |||
| 77 | my $response_class = 'Google::Cloud::Talent::V4beta1::Tenant::Tenant'; | ||
| 78 | if (eval { $self->transport->isa('Google::Cloud::REST::Client') }) { | ||
| 79 | return $self->transport->call({ | ||
| 80 | http_method => 'POST', | ||
| 81 | path => '/google.cloud.talent.v4beta1.TenantService/CreateTenant', | ||
| 82 | request => $request, | ||
| 83 | response_class => $response_class, | ||
| 84 | }); | ||
| 85 | } | ||
| 86 | |||
| 87 | my $response = $self->transport->call({ | ||
| 88 | service => 'google.cloud.talent.v4beta1.TenantService', | ||
| 89 | method => 'CreateTenant', | ||
| 90 | request => $request, | ||
| 91 | response_class => $response_class, | ||
| 92 | }); | ||
| 93 | |||
| 94 | return $response; | ||
| 95 | } | ||
| 96 | |||
| 97 | sub list_tenants { | ||
| 98 | my ($self, %params) = @_; | ||
| 99 | |||
| 100 | my $request_class = 'Google::Cloud::Talent::V4beta1::TenantService::ListTenantsRequest'; | ||
| 101 | my $request = eval { $request_class->new(\%params) }; | ||
| 102 | my $new_err = $@; | ||
| 103 | if (!$request) { | ||
| 104 | $request = eval { $request_class->new(%params) }; | ||
| 105 | $new_err ||= $@; | ||
| 106 | } | ||
| 107 | if (!$request) { | ||
| 108 | croak 'Failed to construct ' . $request_class . ': ' . ($new_err || 'unknown error'); | ||
| 109 | } | ||
| 110 | |||
| 111 | my $response_class = 'Google::Cloud::Talent::V4beta1::TenantService::ListTenantsResponse'; | ||
| 112 | if (eval { $self->transport->isa('Google::Cloud::REST::Client') }) { | ||
| 113 | return $self->transport->call({ | ||
| 114 | http_method => 'POST', | ||
| 115 | path => '/google.cloud.talent.v4beta1.TenantService/ListTenants', | ||
| 116 | request => $request, | ||
| 117 | response_class => $response_class, | ||
| 118 | }); | ||
| 119 | } | ||
| 120 | |||
| 121 | my $response = $self->transport->call({ | ||
| 122 | service => 'google.cloud.talent.v4beta1.TenantService', | ||
| 123 | method => 'ListTenants', | ||
| 124 | request => $request, | ||
| 125 | response_class => $response_class, | ||
| 126 | }); | ||
| 127 | |||
| 128 | return $response; | ||
| 129 | } | ||
| 130 | 1; # End of Google::Cloud::Talent::V4beta1::TenantServiceClient | ||
| 131 | |||
| 132 | __END__ | ||