line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dwimmer::Client; |
2
|
5
|
|
|
5
|
|
279518
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use WWW::Mechanize; |
5
|
|
|
|
|
|
|
use JSON qw(from_json); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has host => ( is => 'ro', isa => 'Str', required => 1 ); |
8
|
|
|
|
|
|
|
has mech => ( is => 'rw', isa => 'WWW::Mechanize', default => sub { WWW::Mechanize->new } ); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.32'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# get_user parameters can be id => 1 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub save_page { |
16
|
|
|
|
|
|
|
my ( $self, %args ) = @_; |
17
|
|
|
|
|
|
|
my $m = $self->mech; |
18
|
|
|
|
|
|
|
$args{editor_body} = delete $args{body}; |
19
|
|
|
|
|
|
|
$args{editor_title} = delete $args{title}; |
20
|
|
|
|
|
|
|
$m->post( $self->host . "/_dwimmer/save_page.json", \%args ); |
21
|
|
|
|
|
|
|
return from_json $m->content; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my %GET = map { $_ => $_ } qw( |
26
|
|
|
|
|
|
|
feed_collectors |
27
|
|
|
|
|
|
|
feeds |
28
|
|
|
|
|
|
|
fetch_lists |
29
|
|
|
|
|
|
|
page |
30
|
|
|
|
|
|
|
get_pages |
31
|
|
|
|
|
|
|
get_user |
32
|
|
|
|
|
|
|
history |
33
|
|
|
|
|
|
|
list_members |
34
|
|
|
|
|
|
|
list_users |
35
|
|
|
|
|
|
|
logout |
36
|
|
|
|
|
|
|
register_email |
37
|
|
|
|
|
|
|
search |
38
|
|
|
|
|
|
|
session |
39
|
|
|
|
|
|
|
site_config |
40
|
|
|
|
|
|
|
sites |
41
|
|
|
|
|
|
|
validate_email |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
my %POST = map { $_ => $_ } qw( |
44
|
|
|
|
|
|
|
add_feed |
45
|
|
|
|
|
|
|
add_user |
46
|
|
|
|
|
|
|
change_password |
47
|
|
|
|
|
|
|
change_my_password |
48
|
|
|
|
|
|
|
create_feed_collector |
49
|
|
|
|
|
|
|
create_list |
50
|
|
|
|
|
|
|
create_site |
51
|
|
|
|
|
|
|
login |
52
|
|
|
|
|
|
|
set_site_config |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
AUTOLOAD { |
56
|
|
|
|
|
|
|
our $AUTOLOAD; |
57
|
|
|
|
|
|
|
( my $sub = $AUTOLOAD ) =~ s/^Dwimmer::Client:://; |
58
|
|
|
|
|
|
|
my ( $self, %attr ) = @_; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $m = $self->mech; |
61
|
|
|
|
|
|
|
if ( $GET{$sub} ) { |
62
|
|
|
|
|
|
|
my $params = join "&", map {"$_=$attr{$_}"} keys %attr; |
63
|
|
|
|
|
|
|
my $url = $self->host . "/_dwimmer/$GET{$sub}.json?$params"; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#warn $url; |
66
|
|
|
|
|
|
|
$m->get($url); |
67
|
|
|
|
|
|
|
} elsif ( $POST{$sub} ) { |
68
|
|
|
|
|
|
|
my $url = $self->host . "/_dwimmer/$POST{$sub}.json"; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#warn $url; |
71
|
|
|
|
|
|
|
$m->post( $url, \%attr ); |
72
|
|
|
|
|
|
|
} else { |
73
|
|
|
|
|
|
|
die "Could not locate method '$sub'\n"; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
return from_json $m->content; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|