| 1 | package Google::Cloud::Pubsublite::V1::PublisherServiceClient; | ||
| 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::Pubsublite::V1::Common; | ||
| 14 | use Google::Cloud::Pubsublite::V1::TopicStats; | ||
| 15 | use Google::Cloud::Pubsublite::V1::Publisher; | ||
| 16 | use Google::Cloud::Pubsublite::V1::Cursor; | ||
| 17 | use Google::Cloud::Pubsublite::V1::Subscriber; | ||
| 18 | use Google::Cloud::Pubsublite::V1::Admin; | ||
| 19 | |||
| 20 | our $VERSION = '0.06'; | ||
| 21 | |||
| 22 | has credentials => ( is => 'ro', required => 0 ); | ||
| 23 | has transport => ( is => 'rw' ); | ||
| 24 | |||
| 25 | sub BUILD { | ||
| 26 | my ($self) = @_; | ||
| 27 | |||
| 28 | my $auth = $self->credentials; | ||
| 29 | if (!defined $auth) { | ||
| 30 | $auth = Google::Auth->default(); | ||
| 31 | } elsif (!eval { $auth->can('get_token') }) { | ||
| 32 | croak 'Invalid credentials object: must implement get_token()'; | ||
| 33 | } | ||
| 34 | my $token = $auth->get_token(); | ||
| 35 | |||
| 36 | my $target = 'pubsublite.googleapis.com:443'; | ||
| 37 | my $t = $self->transport || 'grpc'; | ||
| 38 | |||
| 39 | if (ref($t) && eval { $t->can('call') }) { | ||
| 40 | # Already a transport object | ||
| 41 | } elsif (lc($t) eq 'rest') { | ||
| 42 | my $client = Google::Cloud::REST::Client->new( | ||
| 43 | target => $target, | ||
| 44 | auth_token => $token, | ||
| 45 | ); | ||
| 46 | $self->transport($client); | ||
| 47 | } else { | ||
| 48 | my $client = Google::gRPC::Client->new( | ||
| 49 | target => $target, | ||
| 50 | auth_token => $token, | ||
| 51 | ); | ||
| 52 | $self->transport($client); | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | sub publish { | ||
| 57 | my ($self, %params) = @_; | ||
| 58 | |||
| 59 | my $request_class = 'Google::Cloud::Pubsublite::V1::Publisher::PublishRequest'; | ||
| 60 | my $request = eval { $request_class->new(\%params) }; | ||
| 61 | my $new_err = $@; | ||
| 62 | if (!$request) { | ||
| 63 | $request = eval { $request_class->new(%params) }; | ||
| 64 | $new_err ||= $@; | ||
| 65 | } | ||
| 66 | if (!$request) { | ||
| 67 | croak 'Failed to construct ' . $request_class . ': ' . ($new_err || 'unknown error'); | ||
| 68 | } | ||
| 69 | |||
| 70 | my $response_class = 'Google::Cloud::Pubsublite::V1::Publisher::PublishResponse'; | ||
| 71 | if (eval { $self->transport->isa('Google::Cloud::REST::Client') }) { | ||
| 72 | return $self->transport->call({ | ||
| 73 | http_method => 'POST', | ||
| 74 | path => '/google.cloud.pubsublite.v1.PublisherService/Publish', | ||
| 75 | request => $request, | ||
| 76 | response_class => $response_class, | ||
| 77 | }); | ||
| 78 | } | ||
| 79 | |||
| 80 | my $response = $self->transport->call({ | ||
| 81 | service => 'google.cloud.pubsublite.v1.PublisherService', | ||
| 82 | method => 'Publish', | ||
| 83 | request => $request, | ||
| 84 | response_class => $response_class, | ||
| 85 | }); | ||
| 86 | |||
| 87 | return $response; | ||
| 88 | } | ||
| 89 | 1; # End of Google::Cloud::Pubsublite::V1::PublisherServiceClient | ||
| 90 | |||
| 91 | __END__ | ||