APIDiscovery.pm

filter: Statementstmt 91.5% 54 / 59 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 92.3% 12 / 13 Podpod 50.0% 2 / 4 totaltotal 89.0% 73 / 82 SCAR 16.1
CC
5
Cov
91%
discover
3.4
BUILDARGS
2.0
supported_apis
2.0
CRAP 5.0
↑ Summary APIDiscovery/API.pm »
1 package WWW::Google::APIDiscovery;
2  
3 5 $WWW::Google::APIDiscovery::VERSION = '0.27';
4 5 $WWW::Google::APIDiscovery::AUTHORITY = 'cpan:MANWAR';
5  
6 =head1 NAME
7  
8 WWW::Google::APIDiscovery - Interface to Google API Discovery Service.
9  
10 =head1 VERSION
11  
12 Version 0.27
13  
14 =cut
15  
16 5 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 5 ▶use WWW::Google::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use WWW::Google::APIDiscovery::API;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶use WWW::Google::APIDiscovery::API::MetaData;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 5 extends 'WWW::Google::UserAgent';
27  
28 5 our $BASE_URL = 'https://www.googleapis.com/discovery/v1/apis';
29  
30 5 has [ qw(apis kind version) ] => (is => 'rw');
31  
32 =head1 DESCRIPTION
33  
34 The Google APIs Discovery Service allows you to interact with Google APIs by
35 exposing machine readable metadata about other Google APIs through a simple API.
36 Currently supports version v1.
37  
38 IMPORTANT:The version v1 of the Google APIs Discovery Service is in Labs and its
39 features might change unexpectedly until it graduates.
40  
41 The official Google API document can be found L<here|https://developers.google.com/discovery/v1/getting_started>.
42  
43 =head1 SYNOPSIS
44  
45 use strict; use warnings;
46 use WWW::Google::APIDiscovery;
47  
48 my $google = WWW::Google::APIDiscovery->new;
49 my $apis = $google->supported_apis;
50 my $meta = $google->discover('customsearch:v1');
51  
52 print "Title: ", $meta->title, "\n";
53  
54 =cut
55  
56 sub BUILDARGS {
57 2 ▶ my ($class, $args) = @_;
Subroutine BUILDARGS: called CC=2 SCAR=6.9
Pod undocumented
58  
59 2 ▶ die "ERROR: No parameters required for constructor."
Branch: 1 branch
BranchTrueFalseTotal
if defined $args 1 1 2
60 if defined $args;
61  
62 1 return { api_key => 'Dummy' };
63 };
64  
65 sub BUILD {
66 1 ▶ my ($self) = @_;
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
67  
68 1 $self->_supported_apis;
69 }
70  
71 =head1 METHODS
72  
73 =head2 discover()
74  
75 Returns meta data of the API of type L<WWW::Google::APIDiscovery::API::MetaData>.
76  
77 =cut
78  
79 sub discover {
80 2 ▶ my ($self, $api_id) = @_;
Subroutine discover: called CC=3 SCAR=12.3
Pod documented
81  
82 2 ▶ die "ERROR: Missing mandatory param: api_id" unless defined $api_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $api_id 1 1 2
83  
84 1 my $api = $self->{apis}->{$api_id};
85 1 ▶ die "ERROR: Unsupported API [$api_id]" unless defined $api;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $api 1 0 1
86  
87 0 my $response = $self->get($api->url);
88 0 my $contents = from_json($response->{content});
89  
90 0 return WWW::Google::APIDiscovery::API::MetaData->new($contents);
91 }
92  
93 =head2 supported_apis()
94  
95 Returns the list of supported APIs of type L<WWW::Google::APIDiscovery::API>.
96  
97 =cut
98  
99 sub supported_apis {
100 0 ▶ my ($self) = @_;
Subroutine supported_apis: not called CC=1 SCAR=6.9
Pod documented
101  
102 0 return $self->{apis};
103 }
104  
105 sub _supported_apis {
106 1 ▶ my ($self) = @_;
Subroutine _supported_apis: called CC=2 SCAR=6.9
107  
108 1 my $response = $self->get($BASE_URL);
109 1 my $contents = from_json($response->{content});
110  
111 1 $self->kind($contents->{kind});
112 1 $self->version($contents->{discoveryVersion});
113 1 my $supported_apis = {};
114 1 foreach my $item (@{$contents->{items}}) {
115 523 my $id = $item->{id};
116 523 my $name = $item->{name};
117 523 my $version = $item->{version};
118 523 my $title = $item->{title};
119 523 my $description = $item->{description};
120 523 my $url = $item->{discoveryRestUrl};
121 523 $supported_apis->{$id} = WWW::Google::APIDiscovery::API->new(
122 id => $id,
123 name => $name,
124 version => $version,
125 title => $title,
126 description => $description,
127 url => $url);
128 }
129  
130 1 $self->apis($supported_apis);
131 }
132  
133 =head1 AUTHOR
134  
135 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
136  
137 =head1 REPOSITORY
138  
139 L<https://github.com/manwar/WWW-Google-APIDiscovery>
140  
141 =head1 CONTRIBUTORS
142  
143 Gabor Szabo (szabgab)
144  
145 =head1 BUGS
146  
147 Please report any bugs or feature requests to C<bug-www-google-apidiscovery at
148 rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Google-APIDiscovery>.
149 I will be notified, and then you'll automatically be notified of progress on your
150 bug as I make changes.
151  
152 =head1 SUPPORT
153  
154 You can find documentation for this module with the perldoc command.
155  
156 perldoc WWW::Google::APIDiscovery
157  
158 You can also look for information at:
159  
160 =over 4
161  
162 =item * RT: CPAN's request tracker (report bugs here)
163  
164 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Google-APIDiscovery>
165  
166 =item * AnnoCPAN: Annotated CPAN documentation
167  
168 L<http://annocpan.org/dist/WWW-Google-APIDiscovery>
169  
170 =item * CPAN Ratings
171  
172 L<http://cpanratings.perl.org/d/WWW-Google-APIDiscovery>
173  
174 =item * Search CPAN
175  
176 L<http://search.cpan.org/dist/WWW-Google-APIDiscovery/>
177  
178 =back
179  
180 =head1 LICENSE AND COPYRIGHT
181  
182 Copyright (C) 2011 - 2015 Mohammad S Anwar.
183  
184 This program is free software; you can redistribute it and/or modify it under
185 the terms of the the Artistic License (2.0). You may obtain a copy of the full
186 license at:
187  
188 L<http://www.perlfoundation.org/artistic_license_2_0>
189  
190 Any use, modification, and distribution of the Standard or Modified Versions is
191 governed by this Artistic License.By using, modifying or distributing the Package,
192 you accept this license. Do not use, modify, or distribute the Package, if you do
193 not accept this license.
194  
195 If your Modified Version has been derived from a Modified Version made by someone
196 other than you,you are nevertheless required to ensure that your Modified Version
197 complies with the requirements of this license.
198  
199 This license does not grant you the right to use any trademark, service mark,
200 tradename, or logo of the Copyright Holder.
201  
202 This license includes the non-exclusive, worldwide, free-of-charge patent license
203 to make, have made, use, offer to sell, sell, import and otherwise transfer the
204 Package with respect to any patent claims licensable by the Copyright Holder that
205 are necessarily infringed by the Package. If you institute patent litigation
206 (including a cross-claim or counterclaim) against any party alleging that the
207 Package constitutes direct or contributory patent infringement,then this Artistic
208 License to you shall terminate on the date that such litigation is filed.
209  
210 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
211 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
212 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
213 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
214 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
215 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
216 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
217  
218 =cut
219  
220 5 1; # End of WWW::Google::APIDiscovery
↑ Summary APIDiscovery/API.pm »