line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::OpenAMD; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $AFresh1: OpenAMD.pm,v 1.20 2010/07/17 11:48:28 andrew Exp $ |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
117140
|
use warnings; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
136
|
|
6
|
4
|
|
|
4
|
|
23
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
133
|
|
7
|
4
|
|
|
4
|
|
22
|
use Carp; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
386
|
|
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
3863
|
use version; our $VERSION = qv('0.1.1'); |
|
4
|
|
|
|
|
11987
|
|
|
4
|
|
|
|
|
25
|
|
10
|
|
|
|
|
|
|
my $BASE_URI = 'https://api.hope.net/api/'; |
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
366
|
use Scalar::Util qw( refaddr ); |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
484
|
|
13
|
|
|
|
|
|
|
*_ident = \&refaddr; |
14
|
|
|
|
|
|
|
|
15
|
4
|
|
|
4
|
|
7066
|
use LWP::UserAgent; |
|
4
|
|
|
|
|
266043
|
|
|
4
|
|
|
|
|
148
|
|
16
|
4
|
|
|
4
|
|
49
|
use URI; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
104
|
|
17
|
4
|
|
|
4
|
|
4312
|
use Net::OAuth; |
|
4
|
|
|
|
|
3353
|
|
|
4
|
|
|
|
|
117
|
|
18
|
4
|
|
|
4
|
|
4932
|
use JSON; |
|
4
|
|
|
|
|
60936
|
|
|
4
|
|
|
|
|
26
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
{ |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my @attr_refs = \( |
23
|
|
|
|
|
|
|
my %base_uri_of, |
24
|
|
|
|
|
|
|
my %ua_of, my %auth_of, my %actions_of, |
25
|
|
|
|
|
|
|
my %json_of, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
29
|
0
|
|
|
0
|
1
|
|
my ( $class, $options ) = @_; |
30
|
0
|
|
|
|
|
|
my $self = bless do { \my $x }, $class; |
|
0
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
my $ident = _ident($self); |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
0
|
|
|
|
$options ||= {}; |
34
|
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
croak 'Options should be a hashref' if ref $options ne 'HASH'; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
0
|
|
|
|
$base_uri_of{$ident} = $options->{base_uri} || $BASE_URI; |
38
|
0
|
|
0
|
|
|
|
$ua_of{$ident} = $options->{ua} || LWP::UserAgent->new(); |
39
|
0
|
|
0
|
|
|
|
$json_of{$ident} = $options->{json} || JSON->new(); |
40
|
0
|
|
0
|
|
|
|
$actions_of{$ident} = $options->{actions} |
41
|
|
|
|
|
|
|
|| [qw( location speakers talks interests users )]; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
foreach my $action ( @{ $actions_of{$ident} } ) { |
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
## no critic |
45
|
4
|
|
|
4
|
|
1562
|
no strict 'refs'; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
1453
|
|
46
|
0
|
|
|
0
|
|
|
*{$action} = sub { shift->get( $action, @_ ) }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# XXX Authenticate |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub get { |
55
|
0
|
|
|
0
|
1
|
|
my ( $self, $action, $query ) = @_; |
56
|
0
|
|
|
|
|
|
my $ident = _ident($self); |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $uri = URI->new_abs( $action . '/', $base_uri_of{$ident} ); |
59
|
0
|
|
|
|
|
|
$uri->query_form($query); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $response = $ua_of{$ident}->get($uri); |
62
|
0
|
0
|
|
|
|
|
croak $response->status_line if !$response->is_success; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $data; |
65
|
0
|
|
|
|
|
|
eval { |
66
|
0
|
|
|
|
|
|
$data = $json_of{$ident}->decode( $response->decoded_content ); |
67
|
|
|
|
|
|
|
}; |
68
|
0
|
0
|
|
|
|
|
croak "Invalid JSON from [$uri]" if $@; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return $data; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
0
|
1
|
|
sub stats { croak 'Unused feature' } |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub DESTROY { |
76
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
77
|
0
|
|
|
|
|
|
my $ident = _ident $self; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
foreach my $attr_ref (@attr_refs) { |
80
|
0
|
|
|
|
|
|
delete $attr_ref->{$ident}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
89
|
|
|
|
|
|
|
__END__ |