line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Decibel; |
2
|
1
|
|
|
1
|
|
1240
|
use JSON::XS; |
|
1
|
|
|
|
|
4148
|
|
|
1
|
|
|
|
|
60
|
|
3
|
1
|
|
|
1
|
|
400
|
use Cache::LRU; |
|
1
|
|
|
|
|
476
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
503
|
use Net::DNS::Lite; |
|
1
|
|
|
|
|
11585
|
|
|
1
|
|
|
|
|
53
|
|
5
|
1
|
|
|
1
|
|
503
|
use Furl; |
|
1
|
|
|
|
|
21069
|
|
|
1
|
|
|
|
|
42
|
|
6
|
1
|
|
|
1
|
|
829
|
use URI; |
|
1
|
|
|
|
|
5431
|
|
|
1
|
|
|
|
|
45
|
|
7
|
1
|
|
|
1
|
|
694
|
use URI::QueryParam; |
|
1
|
|
|
|
|
526
|
|
|
1
|
|
|
|
|
23
|
|
8
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
65
|
|
9
|
1
|
|
|
1
|
|
493
|
use Moo; |
|
1
|
|
|
|
|
11632
|
|
|
1
|
|
|
|
|
6
|
|
10
|
1
|
|
|
1
|
|
1660
|
use namespace::clean; |
|
1
|
|
|
|
|
9456
|
|
|
1
|
|
|
|
|
5
|
|
11
|
|
|
|
|
|
|
our $VERSION = "0.03"; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$Net::DNS::Lite::CACHE = Cache::LRU->new( size => 512 ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has 'app_id' => ( |
17
|
|
|
|
|
|
|
is => 'rw', |
18
|
|
|
|
|
|
|
isa => sub { $_[0] }, |
19
|
|
|
|
|
|
|
required => 1, |
20
|
|
|
|
|
|
|
default => sub { $ENV{DECIBEL_APPLICATION_ID} }, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has 'app_key' => ( |
24
|
|
|
|
|
|
|
is => 'rw', |
25
|
|
|
|
|
|
|
isa => sub { $_[0] }, |
26
|
|
|
|
|
|
|
required => 1, |
27
|
|
|
|
|
|
|
default => sub { $ENV{DECIBEL_APPLICATION_KEY} }, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $build_http = sub { |
31
|
|
|
|
|
|
|
my $self = shift; |
32
|
|
|
|
|
|
|
my $http = Furl::HTTP->new( |
33
|
|
|
|
|
|
|
inet_aton => \&Net::DNS::Lite::inet_aton, |
34
|
|
|
|
|
|
|
agent => 'WebService::Decibel/' . $VERSION, |
35
|
|
|
|
|
|
|
headers => [ |
36
|
|
|
|
|
|
|
'Accept-Encoding' => 'gzip', |
37
|
|
|
|
|
|
|
'DecibelAppID' => $self->app_id, |
38
|
|
|
|
|
|
|
'DecibelAppKey' => $self->app_key, |
39
|
|
|
|
|
|
|
'DecibelTimestamp' => '20140903 17:22:33', |
40
|
|
|
|
|
|
|
], |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
return $http; |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has 'http' => ( |
46
|
|
|
|
|
|
|
is => 'lazy', |
47
|
|
|
|
|
|
|
required => 1, |
48
|
|
|
|
|
|
|
default => $build_http, |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my @methods = qw( album albums artist artists disctags image recording recordings ); |
52
|
|
|
|
|
|
|
for my $method (@methods) { |
53
|
|
|
|
|
|
|
my $code = sub { |
54
|
0
|
|
|
0
|
|
|
my ($self, %query_param) = @_; |
55
|
0
|
|
|
|
|
|
return $self->request($method, \%query_param); |
56
|
|
|
|
|
|
|
}; |
57
|
1
|
|
|
1
|
|
461
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
174
|
|
58
|
|
|
|
|
|
|
*{$method} = $code; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub request { |
63
|
0
|
|
|
0
|
0
|
|
my ( $self, $path, $query_param ) = @_; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $query = URI->new; |
66
|
0
|
|
|
|
|
|
map { $query->query_param( $_, $query_param->{$_} ) } keys %$query_param; |
|
0
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my ($minor_version, $status_code, $message, $headers, $content) = |
69
|
|
|
|
|
|
|
$self->http->request( |
70
|
|
|
|
|
|
|
scheme => 'http', |
71
|
|
|
|
|
|
|
host => 'rest.decibel.net', |
72
|
|
|
|
|
|
|
path_query => "v2/$path$query", |
73
|
|
|
|
|
|
|
method => 'GET', |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
if ( $content !~ /^\{/) { |
77
|
0
|
|
|
|
|
|
confess $content; |
78
|
|
|
|
|
|
|
} else { |
79
|
0
|
|
|
|
|
|
return decode_json( $content ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
__END__ |