line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Bandcamp; |
2
|
1
|
|
|
1
|
|
5343
|
use JSON::XS; |
|
1
|
|
|
|
|
11831
|
|
|
1
|
|
|
|
|
83
|
|
3
|
1
|
|
|
1
|
|
861
|
use Cache::LRU; |
|
1
|
|
|
|
|
681
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
846
|
use Net::DNS::Lite; |
|
1
|
|
|
|
|
33211
|
|
|
1
|
|
|
|
|
68
|
|
5
|
1
|
|
|
1
|
|
502
|
use Furl; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use URI; |
7
|
|
|
|
|
|
|
use URI::QueryParam; |
8
|
|
|
|
|
|
|
use Carp; |
9
|
|
|
|
|
|
|
use Moo; |
10
|
|
|
|
|
|
|
use namespace::clean; |
11
|
|
|
|
|
|
|
our $VERSION = "0.04"; |
12
|
|
|
|
|
|
|
use Data::Dumper; |
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{BANDCAMP_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::Bandcamp' . $VERSION, |
30
|
|
|
|
|
|
|
headers => [ 'Accept-Encoding' => 'gzip',], |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
$http->env_proxy; |
33
|
|
|
|
|
|
|
return $http; |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub band_search { |
39
|
|
|
|
|
|
|
my ($self, %query_param) = @_; |
40
|
|
|
|
|
|
|
return $self->_make_request('api/band/3/search', \%query_param); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub band_discography { |
44
|
|
|
|
|
|
|
my ($self, %query_param) = @_; |
45
|
|
|
|
|
|
|
return $self->_make_request('api/band/3/discography', \%query_param); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub band_info { |
49
|
|
|
|
|
|
|
my ($self, %query_param) = @_; |
50
|
|
|
|
|
|
|
return $self->_make_request('api/band/3/info', \%query_param); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub album_info { |
54
|
|
|
|
|
|
|
my ($self, %query_param) = @_; |
55
|
|
|
|
|
|
|
return $self->_make_request('api/album/2/info', \%query_param); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub track_info { |
59
|
|
|
|
|
|
|
my ($self, %query_param) = @_; |
60
|
|
|
|
|
|
|
return $self->_make_request('api/track/3/info', \%query_param); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub url_info { |
64
|
|
|
|
|
|
|
my ($self, %query_param) = @_; |
65
|
|
|
|
|
|
|
return $self->_make_request('api/url/1/info', \%query_param); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _make_request { |
69
|
|
|
|
|
|
|
my ( $self, $path, $query_param ) = @_; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $query = URI->new; |
72
|
|
|
|
|
|
|
$query->query_param( 'key', $self->api_key ); |
73
|
|
|
|
|
|
|
map { $query->query_param( $_, $query_param->{$_} ) } keys %$query_param; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my ($minor_version, $code, $message, $headers, $content) = |
76
|
|
|
|
|
|
|
$self->http->request( |
77
|
|
|
|
|
|
|
scheme => 'http', |
78
|
|
|
|
|
|
|
host => 'api.bandcamp.com', |
79
|
|
|
|
|
|
|
path_query => "$path$query", |
80
|
|
|
|
|
|
|
method => 'GET', |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $data = decode_json( $content ); |
84
|
|
|
|
|
|
|
warn Dumper $data; |
85
|
|
|
|
|
|
|
if ( defined $data->{error} ) { |
86
|
|
|
|
|
|
|
my $code = $data->{error}; |
87
|
|
|
|
|
|
|
my $message = $data->{message}; |
88
|
|
|
|
|
|
|
confess "$code: $message"; |
89
|
|
|
|
|
|
|
} else { |
90
|
|
|
|
|
|
|
return $data; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
__END__ |