line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Google::Tasks; |
2
|
|
|
|
|
|
|
# ABSTRACT: Manipulate Google/GMail Tasks |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
60376
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
483
|
use Moo; |
|
1
|
|
|
|
|
11969
|
|
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
1618
|
use namespace::clean; |
|
1
|
|
|
|
|
9425
|
|
|
1
|
|
|
|
|
6
|
|
9
|
1
|
|
|
1
|
|
735
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
32711
|
|
|
1
|
|
|
|
|
30
|
|
10
|
1
|
|
|
1
|
|
530
|
use HTML::Form; |
|
1
|
|
|
|
|
12607
|
|
|
1
|
|
|
|
|
30
|
|
11
|
1
|
|
|
1
|
|
676
|
use JSON; |
|
1
|
|
|
|
|
9045
|
|
|
1
|
|
|
|
|
9
|
|
12
|
1
|
|
|
1
|
|
793
|
use HTTP::Request::Common; |
|
1
|
|
|
|
|
1550
|
|
|
1
|
|
|
|
|
69
|
|
13
|
1
|
|
|
1
|
|
5
|
use Try::Tiny qw( try catch finally ); |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
54
|
|
14
|
1
|
|
|
1
|
|
4
|
use Carp 'croak'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
934
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '1.03'; # VERSION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has json => ( is => 'ro', default => sub { JSON->new } ); |
19
|
|
|
|
|
|
|
has ua => ( |
20
|
|
|
|
|
|
|
is => 'ro', |
21
|
|
|
|
|
|
|
default => sub { |
22
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
23
|
|
|
|
|
|
|
push( @{ $ua->requests_redirectable }, 'POST' ); |
24
|
|
|
|
|
|
|
$ua->cookie_jar({}); |
25
|
|
|
|
|
|
|
return $ua; |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has user => ( is => 'rwp' ); |
30
|
|
|
|
|
|
|
has passwd => ( is => 'rwp' ); |
31
|
|
|
|
|
|
|
has is_authed => ( is => 'rwp', default => 0 ); |
32
|
|
|
|
|
|
|
has lists => ( is => 'rwp' ); |
33
|
|
|
|
|
|
|
has tasks => ( is => 'rwp' ); |
34
|
|
|
|
|
|
|
has active_list => ( is => 'rwp' ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub BUILD { |
37
|
1
|
|
|
1
|
0
|
9
|
my ($self) = @_; |
38
|
1
|
50
|
33
|
|
|
20
|
$self->login( $self->user, $self->passwd ) if ( $self->user and $self->passwd ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub login { |
42
|
0
|
|
|
0
|
1
|
|
my ( $self, $user, $passwd ) = @_; |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
$self->_set_user($user) if ($user); |
45
|
0
|
0
|
|
|
|
|
$self->_set_passwd($passwd) if ($passwd); |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
0
|
|
|
|
croak('Must provide "user" and "passwd" values to login() or new()') |
48
|
|
|
|
|
|
|
unless ( $self->user and $self->passwd ); |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $form = ( HTML::Form->parse( $self->ua->request( |
51
|
|
|
|
|
|
|
HTTP::Request->new( 'GET', 'https://mail.google.com/tasks/ig' ) |
52
|
|
|
|
|
|
|
) ) )[0]; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
$form->value( 'Email', $self->user ); |
55
|
0
|
|
|
|
|
|
$form->value( 'Passwd', $self->passwd ); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $res = $self->ua->request( $form->click ); |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
croak('Authentication failed; check user and passwd values and that LWP::Protocol::https is installed') |
60
|
|
|
|
|
|
|
if ( $res->content =~ /Sign in/ ); |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
$self->_set_is_authed(1); |
63
|
0
|
0
|
|
|
|
|
return $self->_parse_data( |
64
|
|
|
|
|
|
|
$self->json->decode( |
65
|
|
|
|
|
|
|
( $res->content =~ /\{_setup\((.*)\)\}/ ) ? $1 : '' |
66
|
|
|
|
|
|
|
)->{'t'} |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _parse_data { |
71
|
0
|
|
|
0
|
|
|
my ( $self, $data ) = @_; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$self->_set_lists( [ map { Google::Tasks::List->new( %{$_}, 'root' => $self ) } @{ $data->{'lists'} } ] ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my %list_ids; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
$self->_set_tasks( [ map { |
78
|
0
|
|
|
|
|
|
$list_ids{$_}++ for ( @{ $_->{'list_id'} } ); |
|
0
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
$_->{'list_id'} = $_->{'list_id'}[0]; |
80
|
0
|
|
|
|
|
|
Google::Tasks::Task->new( %{$_}, 'root' => $self ); |
|
0
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
} @{ $data->{'tasks'} } ] ); |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $most_common_list_id = ( |
84
|
0
|
|
|
|
|
|
map { $_->[0] } |
85
|
0
|
|
|
|
|
|
sort { $b->[1] <=> $a->[1] } |
86
|
0
|
|
|
|
|
|
map { [ $_, $list_ids{$_} ] } |
87
|
|
|
|
|
|
|
keys %list_ids |
88
|
|
|
|
|
|
|
)[0]; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
try { |
91
|
0
|
|
|
|
|
|
$self->_set_active_list( |
92
|
0
|
|
|
0
|
|
|
grep { $_->id eq $most_common_list_id } @{ $self->lists } |
|
0
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
); |
94
|
0
|
|
|
|
|
|
}; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
return $self; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _call { |
100
|
0
|
|
|
0
|
|
|
my ( $self, $action ) = @_; |
101
|
0
|
0
|
|
|
|
|
croak('Must successfully authenticate with login() first') unless ( $self->is_authed ); |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
$action->{'action_id'} = int( rand(100) ); |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $res = $self->ua->request( HTTP::Request::Common::POST( |
106
|
|
|
|
|
|
|
'https://mail.google.com/tasks/r/ig', |
107
|
|
|
|
|
|
|
'AT' => 1, |
108
|
|
|
|
|
|
|
'Content' => [ 'r' => encode_json( { 'action_list' => [$action] } ) ], |
109
|
|
|
|
|
|
|
) ); |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
my $json; |
112
|
|
|
|
|
|
|
try { |
113
|
0
|
|
|
0
|
|
|
$json = $self->json->decode( $res->content ); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
catch { |
116
|
0
|
|
|
0
|
|
|
croak( $res->content ); |
117
|
0
|
|
|
|
|
|
}; |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
return $json; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub refresh { |
123
|
0
|
|
|
0
|
1
|
|
my ( $self, $list_name, $show_deleted ) = @_; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
my $list = $self->active_list; |
126
|
0
|
0
|
|
|
|
|
if ($list_name) { |
127
|
0
|
|
|
|
|
|
($list) = ( grep { $_->name eq $list_name } @{ $self->data->lists } ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
0
|
0
|
0
|
|
|
|
croak('Either provide no list name or a valid list name of a list that has been loaded/saved') |
130
|
|
|
|
|
|
|
unless ( ref $list eq 'Google::Tasks::List' and $list->id ); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
0
|
0
|
|
|
|
|
my $action = { |
134
|
|
|
|
|
|
|
'action_type' => 'get_all', |
135
|
|
|
|
|
|
|
'get_deleted' => ($show_deleted) ? JSON::true : JSON::false, |
136
|
|
|
|
|
|
|
}; |
137
|
|
|
|
|
|
|
|
138
|
0
|
0
|
0
|
|
|
|
$action->{'list_id'} = $list->id if ( ref $list eq 'Google::Tasks::List' and $list->id ); |
139
|
0
|
|
|
|
|
|
return $self->_parse_data( $self->_call($action) ); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
package Google::Tasks::List { |
143
|
1
|
|
|
1
|
|
5
|
use Moo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
144
|
1
|
|
|
1
|
|
303
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
has root => ( is => 'rwp', required => 1 ); |
147
|
|
|
|
|
|
|
has id => ( is => 'rwp' ); |
148
|
|
|
|
|
|
|
has name => ( is => 'rw', default => '', coerce => sub { defined $_[0] ? $_[0] : '' } ); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub save { |
151
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
152
|
|
|
|
|
|
|
|
153
|
0
|
0
|
|
|
|
|
unless ( $self->id ) { |
154
|
0
|
|
|
|
|
|
my $rv = $self->root->_call( { |
155
|
|
|
|
|
|
|
'action_type' => 'create', |
156
|
0
|
|
|
|
|
|
'index' => scalar( @{ $self->root->lists } ), |
157
|
|
|
|
|
|
|
'entity_delta' => { |
158
|
|
|
|
|
|
|
'name' => $self->name, |
159
|
|
|
|
|
|
|
'entity_type' => 'GROUP', |
160
|
|
|
|
|
|
|
}, |
161
|
|
|
|
|
|
|
} ); |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
$self->_set_id( $rv->{'results'}[0]{'new_id'} ); |
164
|
0
|
|
|
|
|
|
$self->root->_set_lists( [ @{ $self->root->lists }, $self ] ); |
|
0
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
$self->root->_set_active_list($self); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
else { |
168
|
0
|
|
|
|
|
|
$self->root->_call( { |
169
|
|
|
|
|
|
|
'action_type' => 'update', |
170
|
|
|
|
|
|
|
'id' => $self->id, |
171
|
|
|
|
|
|
|
'entity_delta' => { |
172
|
|
|
|
|
|
|
'name' => $self->name, |
173
|
|
|
|
|
|
|
}, |
174
|
|
|
|
|
|
|
} ); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
return $self; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub drop { |
181
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
182
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
$self->_call( { |
184
|
|
|
|
|
|
|
'action_type' => 'update', |
185
|
|
|
|
|
|
|
'id' => $self->id, |
186
|
|
|
|
|
|
|
'entity_delta' => { |
187
|
|
|
|
|
|
|
'deleted' => JSON::true, |
188
|
|
|
|
|
|
|
}, |
189
|
|
|
|
|
|
|
} ); |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
$self->root->_set_lists( [ grep { $_->id ne $self->id } @{ $self->root->lists } ] ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
192
|
0
|
0
|
|
|
|
|
$self->root->_set_active_list(undef) if ( $self->root->active_list->id eq $self->id ); |
193
|
|
|
|
|
|
|
|
194
|
0
|
|
|
|
|
|
return $self->root; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub clear { |
198
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
$self->_call( { |
201
|
|
|
|
|
|
|
'action_type' => 'update_user', |
202
|
|
|
|
|
|
|
'clear_list_ids' => $self->id, |
203
|
|
|
|
|
|
|
} ); |
204
|
|
|
|
|
|
|
|
205
|
0
|
|
0
|
|
|
|
$self->root->_set_tasks( [ grep { not $_->completed and not $_->deleted } @{ $self->root->tasks } ] ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
return $self; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
}; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub add_list { |
211
|
0
|
|
|
0
|
1
|
|
my ( $self, $list_name ) = @_; |
212
|
0
|
|
|
|
|
|
return Google::Tasks::List->new( name => $list_name, root => $self )->save; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub drop_list { |
216
|
0
|
|
|
0
|
1
|
|
my ( $self, $list_name ) = @_; |
217
|
0
|
|
|
|
|
|
my ($list) = grep { $_->name eq $list_name } @{ $self->data->lists }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
|
219
|
0
|
0
|
0
|
|
|
|
croak('Must provide a valid list name of a list that has been loaded or saved') |
220
|
|
|
|
|
|
|
unless ( ref $list eq 'Google::Tasks::List' and $list->id ); |
221
|
|
|
|
|
|
|
|
222
|
0
|
|
|
|
|
|
return $list->drop; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub rename_list { |
226
|
0
|
|
|
0
|
1
|
|
my ( $self, $current_list_name, $new_list_name ) = @_; |
227
|
0
|
|
|
|
|
|
my ($list) = grep { $_->name eq $current_list_name } @{ $self->data->lists }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
|
229
|
0
|
0
|
0
|
|
|
|
croak('Must provide a valid list name of a list that has been loaded or saved') |
230
|
|
|
|
|
|
|
unless ( ref $list eq 'Google::Tasks::List' and $list->id ); |
231
|
|
|
|
|
|
|
|
232
|
0
|
|
|
|
|
|
return $list->name($new_list_name)->save; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
sub clear_list { |
236
|
0
|
|
|
0
|
1
|
|
my ( $self, $list_name ) = @_; |
237
|
0
|
|
|
|
|
|
my ($list) = grep { $_->name eq $list_name } @{ $self->data->lists }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
|
239
|
0
|
0
|
0
|
|
|
|
croak('Must provide a valid list name of a list that has been loaded or saved') |
240
|
|
|
|
|
|
|
unless ( ref $list eq 'Google::Tasks::List' and $list->id ); |
241
|
|
|
|
|
|
|
|
242
|
0
|
|
|
|
|
|
return $list->clear; |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
package Google::Tasks::Task { |
246
|
1
|
|
|
1
|
|
947
|
use Moo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
247
|
1
|
|
|
1
|
|
205
|
use namespace::clean; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3
|
|
248
|
1
|
|
|
1
|
|
129
|
use Carp 'croak'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
249
|
1
|
|
|
1
|
|
569
|
use List::MoreUtils 'firstidx'; |
|
1
|
|
|
|
|
7795
|
|
|
1
|
|
|
|
|
7
|
|
250
|
1
|
|
|
1
|
|
814
|
use Date::Parse 'str2time'; |
|
1
|
|
|
|
|
3844
|
|
|
1
|
|
|
|
|
80
|
|
251
|
1
|
|
|
1
|
|
951
|
use DateTime; |
|
1
|
|
|
|
|
92229
|
|
|
1
|
|
|
|
|
936
|
|
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
has root => ( is => 'rwp', required => 1 ); |
254
|
|
|
|
|
|
|
has list => ( is => 'rwp' ); |
255
|
|
|
|
|
|
|
has list_id => ( is => 'rwp' ); |
256
|
|
|
|
|
|
|
has id => ( is => 'rwp' ); |
257
|
|
|
|
|
|
|
has name => ( is => 'rw', default => '', coerce => sub { defined $_[0] ? $_[0] : '' } ); |
258
|
|
|
|
|
|
|
has notes => ( is => 'rw', default => '', coerce => sub { defined $_[0] ? $_[0] : '' } ); |
259
|
|
|
|
|
|
|
has completed => ( is => 'rw', default => 0, coerce => sub { $_[0] ? JSON::true : JSON::false } ); |
260
|
|
|
|
|
|
|
has deleted => ( is => 'rw', default => 0, coerce => sub { $_[0] ? JSON::true : JSON::false } ); |
261
|
|
|
|
|
|
|
has task_date => ( is => 'rw', coerce => sub { DateTime->from_epoch( epoch => str2time( $_[0] ) ) } ); |
262
|
|
|
|
|
|
|
has index => ( is => 'rwp', default => 0 ); |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
sub BUILD { |
265
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
266
|
0
|
|
|
|
|
|
local $Carp::CarpLevel = 2; |
267
|
|
|
|
|
|
|
|
268
|
0
|
0
|
|
|
|
|
if ( $self->list_id ) { |
|
|
0
|
|
|
|
|
|
269
|
0
|
|
|
|
|
|
my ($list) = grep { $self->list_id eq $_->id } @{ $self->root->lists }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
270
|
0
|
0
|
|
|
|
|
croak('If "list_id" is provided, it must be a valid list ID from a loaded list') |
271
|
|
|
|
|
|
|
if ( not $list ); |
272
|
|
|
|
|
|
|
|
273
|
0
|
|
|
|
|
|
$self->_set_list($list); |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
elsif ( $self->list ) { |
276
|
0
|
0
|
|
|
|
|
croak('If "list" is provided, it must be a valid Google::Tasks::List object') |
277
|
|
|
|
|
|
|
if ( ref $self->list ne 'Google::Tasks::List' ); |
278
|
|
|
|
|
|
|
|
279
|
0
|
|
|
|
|
|
$self->_set_list_id = $self->list->id; |
280
|
|
|
|
|
|
|
} |
281
|
|
|
|
|
|
|
else { |
282
|
0
|
|
|
|
|
|
$self->_set_list( $self->root->active_list ); |
283
|
0
|
|
|
|
|
|
$self->_set_list_id( $self->root->active_list->id ); |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
sub save { |
288
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
289
|
|
|
|
|
|
|
|
290
|
0
|
|
|
|
|
|
my %attr = map { $_ => $self->$_ } qw( name notes completed deleted ); |
|
0
|
|
|
|
|
|
|
291
|
0
|
0
|
|
|
|
|
$attr{'task_date'} = $self->task_date->ymd('') if ( defined $self->task_date ); |
292
|
|
|
|
|
|
|
|
293
|
0
|
0
|
|
|
|
|
unless ( $self->id ) { |
294
|
0
|
|
|
|
|
|
my %extra; |
295
|
0
|
0
|
|
|
|
|
$extra{'prior_sibling_id'} = $self->root->tasks->[ $self->index - 1 ]->id if ( $self->index ); |
296
|
|
|
|
|
|
|
|
297
|
0
|
|
|
|
|
|
my $rv = $self->root->_call( { |
298
|
|
|
|
|
|
|
'action_type' => 'create', |
299
|
|
|
|
|
|
|
'list_id' => $self->list_id, |
300
|
|
|
|
|
|
|
'parent_id' => $self->list_id, |
301
|
|
|
|
|
|
|
'dest_parent_type' => 'GROUP', |
302
|
|
|
|
|
|
|
'index' => $self->index, |
303
|
|
|
|
|
|
|
'entity_delta' => { |
304
|
|
|
|
|
|
|
'entity_type' => 'TASK', |
305
|
|
|
|
|
|
|
%attr, |
306
|
|
|
|
|
|
|
}, |
307
|
|
|
|
|
|
|
%extra, |
308
|
|
|
|
|
|
|
} ); |
309
|
|
|
|
|
|
|
|
310
|
0
|
|
|
|
|
|
$self->_set_id( $rv->{'results'}[0]{'new_id'} ); |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
else { |
313
|
0
|
|
|
|
|
|
$self->root->_call( { |
314
|
|
|
|
|
|
|
'action_type' => 'update', |
315
|
|
|
|
|
|
|
'id' => $self->id, |
316
|
|
|
|
|
|
|
'entity_delta' => { |
317
|
|
|
|
|
|
|
%attr, |
318
|
|
|
|
|
|
|
}, |
319
|
|
|
|
|
|
|
} ); |
320
|
|
|
|
|
|
|
} |
321
|
|
|
|
|
|
|
|
322
|
0
|
|
|
|
|
|
return $self; |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
sub move { |
326
|
0
|
|
|
0
|
0
|
|
my ( $self, $command ) = @_; |
327
|
0
|
0
|
|
|
|
|
croak('Must provide some command value for move()') unless ( defined $command ); |
328
|
|
|
|
|
|
|
|
329
|
0
|
0
|
0
|
|
|
|
if ( $command =~ /^\d+$/ ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
330
|
0
|
0
|
0
|
|
|
|
croak("move() command seems to relocate task out of bounds of current list") |
331
|
|
|
|
|
|
|
if ( $command and not defined $self->root->tasks->[$command] ); |
332
|
|
|
|
|
|
|
|
333
|
0
|
0
|
|
|
|
|
$self->root->_call( { |
334
|
|
|
|
|
|
|
'action_type' => 'move', |
335
|
|
|
|
|
|
|
'id' => $self->id, |
336
|
|
|
|
|
|
|
'source_list' => $self->list_id, |
337
|
|
|
|
|
|
|
($command) ? ( |
338
|
|
|
|
|
|
|
'dest_parent' => $self->list_id, |
339
|
|
|
|
|
|
|
'prior_sibling_id' => $self->root->tasks->[$command]->id, |
340
|
|
|
|
|
|
|
) : ( |
341
|
|
|
|
|
|
|
'dest_parent' => $self->list_id, |
342
|
|
|
|
|
|
|
), |
343
|
|
|
|
|
|
|
} ); |
344
|
|
|
|
|
|
|
|
345
|
0
|
|
|
|
|
|
my @tasks = grep { $_->id ne $self->id } @{ $self->root->tasks }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
346
|
0
|
|
|
|
|
|
splice( @tasks, $command, 0, $self ); |
347
|
0
|
|
|
|
|
|
$self->root->_set_tasks(\@tasks); |
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
elsif ( $command eq 'down' ) { |
350
|
0
|
|
|
0
|
|
|
$self->move( ( firstidx { $_->id eq $self->id } @{ $self->root->tasks } ) + 1 ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
} |
352
|
|
|
|
|
|
|
elsif ( $command eq 'up' ) { |
353
|
0
|
|
|
0
|
|
|
my $idx = ( firstidx { $_->id eq $self->id } @{ $self->root->tasks } ) - 1; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
|
355
|
0
|
0
|
|
|
|
|
croak("move() command seems to relocate task out of bounds of current list") |
356
|
|
|
|
|
|
|
if ( $idx < 0 ); |
357
|
|
|
|
|
|
|
|
358
|
0
|
|
|
|
|
|
$self->move($idx); |
359
|
|
|
|
|
|
|
} |
360
|
|
|
|
|
|
|
elsif ( |
361
|
|
|
|
|
|
|
ref $command eq 'Google::Tasks::Task' or |
362
|
|
|
|
|
|
|
ref $command eq 'Google::Tasks::List' |
363
|
|
|
|
|
|
|
) { |
364
|
0
|
|
|
|
|
|
$self->root->_call( { |
365
|
|
|
|
|
|
|
'action_type' => 'move', |
366
|
|
|
|
|
|
|
'id' => $self->id, |
367
|
|
|
|
|
|
|
'source_list' => $self->list_id, |
368
|
|
|
|
|
|
|
'dest_parent' => $command->id, |
369
|
|
|
|
|
|
|
} ); |
370
|
|
|
|
|
|
|
} |
371
|
|
|
|
|
|
|
else { |
372
|
0
|
|
|
|
|
|
croak('Was unable to recognize command value provided'); |
373
|
|
|
|
|
|
|
} |
374
|
|
|
|
|
|
|
|
375
|
0
|
|
|
|
|
|
return $self; |
376
|
|
|
|
|
|
|
} |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
sub drop { |
379
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
380
|
|
|
|
|
|
|
|
381
|
0
|
|
|
|
|
|
$self->_call( { |
382
|
|
|
|
|
|
|
'action_type' => 'update', |
383
|
|
|
|
|
|
|
'id' => $self->id, |
384
|
|
|
|
|
|
|
'entity_delta' => { |
385
|
|
|
|
|
|
|
'deleted' => JSON::true, |
386
|
|
|
|
|
|
|
}, |
387
|
|
|
|
|
|
|
} ); |
388
|
|
|
|
|
|
|
|
389
|
0
|
|
|
|
|
|
$self->root->_set_tasks( [ grep { $_->id ne $self->id } @{ $self->root->tasks } ] ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
390
|
0
|
|
|
|
|
|
return $self->root; |
391
|
|
|
|
|
|
|
} |
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
}; |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
sub add_task { |
396
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
397
|
0
|
|
|
|
|
|
return Google::Tasks::Task->new( @_, root => $self )->save; |
398
|
|
|
|
|
|
|
} |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
sub drop_task { |
401
|
0
|
|
|
0
|
1
|
|
my ( $self, $task_name ) = @_; |
402
|
0
|
|
|
|
|
|
return $self->task_by_name($task_name)->drop; |
403
|
|
|
|
|
|
|
} |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
sub task_by_name { |
406
|
0
|
|
|
0
|
1
|
|
my ( $self, $task_name ) = @_; |
407
|
0
|
|
|
|
|
|
my ($task) = grep { $_->name ne $task_name } @{ $self->root->tasks }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
408
|
0
|
0
|
|
|
|
|
croak('Unable to find a task by the name provided') unless ( ref $task eq 'Google::Tasks::Task' ); |
409
|
0
|
|
|
|
|
|
return $task; |
410
|
|
|
|
|
|
|
} |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
1; |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
__END__ |