line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
17057
|
use 5.014; |
|
2
|
|
|
|
|
7
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package WebService::ForecastIO::Request; |
4
|
|
|
|
|
|
|
$WebService::ForecastIO::Request::VERSION = '0.02'; |
5
|
2
|
|
|
2
|
|
9
|
use Moo::Role; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
11
|
|
6
|
2
|
|
|
2
|
|
2016
|
use HTTP::Tiny; |
|
2
|
|
|
|
|
88990
|
|
|
2
|
|
|
|
|
87
|
|
7
|
2
|
|
|
2
|
|
1554
|
use JSON; |
|
2
|
|
|
|
|
19745
|
|
|
2
|
|
|
|
|
11
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Request role for WebService::ForecaseIO |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'base_url' => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
default => sub { "https://api.darksky.net/forecast" }, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'api_key' => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
required => 1 |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has 'ua' => ( |
24
|
|
|
|
|
|
|
is => 'ro', |
25
|
|
|
|
|
|
|
default => sub { |
26
|
|
|
|
|
|
|
HTTP::Tiny->new( |
27
|
|
|
|
|
|
|
agent => "WebService::ForecastIO/$WebService::ForecastIO::VERSION ", |
28
|
|
|
|
|
|
|
SSL_options => { |
29
|
|
|
|
|
|
|
SSL_hostname => "", |
30
|
|
|
|
|
|
|
SSL_verify_mode => 0 |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
lazy => 1, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has 'decoder' => ( |
39
|
|
|
|
|
|
|
is => 'ro', |
40
|
|
|
|
|
|
|
default => sub { |
41
|
|
|
|
|
|
|
JSON->new(); |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
lazy => 1, |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub request { |
47
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $url = $self->base_url . "/" . $self->api_key . "/" . (join ",", @_); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $qp = join "&", (map {; "$_=" . $self->$_() } |
52
|
0
|
|
|
|
|
|
grep {; defined $self->$_() } qw(exclude units)); |
|
0
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
if ( $qp ) { |
55
|
0
|
|
|
|
|
|
$url .= "?$qp"; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $response = $self->ua->get($url); |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
if ( $response->{success} ) { |
61
|
0
|
|
|
|
|
|
$self->decoder->decode($response->{content}); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
0
|
|
|
|
|
|
die "Request to $url returned $response->{status}: $response->{content}\n"; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |