line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Untappd::API; |
2
|
1
|
|
|
1
|
|
46799
|
use Moo; |
|
1
|
|
|
|
|
73346
|
|
|
1
|
|
|
|
|
7
|
|
3
|
1
|
|
|
1
|
|
2563
|
use Hijk; |
|
1
|
|
|
|
|
18158
|
|
|
1
|
|
|
|
|
473
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = 0.01; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has 'client_id', is => 'ro', required => 1; |
8
|
|
|
|
|
|
|
has 'client_secret', is => 'ro', required => 1; |
9
|
|
|
|
|
|
|
has 'endpoint', is => 'rwp', default => 'http://api.untappd.com/v4'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub _auth_params { |
12
|
2
|
|
|
2
|
|
4282
|
my ($self) = @_; |
13
|
2
|
|
|
|
|
15
|
return '&client_id=' . $self->client_id |
14
|
|
|
|
|
|
|
. '&client_secret=' . $self->client_secret; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub beer_info { |
18
|
0
|
|
|
0
|
0
|
|
my ($self, $bid) = @_; |
19
|
0
|
|
|
|
|
|
return $self->_request("/beer/info/$bid"); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub beer_search_by_name { |
23
|
0
|
|
|
0
|
0
|
|
my ( $self, $beer_name ) = @_; |
24
|
0
|
0
|
|
|
|
|
return if !defined $beer_name; |
25
|
0
|
|
|
|
|
|
return $self->_beer_search( $beer_name, "name" ); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub beer_search_by_count { |
29
|
0
|
|
|
0
|
0
|
|
my ( $self, $beer_name ) = @_; |
30
|
0
|
0
|
|
|
|
|
return if !defined $beer_name; |
31
|
0
|
|
|
|
|
|
return $self->_beer_search( $beer_name, "count" ); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _beer_search { |
35
|
0
|
|
|
0
|
|
|
my ( $self, $beer_name, $method ) = @_; |
36
|
0
|
|
|
|
|
|
return $self->_request("/search/$beer_name" . "q=$method"); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _request { |
40
|
0
|
|
|
0
|
|
|
my ( $self, $path ) = @_; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $res = Hijk::request({ |
43
|
|
|
|
|
|
|
method => "GET", |
44
|
|
|
|
|
|
|
host => $self->endpoint, |
45
|
|
|
|
|
|
|
port => "80", |
46
|
|
|
|
|
|
|
path => $path . $self->_auth_params, |
47
|
|
|
|
|
|
|
query_string => "color=red" |
48
|
|
|
|
|
|
|
}); |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
0
|
|
|
|
return if ( exists $res->{error} && $res->{error} == "200" ); |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
return $res; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
__END__ |