Skip to content

Commit 44f4339

Browse files
committed
CPANEL RELEASE V0.21
Includes refactored api_query including the ulimate inclusion of parameters specified with location='query' to be added as GET params. Performed an audit of existing endpoints to cofirm that can always assume ok to append the '?'. The other hackable options remain available but default behavious is now working thanks to @rabbiveesh
1 parent 5cb1eb7 commit 44f4339

File tree

5 files changed

+32
-15
lines changed

5 files changed

+32
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ WebService::GoogleAPI::Client - Perl Google API Services OAUTH Client.
1515

1616
# VERSION
1717

18-
version 0.20.1
18+
version 0.21
1919

2020
# SYNOPSIS
2121

README.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ NAME
44

55
VERSION
66

7-
version 0.20.1
7+
version 0.21
88

99
SYNOPSIS
1010

@@ -125,6 +125,13 @@ METHODS
125125
if the pre-query validation fails then a 418 - I'm a Teapot error response is returned with the
126126
body containing the specific description of the errors ( Tea Leaves ;^) ).
127127

128+
NB: If you pass a 'path' parameter this takes precendence over the API
129+
Discovery Spec. Any parameters defined in the path of the format
130+
{VARNAME} will be filled in with values within the options=>{ VARNAME
131+
=> 'value '} parameter structure. This is the simplest way of
132+
addressing issues where the API discovery spec is inaccurate. ( See
133+
dev_sheets_example.pl as at 14/11/18 for illustration )
134+
128135
To allow the user to fix discrepencies in the Discovery Specification
129136
the cb_method_discovery_modify callback can be used which must accept
130137
the method specification as a parameter and must return a (potentially

dist.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ author = Peter Scott <[email protected]>
33
license = Apache_2_0
44
copyright_holder = Peter Scott and others
55
copyright_year = 2017-2018
6-
version = 0.20.1
6+
version = 0.21
77
main_module = lib/WebService/GoogleAPI/Client.pm
88

99
;[MinimumPerl]

examples/dev_sheets_example.pl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,20 @@ =head2 LIST ALL SHEETS
184184
range => $config->{sheet_update_range},
185185
majorDimension => 'ROWS',
186186
'values' => [[99],[98]],
187-
#responseValueRenderOption => 'FORMATTED_VALUE',
187+
responseValueRenderOption => 'FORMATTED_VALUE',
188+
includeValuesInResponse => 'true'
188189

189190
} ;
190191

191192
my $r = $gapi_client->api_query( api_endpoint_id => "$versioned_api.spreadsheets.values.update",
192-
path => 'v4/spreadsheets/{spreadsheetId}/values/{range}?valueInputOption={valueInputOption}&responseValueRenderOption=FORMATTED_VALUE',
193+
#path => 'v4/spreadsheets/{spreadsheetId}/values/{range}?valueInputOption={valueInputOption}&responseValueRenderOption=FORMATTED_VALUE',
193194
options => $options,
194-
# cb_method_discovery_modify => sub {
195-
# my $meth_spec = shift;
196-
# $meth_spec->{parameters}{valueInputOption}{location} = 'path';
197-
# $meth_spec->{path} = "v4/spreadsheets/{spreadsheetId}/values/{range}?valueInputOption={valueInputOption}";
198-
# return $meth_spec;
199-
# }
195+
# cb_method_discovery_modify => sub {
196+
# my $meth_spec = shift;
197+
# $meth_spec->{parameters}{valueInputOption}{location} = 'path';
198+
# $meth_spec->{path} = "v4/spreadsheets/{spreadsheetId}/values/{range}?valueInputOption={valueInputOption}";
199+
# return $meth_spec;
200+
# }
200201
);
201202
print dd $r->json; # ->json;
202203
############################################################################

lib/WebService/GoogleAPI/Client.pm

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ sub _process_params_for_api_endpoint_and_return_errors
311311
$params->{ path } = $method_discovery_struct->{ path } unless $params->{ path }; ## Set default path iff not set by user - NB - will prepend baseUrl later
312312
push @teapot_errors, 'path is a required parameter' unless $params->{ path };
313313

314-
push @teapot_errors, $self->_interpolate_path_parameters_and_return_errors( $params, $method_discovery_struct );
314+
push @teapot_errors, $self->_interpolate_path_parameters_append_query_params_and_return_errors( $params, $method_discovery_struct );
315315

316316
$params->{ path } =~ s/^\///sxmg; ## remove leading '/' from path
317317
$params->{ path } = "$api_discovery_struct->{baseUrl}/$params->{path}" unless $params->{ path } =~ /^$api_discovery_struct->{baseUrl}/ixsmg; ## prepend baseUrl if required
@@ -325,12 +325,12 @@ sub _process_params_for_api_endpoint_and_return_errors
325325

326326

327327
##################################################
328-
sub _interpolate_path_parameters_and_return_errors
328+
sub _interpolate_path_parameters_append_query_params_and_return_errors
329329
{
330330
my ( $self, $params, $method_discovery_struct ) = @_;
331331
my @teapot_errors = ();
332332

333-
333+
my @get_query_params = ();
334334
my %path_params = map { $_ => 1 } ($params->{path} =~ /\{\+*([^\}]+)\}/xg); ## the params embedded in the path as indexes of hash
335335

336336
foreach my $meth_param_spec ( uniq(keys %path_params ,keys %{ $method_discovery_struct->{ parameters } } ) )
@@ -367,11 +367,20 @@ sub _interpolate_path_parameters_and_return_errors
367367
}
368368
}
369369
}
370-
elsif ( ( !defined $params->{ options }{ $meth_param_spec } ) && ( $method_discovery_struct->{ parameters }{ $meth_param_spec }{ 'location' } eq 'query' )) ## check post form variables .. assume not get?
370+
elsif ( ( defined $params->{ options }{ $meth_param_spec } ) && ( $method_discovery_struct->{ parameters }{ $meth_param_spec }{ 'location' } eq 'query' )) ## check post form variables .. assume not get?
371371
{
372372
$params->{ options }{ $meth_param_spec } = $method_discovery_struct->{ parameters }{ $meth_param_spec }{ default } if ( defined $method_discovery_struct->{ parameters }{ $meth_param_spec }{ default } );
373+
push( @get_query_params, "$meth_param_spec=$params->{options}{$meth_param_spec}" ) if defined $params->{ options }{ $meth_param_spec };
374+
delete $params->{ options }{ $meth_param_spec };
373375
}
374376
}
377+
if ( scalar(@get_query_params)>0 )
378+
{
379+
#$params->{path} .= '/' unless $params->{path} =~ /\/$/mx;
380+
$params->{path} .= '?' . join('&', @get_query_params );
381+
}
382+
#print pp $params;
383+
#exit;
375384
return @teapot_errors;
376385
}
377386
##################################################

0 commit comments

Comments
 (0)