line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Coderwall; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Simple Perl interface to the coderwall API |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
52679
|
use WWW::Coderwall::User; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
76
|
|
6
|
2
|
|
|
2
|
|
4087
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
141474
|
|
|
2
|
|
|
|
|
75
|
|
7
|
2
|
|
|
2
|
|
2977
|
use Data::Printer; |
|
2
|
|
|
|
|
335394
|
|
|
2
|
|
|
|
|
20
|
|
8
|
2
|
|
|
2
|
|
2857
|
use JSON; |
|
2
|
|
|
|
|
36548
|
|
|
2
|
|
|
|
|
14
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
355
|
use Moo; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
37
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = "0.003"; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub get_user { |
17
|
0
|
|
|
0
|
1
|
|
my ( $self, $username ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $uri = "http://coderwall.com/$username.json"; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
my %user_data = %{$self->_call_api($uri)}; |
|
0
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
return WWW::Coderwall::User->new( |
24
|
|
|
|
|
|
|
username => $user_data{'username'}, |
25
|
|
|
|
|
|
|
name => $user_data{'name'}, |
26
|
|
|
|
|
|
|
location => $user_data{'location'}, |
27
|
|
|
|
|
|
|
team => $user_data{'team'}, |
28
|
|
|
|
|
|
|
accounts => $user_data{'accounts'}, |
29
|
|
|
|
|
|
|
badges => $user_data{'badges'}, |
30
|
|
|
|
|
|
|
endorsements => $user_data{'endorsements'}, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has http_agent => ( |
36
|
|
|
|
|
|
|
is => 'ro', |
37
|
|
|
|
|
|
|
lazy => 1, |
38
|
|
|
|
|
|
|
default => sub { |
39
|
|
|
|
|
|
|
my $self = shift; |
40
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
41
|
|
|
|
|
|
|
$ua->agent($self->http_agent_name); |
42
|
|
|
|
|
|
|
return $ua; |
43
|
|
|
|
|
|
|
}, |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has http_agent_name => ( |
48
|
|
|
|
|
|
|
is => 'ro', |
49
|
|
|
|
|
|
|
lazy => 1, |
50
|
|
|
|
|
|
|
default => sub { __PACKAGE__.'/'.$VERSION }, |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _call_api { |
55
|
0
|
|
|
0
|
|
|
my ( $self, $uri ) = @_; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $response = $self->http_agent->get($uri); |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if ( $response->is_success ) { |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $json = JSON->new->allow_nonref; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return $json->decode( $response->decoded_content ); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
die __PACKAGE__.' API request failed: ' . $response->status_line. "\n"; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |