line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::GigaTools; |
2
|
1
|
|
|
1
|
|
1234
|
use JSON::XS; |
|
1
|
|
|
|
|
4129
|
|
|
1
|
|
|
|
|
68
|
|
3
|
1
|
|
|
1
|
|
418
|
use Cache::LRU; |
|
1
|
|
|
|
|
480
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
516
|
use Net::DNS::Lite; |
|
1
|
|
|
|
|
15472
|
|
|
1
|
|
|
|
|
65
|
|
5
|
1
|
|
|
1
|
|
598
|
use Furl; |
|
1
|
|
|
|
|
15931
|
|
|
1
|
|
|
|
|
33
|
|
6
|
1
|
|
|
1
|
|
14764
|
use URI; |
|
1
|
|
|
|
|
3965
|
|
|
1
|
|
|
|
|
42
|
|
7
|
1
|
|
|
1
|
|
570
|
use URI::QueryParam; |
|
1
|
|
|
|
|
595
|
|
|
1
|
|
|
|
|
22
|
|
8
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
84
|
|
9
|
1
|
|
|
1
|
|
529
|
use Moo; |
|
1
|
|
|
|
|
11663
|
|
|
1
|
|
|
|
|
6
|
|
10
|
1
|
|
|
1
|
|
1629
|
use namespace::clean; |
|
1
|
|
|
|
|
9476
|
|
|
1
|
|
|
|
|
5
|
|
11
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$Net::DNS::Lite::CACHE = Cache::LRU->new( size => 512 ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has 'api_key' => ( |
17
|
|
|
|
|
|
|
is => 'rw', |
18
|
|
|
|
|
|
|
isa => sub { $_[0] }, |
19
|
|
|
|
|
|
|
required => 1, |
20
|
|
|
|
|
|
|
default => sub { $ENV{GIGATOOLS_API_KEY} }, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has 'http' => ( |
24
|
|
|
|
|
|
|
is => 'rw', |
25
|
|
|
|
|
|
|
required => 1, |
26
|
|
|
|
|
|
|
default => sub { |
27
|
|
|
|
|
|
|
my $http = Furl::HTTP->new( |
28
|
|
|
|
|
|
|
inet_aton => \&Net::DNS::Lite::inet_aton, |
29
|
|
|
|
|
|
|
agent => 'WebService::GigaTools/' . $VERSION, |
30
|
|
|
|
|
|
|
headers => [ 'Accept-Encoding' => 'gzip',], |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
return $http; |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my @methods = ( |
38
|
|
|
|
|
|
|
'gigs', |
39
|
|
|
|
|
|
|
'city', |
40
|
|
|
|
|
|
|
'country', |
41
|
|
|
|
|
|
|
'venue', |
42
|
|
|
|
|
|
|
'search', |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
for my $method (@methods) { |
47
|
|
|
|
|
|
|
my $code = sub { |
48
|
0
|
|
|
0
|
|
|
my ($self, %query_param) = @_; |
49
|
0
|
|
|
|
|
|
return $self->request("$method.json", \%query_param); |
50
|
|
|
|
|
|
|
}; |
51
|
1
|
|
|
1
|
|
444
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
178
|
|
52
|
|
|
|
|
|
|
*{$method} = $code; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub request { |
57
|
0
|
|
|
0
|
0
|
|
my ( $self, $path, $query_param ) = @_; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $query = URI->new; |
60
|
0
|
|
|
|
|
|
$query->query_param( 'api_key', $self->api_key ); |
61
|
0
|
|
|
|
|
|
map { $query->query_param( $_, $query_param->{$_} ) } keys %$query_param; |
|
0
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my ($minor_version, $status_code, $message, $headers, $content) = |
64
|
|
|
|
|
|
|
$self->http->request( |
65
|
|
|
|
|
|
|
scheme => 'http', |
66
|
|
|
|
|
|
|
host => 'api.gigatools.com', |
67
|
|
|
|
|
|
|
path_query => "$path$query", |
68
|
|
|
|
|
|
|
method => 'GET', |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $data = decode_json( $content ); |
72
|
0
|
0
|
|
|
|
|
if ( $status_code != 200 ) { |
73
|
0
|
|
|
|
|
|
confess "Error"; |
74
|
|
|
|
|
|
|
} else { |
75
|
0
|
|
|
|
|
|
return $data; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
__END__ |