blib/lib/Map/Tube/Server.pm

filter: Statementstmt 54.9% 28 / 51 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 58.3% 7 / 12 Podpod n/a totaltotal 49.3% 35 / 71 SCAR 21.5
CC
5
Cov
47%
__ANON__
6.0
__ANON__
6.0
__ANON__
6.0
CRAP 8.6
↑ Summary
1 package Map::Tube::Server;
2  
3 1 $Map::Tube::Server::VERSION = '0.01';
4 1 $Map::Tube::Server::AUTHORITY = 'cpan:MANWAR';
5  
6 =head1 NAME
7  
8 Map::Tube::Server - Dancer2 based server for Map::Tube.
9  
10 =head1 VERSION
11  
12 Version 0.01
13  
14 =cut
15  
16 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use Dancer2;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Dancer2::Plugin::Res;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Dancer2::Plugin::Map::Tube;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 =head1 DESCRIPTION
25  
26 Dancer2 based framework to build the Map::Tube public facing REST API. Currently
27 it is being used by manwar.org to provide the service as REST API.It's still very
28 much beta version v1.
29  
30 =head1 SUPPORTED MAPS
31  
32 The supported maps are defined in L<Dancer2::Plugin::Map::Tube>.
33  
34 =head1 UNSUPPORTED MAPS
35  
36 The following maps do not have complete map data yet.
37  
38 =over 2
39  
40 =item Map::Tube::NYC
41  
42 =item Map::Tube::Tokyo
43  
44 =back
45  
46 =head1 ERROR MESSAGES
47  
48 =over 2
49  
50 =item REACHED REQUEST LIMIT
51  
52 =item MISSING MAP NAME
53  
54 =item RECEIVED INVALID MAP NAME
55  
56 =item RECEIVED UNSUPPORTED MAP NAME
57  
58 =item MISSING START STATION NAME
59  
60 =item RECEIVED INVALID START STATION NAME
61  
62 =item MISSING END STATION NAME
63  
64 =item RECEIVED INVALID END STATION NAME
65  
66 =item MISSING LINE NAME
67  
68 =item RECEIVED INVALID LINE NAME
69  
70 =item MAP NOT INSTALLED
71  
72 =back
73  
74 =cut
75  
76 hook before => sub {
77 0 ▶ header 'Content-Type' => 'application/json';
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 1 };
79  
80 =head1 ROUTES
81  
82 =head2 GET /map-tube/v1/shortest-route/:map/:start/:end
83  
84 Return the shortest route from C<$start> to C<$end> in the C<$map>.
85  
86 Returns ref to an array of shortest route stations list in JSON format.
87  
88 For example:
89  
90 curl http://manwar.mooo.info/map-tube/v1/shortest-route/london/baker%20street/wembley%20park
91  
92 =cut
93  
94 get '/shortest-route/:map/:start/:end' => sub {
95 0 ▶ my $client = request->address;
Subroutine __ANON__: not called CC=2 SCAR=17.9
96 0 my $name = route_parameters->get('map');
97 0 my $start = route_parameters->get('start');
98 0 my $end = route_parameters->get('end');
99 0 my $response = api($name)->shortest_route($client, $start, $end);
100  
101 return res($response->{error_code} => $response->{error_message})
102 0 ▶ if (exists $response->{error_code});
Branch: 1 branch
BranchTrueFalseTotal
if exists $response->{"error_code"} 0 0 0
103  
104 0 return $response->{content};
105 1 };
106  
107 =head2 GET /map-tube/v1/stations/:map/:line
108  
109 Returns ref to an array of stations list in JSON format for the given C<map> and
110 C<line>. The C<map> can be any of the supported maps. And the C<line> can be any
111 of lines within the C<map>.For more details, please look into the relevant module
112 for the map C<Map::Tube::*>.
113  
114 curl http://manwar.mooo.info/map-tube/v1/stations/london/metropolitan
115  
116 =cut
117  
118 get '/stations/:map/:line' => sub {
119 0 ▶ my $client = request->address;
Subroutine __ANON__: not called CC=2 SCAR=17.9
120 0 my $name = route_parameters->get('map');
121 0 my $line = route_parameters->get('line');
122  
123 0 my $response = api($name)->line_stations($client, $line);
124  
125 return res($response->{error_code} => $response->{error_message})
126 0 ▶ if (exists $response->{error_code});
Branch: 1 branch
BranchTrueFalseTotal
if exists $response->{"error_code"} 0 0 0
127  
128 0 return $response->{content};
129 1 };
130  
131 =head2 GET /map-tube/v1/stations/:map
132  
133 Returns ref to an array of stations list in JSON format for the given C<map>.
134  
135 curl http://manwar.mooo.info/map-tube/v1/stations/london
136  
137 =cut
138  
139 get '/stations/:map' => sub {
140 0 ▶ my $client = request->address;
Subroutine __ANON__: not called CC=2 SCAR=17.9
141 0 my $name = route_parameters->get('map');
142 0 my $response = api($name)->map_stations($client);
143  
144 return res($response->{error_code} => $response->{error_message})
145 0 ▶ if (exists $response->{error_code});
Branch: 1 branch
BranchTrueFalseTotal
if exists $response->{"error_code"} 0 0 0
146  
147 0 return $response->{content};
148 1 };
149  
150 =head2 GET /map-tube/v1/maps
151  
152 Returns ref to an array of supported maps.
153  
154 curl http://manwar.mooo.info/map-tube/v1/maps
155  
156 =cut
157  
158 get '/maps' => sub {
159 0 ▶ my $client = request->address;
Subroutine __ANON__: not called CC=2 SCAR=17.9
160 0 my $response = api->available_maps($client);
161  
162 return res($response->{error_code} => $response->{error_message})
163 0 ▶ if (exists $response->{error_code});
Branch: 1 branch
BranchTrueFalseTotal
if exists $response->{"error_code"} 0 0 0
164  
165 0 return $response->{content};
166 1 };
167  
168 =head1 AUTHOR
169  
170 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
171  
172 =head1 REPOSITORY
173  
174 L<https://github.com/manwar/Map-Tube-Server>
175  
176 =head1 BUGS
177  
178 Please report any bugs or feature requests to C<bug-map-tube-server at rt.cpan.org>,
179 or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Map-Tube-Server>.
180 I will be notified and then you'll automatically be notified of progress on your
181 bug as I make changes.
182  
183 =head1 SUPPORT
184  
185 You can find documentation for this module with the perldoc command.
186  
187 perldoc Map::Tube::Server
188  
189 You can also look for information at:
190  
191 =over 4
192  
193 =item * RT: CPAN's request tracker (report bugs here)
194  
195 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Map-Tube-Server>
196  
197 =item * AnnoCPAN: Annotated CPAN documentation
198  
199 L<http://annocpan.org/dist/Map-Tube-Server>
200  
201 =item * CPAN Ratings
202  
203 L<http://cpanratings.perl.org/d/Map-Tube-Server>
204  
205 =item * Search CPAN
206  
207 L<http://search.cpan.org/dist/Map-Tube-Server/>
208  
209 =back
210  
211 =head1 LICENSE AND COPYRIGHT
212  
213 Copyright (C) 2018 Mohammad S Anwar.
214  
215 This program is free software; you can redistribute it and / or modify it under
216 the terms of the the Artistic License (2.0). You may obtain a copy of the full
217 license at:
218  
219 L<http://www.perlfoundation.org/artistic_license_2_0>
220  
221 Any use, modification, and distribution of the Standard or Modified Versions is
222 governed by this Artistic License.By using, modifying or distributing the Package,
223 you accept this license. Do not use, modify, or distribute the Package, if you do
224 not accept this license.
225  
226 If your Modified Version has been derived from a Modified Version made by someone
227 other than you,you are nevertheless required to ensure that your Modified Version
228 complies with the requirements of this license.
229  
230 This license does not grant you the right to use any trademark, service mark,
231 tradename, or logo of the Copyright Holder.
232  
233 This license includes the non-exclusive, worldwide, free-of-charge patent license
234 to make, have made, use, offer to sell, sell, import and otherwise transfer the
235 Package with respect to any patent claims licensable by the Copyright Holder that
236 are necessarily infringed by the Package. If you institute patent litigation
237 (including a cross-claim or counterclaim) against any party alleging that the
238 Package constitutes direct or contributory patent infringement,then this Artistic
239 License to you shall terminate on the date that such litigation is filed.
240  
241 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
242 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
243 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
244 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
245 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
246 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
247 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
248  
249 =cut
250  
251 1 1; # End of Map::Tube::Server
↑ Summary