Skip to content

Commit b6e9fd8

Browse files
committed
version bump 0.11 and greater test coverage
1 parent e3947a7 commit b6e9fd8

File tree

10 files changed

+199
-103
lines changed

10 files changed

+199
-103
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.DS_Store
2-
/WebService-GoogleAPI-Client-0.1*
2+
/WebService-GoogleAPI-Client-*
33
/CODE_REVIEW.MD
44
/blib/
55
/.build/

CONTRIBUTING.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@
2222
- The structure under the AuthStorage is ugly and needs some love
2323

2424

25-
Github Repo: [https://github.com/pscott-au/WebService-GoogleAPI-Client]
25+
Github Repo: [https://github.com/pscott-au/WebService-GoogleAPI-Client]
26+
27+
## A few notes
28+
`dzil cover -outputdir docs/cover/`

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![Build Status](https://travis-ci.org/pscott-au/WebService-GoogleAPI-Client.svg?branch=master)](https://travis-ci.org/pscott-au//WebService-GoogleAPI-Client)
22
[![Coverage Status](https://coveralls.io/repos/github/pscott-au/WebService-GoogleAPI-Client/badge.svg?branch=master)](https://coveralls.io/github/pscott-au/WebService-GoogleAPI-Client?branch=master)
3-
[![CPAN Version](https://img.shields.io/cpan/v/WebService-GoogleAPI-Client.svg)](http://search.cpan.org/~localshop//WebService-GoogleAPI-Client/lib/WebService/GoogleAPI/Client.pm)
3+
[![CPAN Version](https://img.shields.io/cpan/v/WebService-GoogleAPI-Client.svg)](http://search.cpan.org/~localshop/WebService-GoogleAPI-Client/lib/WebService/GoogleAPI/Client.pm)
44

55

66
![Perl Google APIs Client Library](https://pscott-au.github.io/WebService-Google-Client/perl-google-apis-client-library.png)
@@ -211,13 +211,6 @@ sudo dzil install
211211

212212
- UNDER REVIEW
213213

214-
# CONTRIBUTING AS A DEVELOPER
215-
216-
- Aspiring to [Trunk Based Developent](https://paulhammant.com/2013/04/05/what-is-trunk-based-development/)
217-
- Use perlcritic nad perltidy if my bracer style is offensive
218-
- This is my first module using dzilla to package a module - I'm not completely sold on it and may be using it incorrectly - advice on improving usage welcome
219-
220-
221214

222215
# SEE ALSO
223216

README.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ NAME
44

55
VERSION
66

7-
version 0.10
7+
version 0.11
88

99
SYNOPSIS
1010

@@ -27,6 +27,11 @@ SYNOPSIS
2727

2828
TODO
2929

30+
BUILD
31+
32+
WebService::GoogleAPI::Client->new( user => '[email protected]',
33+
gapi_json => '/fullpath/gapi.json' );
34+
3035
api_query
3136

3237
query Google API with option to validate request before submitting
@@ -115,6 +120,9 @@ SYNOPSIS
115120
Discovery Resource that is either fetched or cached in CHI locally for
116121
30 days.
117122

123+
WHen called in a scalar context returns the list as a comma joined
124+
string.
125+
118126
DELEGATED FROM WebService::GoogleAPI::Client::Discovery
119127

120128
FUNCTIONAL CLASS PROPERTIES
@@ -180,7 +188,8 @@ SEE ALSO
180188
https:
181189

182190
* Moo::Google - The original code base later forked into
183-
WebService::Google::Client by Steve Dondley.
191+
WebService::Google::Client by Steve Dondley. Some shadows of the
192+
original design remain
184193

185194
* "/github.com/APIs-guru/google-discovery-to-swagger" in Google
186195
Swagger API https:

dist.ini

Lines changed: 8 additions & 7 deletions
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.10
6+
version = 0.11
77
main_module = lib/WebService/GoogleAPI/Client.pm
88

99
[PruneCruft]
@@ -52,12 +52,13 @@ copy = README.txt
5252
[MetaJSON]
5353

5454

55-
;[GitHub::Meta]
56-
;issues = 1
57-
;user = pscott-au
58-
;repository = https://github.com/pscott-au/WebService-GoogleAPI-Client
59-
;require_auth = 1
60-
; uncomment when doing a major release - don't want to hit every build
55+
;[GitHub::Meta]
56+
;issues = 1
57+
;user = pscott-au
58+
;repository = https://github.com/pscott-au/WebService-GoogleAPI-Client
59+
;require_auth = 1
60+
; uncomment when doing a major release - don't want to hit every build
61+
6162
[GitHub::Meta]
6263
repository = https://github.com/pscott-au/WebService-GoogleAPI-Client
6364

examples/usage_basic_examples.pl

100644100755
Lines changed: 100 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use warnings;
77
use File::Temp qw/ tempfile tempdir /;
88
use File::Which;
9-
9+
use feature 'say';
1010

1111

1212
## assumes gapi.json configuration in working directory with scoped project and user authorization
@@ -31,77 +31,115 @@
3131

3232
}
3333

34+
if ( 0 )
35+
{
36+
my $text_to_speech_request_options = {
37+
'input' => {
38+
'text' => 'Using the Web-Services-Google-Client Perl module, it is now a simple matter to access all of the Google API Resources in a consistent manner. Nice work Peter!'
39+
},
40+
'voice' => {
41+
'languageCode' => 'en-gb',
42+
'name' => 'en-GB-Standard-A',
43+
'ssmlGender' => 'FEMALE'
44+
},
45+
'audioConfig' => {
46+
'audioEncoding'=> 'MP3'
47+
}
48+
};
49+
50+
## Using this API requires authorised https://www.googleapis.com/auth/cloud-platform scope
51+
52+
if ( 0 ) ## use a full manually constructed non validating standard user agent query builder approach ( includes auto O-Auth token handling )
53+
{
54+
$r = $gapi_client->api_query(
55+
method => 'POST',
56+
path => 'https://texttospeech.googleapis.com/v1/text:synthesize',
57+
options => $text_to_speech_request_options
58+
) ;
3459

35-
my $text_to_speech_request_options = {
36-
'input' => {
37-
'text' => 'Using the Web-Services-Google-Client Perl module, it is now a simple matter to access all of the Google API Resources in a consistent manner. Nice work Peter!'
38-
},
39-
'voice' => {
40-
'languageCode' => 'en-gb',
41-
'name' => 'en-GB-Standard-A',
42-
'ssmlGender' => 'FEMALE'
43-
},
44-
'audioConfig' => {
45-
'audioEncoding'=> 'MP3'
46-
}
47-
};
60+
}
61+
else ## use the api end-point id and take full advantage of pre-submission validation etc
62+
{
63+
$r = $gapi_client->api_query(
64+
api_endpoint_id => 'texttospeech.text.synthesize',
65+
# method => 'POST', ## not required as determined from API SPEC
66+
# path => 'https://texttospeech.googleapis.com/v1/text:synthesize', ## not required as determined from API SPEC
67+
options => $text_to_speech_request_options
68+
) ;
69+
## NB - this approach will also autofill any defaults that aren't defined
70+
## confirm that the user has the required scope before submitting to Google.
71+
## confirms that all required fields are populated
72+
## where an error is detected - result is a 418 code ( I'm a teapot ) with the body containing the error descriptions
4873

49-
## Using this API requires authorised https://www.googleapis.com/auth/cloud-platform scope
74+
}
5075

51-
if ( 0 ) ## use a full manually constructed non validating standard user agent query builder approach ( includes auto O-Auth token handling )
52-
{
53-
$r = $gapi_client->api_query(
54-
method => 'POST',
55-
path => 'https://texttospeech.googleapis.com/v1/text:synthesize',
56-
options => $text_to_speech_request_options
57-
) ;
76+
if ( $r->is_success ) ## $r is a standard Mojo::Message::Response instance
77+
{
78+
my $returned_data = $r->json; ## convert from json to native hashref - result is a hashref with a key 'audioContent' containing synthesized audio in base64-encoded MP3 format
79+
my $decoded_mp3 = decode_base64( $returned_data->{audioContent} );
5880

59-
}
60-
else ## use the api end-point id and take full advantage of pre-submission validation etc
61-
{
62-
$r = $gapi_client->api_query(
63-
api_endpoint_id => 'texttospeech.text.synthesize',
64-
# method => 'POST', ## not required as determined from API SPEC
65-
# path => 'https://texttospeech.googleapis.com/v1/text:synthesize', ## not required as determined from API SPEC
66-
options => $text_to_speech_request_options
67-
) ;
68-
## NB - this approach will also autofill any defaults that aren't defined
69-
## confirm that the user has the required scope before submitting to Google.
70-
## confirms that all required fields are populated
71-
## where an error is detected - result is a 418 code ( I'm a teapot ) with the body containing the error descriptions
81+
my $tmp = File::Temp->new( UNLINK => 0, SUFFIX => '.mp3' ); ## should prolly unlink=1 if not planning to use output file in future
82+
print $tmp $decoded_mp3;
83+
84+
if ( which('ffplay') )
85+
{
86+
print "ffplay -nodisp -autoexit $tmp\n";
87+
`ffplay -nodisp -autoexit $tmp`;
88+
89+
}
90+
close($tmp);
7291

92+
}
93+
else
94+
{
95+
if ( $r->code eq '418' )
96+
{
97+
print qq{Cool - I'm a teapot - this was caught ebfore sending the request through to Google \n};
98+
print $r->body;
99+
}
100+
else ## other error - should appear in warnings but can inspect $r for more detail
101+
{
102+
print Dumper $r;
103+
}
104+
105+
}
73106
}
74107

75-
if ( $r->is_success ) ## $r is a standard Mojo::Message::Response instance
76-
{
77-
my $returned_data = $r->json; ## convert from json to native hashref - result is a hashref with a key 'audioContent' containing synthesized audio in base64-encoded MP3 format
78-
my $decoded_mp3 = decode_base64( $returned_data->{audioContent} );
79-
80-
my $tmp = File::Temp->new( UNLINK => 0, SUFFIX => '.mp3' ); ## should prolly unlink=1 if not planning to use output file in future
81-
print $tmp $decoded_mp3;
82-
83-
if ( which('ffplay') )
84-
{
85-
print "ffplay -nodisp -autoexit $tmp\n";
86-
`ffplay -nodisp -autoexit $tmp`;
87-
88-
}
89-
close($tmp);
90108

109+
## edge cases to inform improvement to test coverage
110+
111+
my $x = WebService::GoogleAPI::Client->new();
112+
say " WebService::GoogleAPI::Client->new() is a " . ref( $x );
113+
#exit;
114+
#my $y = $x->api_query();
115+
#say Dumper $y;
116+
say "WebService::GoogleAPI::Client->new->api_query() is a " . ref( WebService::GoogleAPI::Client->new->api_query() ); # eq 'Mojo::Message::Response';
117+
118+
say "WebService::GoogleAPI::Client->new->has_scope_to_access_api_endpoint()" . WebService::GoogleAPI::Client->new->has_scope_to_access_api_endpoint();
119+
use WebService::GoogleAPI::Client::Discovery;
120+
121+
#say my $x = WebService::GoogleAPI::Client::Discovery->new->list_of_available_google_api_ids();
122+
say 'fnarly' if ref ( WebService::GoogleAPI::Client::Discovery->new->discover_all() ) eq 'HASH';
123+
#exit;
124+
if ( WebService::GoogleAPI::Client::Discovery->new->augment_discover_all_with_unlisted_experimental_api() )
125+
{
126+
#say Dumper [ WebService::GoogleAPI::Client::Discovery->new->augment_discover_all_with_unlisted_experimental_api() ];
91127
}
92-
else
128+
else
93129
{
94-
if ( $r->code eq '418' )
95-
{
96-
print qq{Cool - I'm a teapot - this was caught ebfore sending the request through to Google \n};
97-
print $r->body;
98-
}
99-
else ## other error - should appear in warnings but can inspect $r for more detail
100-
{
101-
print Dumper $r;
102-
}
103-
130+
#say Dumper WebService::GoogleAPI::Client::Discovery->new->augment_discover_all_with_unlisted_experimental_api();
104131
}
105132

133+
say length( WebService::GoogleAPI::Client::Discovery->new->supported_as_text ) > 100 ;
134+
#say Dumper $x;
135+
136+
say WebService::GoogleAPI::Client::Discovery->new->api_verson_urls;
137+
exit;
138+
my $f = WebService::GoogleAPI::Client::AuthStorage->new;#->get_credentials_for_refresh();
139+
print Dumper $f;
140+
my $dd = $f->get_credentials_for_refresh();
141+
106142

107-
#
143+
#say WebService::GoogleAPI::Client::Discovery->new->augment_discover_all_with_unlisted_experimental_api();
144+
#say join(',', WebService::GoogleAPI::Client->new->list_of_available_google_api_ids() ) . ' as list';
145+
#say WebService::GoogleAPI::Client->new->list_of_available_google_api_ids() . ' as scalar';

0 commit comments

Comments
 (0)