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