line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
4
|
|
|
4
|
|
1147
|
use OpenGbg::Standard::Imports; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.1301'; # VERSION |
4
|
|
|
|
|
|
|
# PODNAME: OpenGbg::Handler |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
class OpenGbg::Handler |
7
|
|
|
|
|
|
|
using Moose { |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Config::Any; |
10
|
|
|
|
|
|
|
use File::HomeDir; |
11
|
|
|
|
|
|
|
use HTTP::Tiny; |
12
|
|
|
|
|
|
|
use Path::Tiny; |
13
|
|
|
|
|
|
|
use OpenGbg::Service::AirQuality; |
14
|
|
|
|
|
|
|
use OpenGbg::Service::Bridge; |
15
|
|
|
|
|
|
|
use OpenGbg::Service::StyrOchStall; |
16
|
|
|
|
|
|
|
use OpenGbg::Service::TrafficCamera; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has config_file => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
isa => AbsFile, |
21
|
|
|
|
|
|
|
lazy => 1, |
22
|
|
|
|
|
|
|
builder => 1, |
23
|
|
|
|
|
|
|
init_arg => undef, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
has config => ( |
26
|
|
|
|
|
|
|
is => 'ro', |
27
|
|
|
|
|
|
|
isa => HashRef, |
28
|
|
|
|
|
|
|
lazy => 1, |
29
|
|
|
|
|
|
|
builder => 1, |
30
|
|
|
|
|
|
|
init_arg => undef, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
has key => ( |
33
|
|
|
|
|
|
|
is => 'ro', |
34
|
|
|
|
|
|
|
isa => Str, |
35
|
|
|
|
|
|
|
lazy => 1, |
36
|
|
|
|
|
|
|
builder => 1, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
has ua => ( |
39
|
|
|
|
|
|
|
is => 'ro', |
40
|
|
|
|
|
|
|
builder => 1, |
41
|
|
|
|
|
|
|
handles => ['get'], |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
has base => ( |
44
|
|
|
|
|
|
|
is => 'ro', |
45
|
|
|
|
|
|
|
isa => Str, |
46
|
|
|
|
|
|
|
default => 'http://data.goteborg.se/', |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my @services = qw/ |
50
|
|
|
|
|
|
|
air_quality |
51
|
|
|
|
|
|
|
bridge |
52
|
|
|
|
|
|
|
styr_och_stall |
53
|
|
|
|
|
|
|
traffic_camera |
54
|
|
|
|
|
|
|
/; |
55
|
|
|
|
|
|
|
foreach my $service (@services) { |
56
|
|
|
|
|
|
|
has $service => ( |
57
|
|
|
|
|
|
|
is => 'ro', |
58
|
|
|
|
|
|
|
lazy => 1, |
59
|
|
|
|
|
|
|
builder => 1, |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
method _build_config_file { |
64
|
|
|
|
|
|
|
my $home = File::HomeDir->my_home; |
65
|
|
|
|
|
|
|
my $conf_file = path($home)->child('.opengbg.ini'); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
method _build_config { |
68
|
|
|
|
|
|
|
my $cfg = Config::Any->load_files({ |
69
|
|
|
|
|
|
|
use_ext => 1, |
70
|
|
|
|
|
|
|
files => [ $self->config_file ], |
71
|
|
|
|
|
|
|
}); |
72
|
|
|
|
|
|
|
my $entry = shift @{ $cfg }; |
73
|
|
|
|
|
|
|
my($filename, $config) = %{ $entry }; |
74
|
|
|
|
|
|
|
return $config; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
method _build_key { |
77
|
|
|
|
|
|
|
return $self->config->{'API'}{'key'}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
method _build_ua { |
80
|
|
|
|
|
|
|
return HTTP::Tiny->new(agent => 'OpenGbg-Browser'); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
method _build_air_quality { |
84
|
|
|
|
|
|
|
return OpenGbg::Service::AirQuality->new(handler => $self); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
method _build_bridge { |
87
|
|
|
|
|
|
|
return OpenGbg::Service::Bridge->new(handler => $self); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
method _build_styr_och_stall { |
90
|
|
|
|
|
|
|
return OpenGbg::Service::StyrOchStall->new(handler => $self); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
method _build_traffic_camera { |
93
|
|
|
|
|
|
|
return OpenGbg::Service::TrafficCamera->new(handler => $self); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=pod |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=encoding utf-8 |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 NAME |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
OpenGbg::Handler |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 VERSION |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Version 0.1301, released 2015-01-16. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 SYNOPSIS |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# $handler is a OpenGbg::Handler object |
114
|
|
|
|
|
|
|
my $handler = OpenGbg->new(key => 'secret-api-key'); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
$response = $handler->styr_och_stall->get_bike_stations; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 DESCRIPTION |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
OpenGbg::Handler is the class from where calls to all web services are made. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 METHOD |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 air_quality() |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Returns a L<OpenGbg::Service::AirQuality> object. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 bridge() |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Returns a L<OpenGbg::Service::Bridge> object. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 styr_och_stall() |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Returns a L<OpenGbg::Service::StyrOchStall> object. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 SOURCE |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
L<https://github.com/Csson/p5-OpenGbg> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 HOMEPAGE |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L<https://metacpan.org/release/OpenGbg> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 AUTHOR |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Erik Carlsson <info@code301.com> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Erik Carlsson. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
153
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |