File Coverage

blib/lib/WWW/Google/APIDiscovery.pm
Criterion Covered Total %
statement 48 53 90.5
branch 5 6 83.3
condition n/a
subroutine 12 13 92.3
pod 2 4 50.0
total 67 76 88.1


line stmt bran cond sub pod time code
1             package WWW::Google::APIDiscovery;
2              
3             $WWW::Google::APIDiscovery::VERSION = '0.28';
4             $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.28
13              
14             =cut
15              
16 5     5   71269 use 5.006;
  5         41  
17 5     5   3233 use JSON;
  5         62977  
  5         26  
18 5     5   3827 use Data::Dumper;
  5         37893  
  5         2123  
19              
20 5     5   2374 use WWW::Google::UserAgent;
  5         593254  
  5         205  
21 5     5   2680 use WWW::Google::APIDiscovery::API;
  5         29  
  5         196  
22 5     5   2527 use WWW::Google::APIDiscovery::API::MetaData;
  5         24  
  5         173  
23              
24 5     5   39 use Moo;
  5         14  
  5         22  
25 5     5   1669 use namespace::autoclean;
  5         13  
  5         20  
26             extends 'WWW::Google::UserAgent';
27              
28             our $BASE_URL = 'https://www.googleapis.com/discovery/v1/apis';
29              
30             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.
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     2 0 5879 my ($class, $args) = @_;
58              
59 2 100       17 die "ERROR: No parameters required for constructor."
60             if defined $args;
61              
62 1         18 return { api_key => 'Dummy' };
63             };
64              
65             sub BUILD {
66 1     1 0 147 my ($self) = @_;
67              
68 1         3 $self->_supported_apis;
69             }
70              
71             =head1 METHODS
72              
73             =head2 discover()
74              
75             Returns meta data of the API of type L.
76              
77             =cut
78              
79             sub discover {
80 2     2 1 929 my ($self, $api_id) = @_;
81              
82 2 100       21 die "ERROR: Missing mandatory param: api_id" unless defined $api_id;
83              
84 1         5 my $api = $self->{apis}->{$api_id};
85 1 50       12 die "ERROR: Unsupported API [$api_id]" unless defined $api;
86              
87 0         0 my $response = $self->get($api->url);
88 0         0 my $contents = from_json($response->{content});
89              
90 0         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.
96              
97             =cut
98              
99             sub supported_apis {
100 0     0 1 0 my ($self) = @_;
101              
102 0         0 return $self->{apis};
103             }
104              
105             sub _supported_apis {
106 1     1   4 my ($self) = @_;
107              
108 1         6 my $response = $self->get($BASE_URL);
109 1         122959 my $contents = from_json($response->{content});
110              
111 1         1882 $self->kind($contents->{kind});
112 1         6 $self->version($contents->{discoveryVersion});
113 1         4 my $supported_apis = {};
114 1         3 foreach my $item (@{$contents->{items}}) {
  1         6  
115 232         7253 my $id = $item->{id};
116 232         336 my $name = $item->{name};
117 232         343 my $version = $item->{version};
118 232         317 my $title = $item->{title};
119 232         314 my $description = $item->{description};
120 232         325 my $url = $item->{discoveryRestUrl};
121 232         3820 $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         248 $self->apis($supported_apis);
131             }
132              
133             =head1 AUTHOR
134              
135             Mohammad S Anwar, C<< >>
136              
137             =head1 REPOSITORY
138              
139             L
140              
141             =head1 CONTRIBUTORS
142              
143             Gabor Szabo (szabgab)
144              
145             =head1 BUGS
146              
147             Please report any bugs or feature requests to C
148             rt.cpan.org>, or through the web interface at L.
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
165              
166             =item * AnnoCPAN: Annotated CPAN documentation
167              
168             L
169              
170             =item * CPAN Ratings
171              
172             L
173              
174             =item * Search CPAN
175              
176             L
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
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             1; # End of WWW::Google::APIDiscovery