OpenGbg.pm

filter: Statementstmt 78.8% 56 / 71 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 65.2% 15 / 23 Podpod n/a totaltotal 75.5% 71 / 94 CC 1 SCAR 3.0
CC
1
Cov
79%
_build_config_file
2.0
_build_config
2.0
_build_key
2.0
CRAP 1.3
« OpenGbg/Service/AirQuality/GetLatestMeasurement.pm ↑ Summary OpenGbg/Service/TrafficCamera/CameraDevices.pm »
1 5 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package OpenGbg;
6  
7 # ABSTRACT: An interface to the Open Data API of Gothenburg
8 5 our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9 5 our $VERSION = '0.1402';
10  
11 5 ▶use OpenGbg::Elk;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 ▶use Config::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use File::HomeDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use Types::Standard qw/HashRef Str/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use Types::Path::Tiny qw/AbsFile/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 5 ▶use OpenGbg::Service::AirQuality;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶use OpenGbg::Service::Bridge;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 ▶use OpenGbg::Service::StyrOchStall;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 ▶use OpenGbg::Service::TrafficCamera;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 5 has config_file => (
27 is => 'ro',
28 isa => AbsFile,
29 lazy => 1,
30 builder => 1,
31 init_arg => undef,
32 );
33 5 has config => (
34 is => 'ro',
35 isa => HashRef,
36 lazy => 1,
37 builder => 1,
38 init_arg => undef,
39 );
40 5 has key => (
41 is => 'ro',
42 isa => Str,
43 lazy => 1,
44 builder => 1,
45 );
46 5 has ua => (
47 is => 'ro',
48 builder => 1,
49 handles => ['get'],
50 );
51 5 has base => (
52 is => 'ro',
53 isa => Str,
54 default => 'http://data.goteborg.se/',
55 );
56  
57 5 my @services = qw/
58 air_quality
59 bridge
60 styr_och_stall
61 traffic_camera
62 /;
63 5 foreach my $service (@services) {
64 20 has $service => (
65 is => 'ro',
66 lazy => 1,
67 builder => 1,
68 );
69 }
70  
71 sub _build_config_file {
72 0 ▶ my $home = File::HomeDir->my_home;
Subroutine _build_config_file: not called CC=1 SCAR=6.9
73 0 my $conf_file = path($home)->child('.opengbg.ini');
74 }
75 sub _build_config {
76 0 ▶ my $self = shift;
Subroutine _build_config: not called CC=1 SCAR=6.9
77  
78 0 my $cfg = Config::Any->load_files({
79 use_ext => 1,
80 files => [ $self->config_file ],
81 });
82 0 my $entry = shift @{ $cfg };
83 0 my($filename, $config) = %{ $entry };
84 0 return $config;
85 }
86 sub _build_key {
87 0 ▶ return shift->config->{'API'}{'key'};
Subroutine _build_key: not called CC=1 SCAR=6.9
88 }
89 sub _build_ua {
90 0 ▶ return HTTP::Tiny->new(agent => 'OpenGbg-Browser');
Subroutine _build_ua: not called CC=1 SCAR=6.9
91 }
92  
93 sub _build_air_quality {
94 0 ▶ return OpenGbg::Service::AirQuality->new(handler => shift);
Subroutine _build_air_quality: not called CC=1 SCAR=6.9
95 }
96 sub _build_bridge {
97 0 ▶ return OpenGbg::Service::Bridge->new(handler => shift);
Subroutine _build_bridge: not called CC=1 SCAR=6.9
98 }
99 sub _build_styr_och_stall {
100 0 ▶ return OpenGbg::Service::StyrOchStall->new(handler => shift);
Subroutine _build_styr_och_stall: not called CC=1 SCAR=6.9
101 }
102 sub _build_traffic_camera {
103 0 ▶ return OpenGbg::Service::TrafficCamera->new(handler => shift);
Subroutine _build_traffic_camera: not called CC=1 SCAR=6.9
104 }
105  
106 5 __PACKAGE__->meta->make_immutable;
107  
108 5 1;
109  
110 __END__
111  
112 =pod
113  
114 =encoding UTF-8
115  
116 =head1 NAME
117  
118 OpenGbg - An interface to the Open Data API of Gothenburg
119  
120  
121  
122 =begin html
123  
124 <p>
125 <img src="https://img.shields.io/badge/perl-5.10+-blue.svg" alt="Requires Perl 5.10+" />
126 <a href="https://travis-ci.org/Csson/p5-OpenGbg"><img src="https://api.travis-ci.org/Csson/p5-OpenGbg.svg?branch=master" alt="Travis status" /></a>
127 <a href="http://cpants.cpanauthors.org/release/CSSON/OpenGbg-0.1402"><img src="http://badgedepot.code301.com/badge/kwalitee/CSSON/OpenGbg/0.1402" alt="Distribution kwalitee" /></a>
128 <a href="http://matrix.cpantesters.org/?dist=OpenGbg%200.1402"><img src="http://badgedepot.code301.com/badge/cpantesters/OpenGbg/0.1402" alt="CPAN Testers result" /></a>
129 <img src="https://img.shields.io/badge/coverage-78.7%-orange.svg" alt="coverage 78.7%" />
130 </p>
131  
132 =end html
133  
134 =head1 VERSION
135  
136 Version 0.1402, released 2016-08-12.
137  
138 =head1 SYNOPSIS
139  
140 use OpenGbg;
141  
142 my $opengbg = OpenGbg->new(key => 'secret-api-key');
143  
144 $stations = $opengbg->styr_och_stall->get_bike_stations;
145  
146 print $stations->get_by_index(0)->to_text;
147  
148 =head1 DESCRIPTION
149  
150 OpenGbg is a way to connect to and use the open data published by the city of L<Gothenburg|https://en.wikipedia.org/wiki/Gothenburg>.
151  
152 The open data homepage is located at L<http://data.goteborg.se/>. All official documentation is in Swedish, but the license agreement is published
153 in English L<here|https://gbgdata.wordpress.com/goopen/>.
154  
155 To use the API you need to sign up for a free api key.
156  
157 =head2 Authenticate
158  
159 Once you have your api key you can use it to authenticate in two different ways:
160  
161 1. You can give it in the constructor:
162  
163 my $opengbg = OpenGbg->new(key => 'secret-api-key');
164  
165 2. You can save it in a file named C<.opengbg.ini> in your homedir:
166  
167 [API]
168 key = secret-api-key
169  
170 =head1 METHODS
171  
172 =head2 new()
173  
174 Takes an optional key-value pair, the key is C<key> and the value your api key, see L<authenticate|/"Authenticate">.
175  
176 my $gbg = OpenGbg->new(key => 'secret-api-key');
177  
178 # or, if the api key is set in C<.opengbg.ini>:
179  
180 my $gbg = OpenGbg->new;
181  
182 =head1 SERVICES
183  
184 The following services are currently implemented in this distribution:
185  
186 L<$gbg-E<gt>air_quality|OpenGbg::Service::AirQuality> - Data on air quality
187  
188 L<$gbg-E<gt>bridge|OpenGbg::Service::Bridge> - Data on the openness of Göta Älvbron
189  
190 L<$gbg-E<gt>styr_och_stall|OpenGbg::Service::StyrOchStall> - Data on rent-a-bike stations
191  
192 L<$gbg-E<gt>traffic_camera|OpenGbg::Service::TrafficCamera> - Data on traffic cameras, and their images
193  
194 =head2 Naming
195  
196 Most names related to the services are de-camelized, while others are lower-cased (no underscores). For example, the service 'GetBikeStations' is called like this:
197  
198 my $gbg = OpenGbg->new;
199 my $stations = $gbg->styr_och_stall->get_bike_stations;
200  
201 All calls to services are prefixed with 'get' even if the service isn't named that way. On the other hand, the 'service' suffix on some services are removed.
202  
203 Date/time intervals are always called C<start> and C<end> (in the web services they are sometimes called 'start' and 'stop').
204  
205 =head1 DISCLAIMER
206  
207 This is not an official distribution.
208  
209 =head1 SOURCE
210  
211 L<https://github.com/Csson/p5-OpenGbg>
212  
213 =head1 HOMEPAGE
214  
215 L<https://metacpan.org/release/OpenGbg>
216  
217 =head1 AUTHOR
218  
219 Erik Carlsson <info@code301.com>
220  
221 =head1 COPYRIGHT AND LICENSE
222  
223 This software is copyright (c) 2016 by Erik Carlsson.
224  
225 This is free software; you can redistribute it and/or modify it under
226 the same terms as the Perl 5 programming language system itself.
227  
228 =cut
« OpenGbg/Service/AirQuality/GetLatestMeasurement.pm ↑ Summary OpenGbg/Service/TrafficCamera/CameraDevices.pm »