V2alpha/UserEventServiceClient.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
« V2alpha/ServingConfigServiceClient.pm ↑ Summary
1 package Google::Cloud::Retail::V2alpha::UserEventServiceClient;
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::Retail::V2alpha::Promotion;
14 use Google::Cloud::Retail::V2alpha::PurgeConfig;
15 use Google::Cloud::Retail::V2alpha::MerchantCenterAccountLink;
16 use Google::Cloud::Retail::V2alpha::ExportConfig;
17 use Google::Cloud::Retail::V2alpha::Common;
18 use Google::Cloud::Retail::V2alpha::GenerativeQuestion;
19 use Google::Cloud::Retail::V2alpha::Safety;
20 use Google::Cloud::Retail::V2alpha::MerchantCenterAccountLinkService;
21 use Google::Cloud::Retail::V2alpha::AnalyticsService;
22 use Google::Cloud::Retail::V2alpha::Project;
23 use Google::Cloud::Retail::V2alpha::Model;
24 use Google::Cloud::Retail::V2alpha::Product;
25 use Google::Cloud::Retail::V2alpha::GenerativeQuestionService;
26 use Google::Cloud::Retail::V2alpha::ProjectService;
27 use Google::Cloud::Retail::V2alpha::ModelService;
28 use Google::Cloud::Retail::V2alpha::SearchService;
29 use Google::Cloud::Retail::V2alpha::UserEvent;
30 use Google::Cloud::Retail::V2alpha::Branch;
31 use Google::Cloud::Retail::V2alpha::ConversationalSearchService;
32 use Google::Cloud::Retail::V2alpha::ServingConfig;
33 use Google::Cloud::Retail::V2alpha::Control;
34 use Google::Cloud::Retail::V2alpha::PredictionService;
35 use Google::Cloud::Retail::V2alpha::ImportConfig;
36 use Google::Cloud::Retail::V2alpha::BranchService;
37 use Google::Cloud::Retail::V2alpha::ServingConfigService;
38 use Google::Cloud::Retail::V2alpha::ControlService;
39 use Google::Cloud::Retail::V2alpha::ProductService;
40 use Google::Cloud::Retail::V2alpha::CompletionService;
41 use Google::Cloud::Retail::V2alpha::Catalog;
42 use Google::Cloud::Retail::V2alpha::UserEventService;
43 use Google::Cloud::Retail::V2alpha::CatalogService;
44  
45 our $VERSION = '0.06';
46  
47 has credentials => ( is => 'ro', required => 0 );
48 has transport => ( is => 'rw' );
49  
50 sub BUILD {
51 my ($self) = @_;
52  
53 my $auth = $self->credentials;
54 if (!defined $auth) {
55 $auth = Google::Auth->default();
56 } elsif (!eval { $auth->can('get_token') }) {
57 croak 'Invalid credentials object: must implement get_token()';
58 }
59 my $token = $auth->get_token();
60  
61 my $target = 'retail.googleapis.com:443';
62 my $t = $self->transport || 'grpc';
63  
64 if (ref($t) && eval { $t->can('call') }) {
65 # Already a transport object
66 } elsif (lc($t) eq 'rest') {
67 my $client = Google::Cloud::REST::Client->new(
68 target => $target,
69 auth_token => $token,
70 );
71 $self->transport($client);
72 } else {
73 my $client = Google::gRPC::Client->new(
74 target => $target,
75 auth_token => $token,
76 );
77 $self->transport($client);
78 }
79 }
80  
81 sub write_user_event {
82 my ($self, %params) = @_;
83  
84 my $request_class = 'Google::Cloud::Retail::V2alpha::UserEventService::WriteUserEventRequest';
85 my $request = eval { $request_class->new(\%params) };
86 my $new_err = $@;
87 if (!$request) {
88 $request = eval { $request_class->new(%params) };
89 $new_err ||= $@;
90 }
91 if (!$request) {
92 croak 'Failed to construct ' . $request_class . ': ' . ($new_err || 'unknown error');
93 }
94  
95 my $response_class = 'Google::Cloud::Retail::V2alpha::UserEvent::UserEvent';
96 if (eval { $self->transport->isa('Google::Cloud::REST::Client') }) {
97 return $self->transport->call({
98 http_method => 'POST',
99 path => '/google.cloud.retail.v2alpha.UserEventService/WriteUserEvent',
100 request => $request,
101 response_class => $response_class,
102 });
103 }
104  
105 my $response = $self->transport->call({
106 service => 'google.cloud.retail.v2alpha.UserEventService',
107 method => 'WriteUserEvent',
108 request => $request,
109 response_class => $response_class,
110 });
111  
112 return $response;
113 }
114 1; # End of Google::Cloud::Retail::V2alpha::UserEventServiceClient
115  
116 __END__
« V2alpha/ServingConfigServiceClient.pm ↑ Summary