| 1 | package Net::Todoist; | ||||||||||||||||||||||||||||||
| 2 | 2 | $Net::Todoist::VERSION = '0.06'; | |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: interface to the API for Todoist (a to-do list service) | ||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use JSON::XS; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use vars qw/$errstr/; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.8
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 14 | 1 | my $class = shift; | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | my $args = scalar @_ % 2 ? shift : {@_}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | unless ( $args->{ua} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | my $ua_args = delete $args->{ua_args} || {}; | ||||||||||||||||||||||||||||
|
Condition50%1/2
delete $args->{'ua_args'} || {}
MC/DC0%0/1
delete $args->{'ua_args'} || {}
delete $args->{'ua_args'}
Truth table50%1/2
A
A= delete $args->{'ua_args'}
| |||||||||||||||||||||||||||||||
| 19 | 1 | $args->{ua} = LWP::UserAgent->new(%$ua_args); | |||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | unless ( $args->{json} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 22 | 1 | $args->{json} = JSON::XS->new->utf8->allow_nonref; | |||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||
| 25 | 1 | bless $args, $class; | |||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | sub errstr { $errstr } | ||||||||||||||||||||||||||||
|
Subroutine
errstr: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub login { | ||||||||||||||||||||||||||||
|
Subroutine
login: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||
| 31 | 0 | my ( $self, $email, $pass ) = @_; | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||
| 33 | my $resp = $self->{ua}->post( | ||||||||||||||||||||||||||||||
| 34 | 0 | 'https://todoist.com/API/login', | |||||||||||||||||||||||||||||
| 35 | [ | ||||||||||||||||||||||||||||||
| 36 | email => $email, | ||||||||||||||||||||||||||||||
| 37 | password => $pass | ||||||||||||||||||||||||||||||
| 38 | ] | ||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 41 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 42 | 0 | return; | |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ( $resp->content =~ 'LOGIN_ERROR' ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 45 | 0 | $errstr = $resp->content; | |||||||||||||||||||||||||||||
| 46 | 0 | return; | |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||
| 49 | 0 | my $data = $self->{json}->decode( $resp->content ); | |||||||||||||||||||||||||||||
| 50 | 0 | $self->{token} = $data->{api_token}; | |||||||||||||||||||||||||||||
| 51 | 0 | return $data; | |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | sub getTimezones { | ||||||||||||||||||||||||||||
|
Subroutine
getTimezones: called CC=3 SCAR=13.5
Pod
documented
| |||||||||||||||||||||||||||||||
| 55 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||
| 57 | 1 | my $resp = $self->{ua}->get('http://todoist.com/API/getTimezones'); | |||||||||||||||||||||||||||||
| 58 | 1 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 59 | 1 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 60 | 1 | return; | |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||
| 63 | 0 | my $data = $self->{json}->decode( $resp->content ); | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | return wantarray ? @$data : $data; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub register { | ||||||||||||||||||||||||||||
|
Subroutine
register: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 68 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | my $args = scalar @_ % 2 ? shift : {@_}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||
| 71 | my $resp = $self->{ua}->post( | ||||||||||||||||||||||||||||||
| 72 | 'https://todoist.com/API/register', | ||||||||||||||||||||||||||||||
| 73 | [ | ||||||||||||||||||||||||||||||
| 74 | email => $args->{email}, | ||||||||||||||||||||||||||||||
| 75 | full_name => $args->{full_name}, | ||||||||||||||||||||||||||||||
| 76 | password => $args->{password} || $args->{pass}, | ||||||||||||||||||||||||||||||
| 77 | timezone => $args->{timezone} | ||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | ] | ||||||||||||||||||||||||||||
|
Condition0%0/3
$args->{'password'} || $args->{'pass'}
MC/DC0%0/2
$args->{'password'} || $args->{'pass'}
$args->{'password'}
$args->{'pass'}
Truth table0%0/3
A || B
A= $args->{'password'}B= $args->{'pass'}
| |||||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 81 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 82 | 0 | return; | |||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | unless ( $resp->content =~ 'api_token' ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 85 | 0 | $errstr = $resp->content; | |||||||||||||||||||||||||||||
| 86 | 0 | return; | |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||
| 89 | 0 | my $data = $self->{json}->decode( $resp->content ); | |||||||||||||||||||||||||||||
| 90 | 0 | $self->{token} = $data->{api_token}; | |||||||||||||||||||||||||||||
| 91 | 0 | return $data; | |||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub updateUser { | ||||||||||||||||||||||||||||
|
Subroutine
updateUser: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||
| 95 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||
| 97 | # validate | ||||||||||||||||||||||||||||||
| 98 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 100 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my $args = scalar @_ % 2 ? shift : {@_}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||
| 104 | my $resp = $self->{ua}->post( | ||||||||||||||||||||||||||||||
| 105 | 'https://todoist.com/API/updateUser', | ||||||||||||||||||||||||||||||
| 106 | [ | ||||||||||||||||||||||||||||||
| 107 | token => $self->{token}, | ||||||||||||||||||||||||||||||
| 108 | email => $args->{email}, | ||||||||||||||||||||||||||||||
| 109 | full_name => $args->{full_name}, | ||||||||||||||||||||||||||||||
| 110 | password => $args->{password} || $args->{pass}, | ||||||||||||||||||||||||||||||
| 111 | timezone => $args->{timezone} | ||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | ] | ||||||||||||||||||||||||||||
|
Condition0%0/3
$args->{'password'} || $args->{'pass'}
MC/DC0%0/2
$args->{'password'} || $args->{'pass'}
$args->{'password'}
$args->{'pass'}
Truth table0%0/3
A || B
A= $args->{'password'}B= $args->{'pass'}
| |||||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 115 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 116 | 0 | return; | |||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | unless ( $resp->content =~ 'api_token' ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 119 | 0 | $errstr = $resp->content; | |||||||||||||||||||||||||||||
| 120 | 0 | return; | |||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||
| 123 | 0 | my $data = $self->{json}->decode( $resp->content ); | |||||||||||||||||||||||||||||
| 124 | 0 | return $data; | |||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | sub getProjects { | ||||||||||||||||||||||||||||
|
Subroutine
getProjects: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 128 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||
| 130 | # validate | ||||||||||||||||||||||||||||||
| 131 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 133 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||
| 135 | my $resp = $self->{ua} | ||||||||||||||||||||||||||||||
| 136 | 0 | ->get("http://todoist.com/API/getProjects?token=$self->{token}"); | |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 138 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 139 | 0 | return; | |||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||
| 142 | 0 | my $data = $self->{json}->decode( $resp->content ); | |||||||||||||||||||||||||||||
| 143 | 0 | ▶ | return wantarray ? @$data : $data; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | sub getProject { | ||||||||||||||||||||||||||||
|
Subroutine
getProject: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||
| 147 | 0 | my ( $self, $project_id ) = @_; | |||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||
| 149 | # validate | ||||||||||||||||||||||||||||||
| 150 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 152 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||
| 154 | my $resp = | ||||||||||||||||||||||||||||||
| 155 | $self->{ua}->get( | ||||||||||||||||||||||||||||||
| 156 | 0 | "http://todoist.com/API/getProject?token=$self->{token}&project_id=$project_id" | |||||||||||||||||||||||||||||
| 157 | ); | ||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 159 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 160 | 0 | return; | |||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||
| 163 | 0 | my $data = $self->{json}->decode( $resp->content ); | |||||||||||||||||||||||||||||
| 164 | 0 | return $data; | |||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | sub addProject { | ||||||||||||||||||||||||||||
|
Subroutine
addProject: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 168 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | my $args = scalar @_ % 2 ? shift : {@_}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||
| 171 | # validate | ||||||||||||||||||||||||||||||
| 172 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 174 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | defined $args->{name} or croak 'name is required.'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||
| 177 | my $resp = $self->{ua}->post( | ||||||||||||||||||||||||||||||
| 178 | 'https://todoist.com/API/addProject', | ||||||||||||||||||||||||||||||
| 179 | [ | ||||||||||||||||||||||||||||||
| 180 | token => $self->{token}, | ||||||||||||||||||||||||||||||
| 181 | name => $args->{name}, | ||||||||||||||||||||||||||||||
| 182 | $args->{color} ? ( color => $args->{color} ) : (), | ||||||||||||||||||||||||||||||
| 183 | $args->{indent} ? ( indent => $args->{indent} ) : (), | ||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | $args->{order} ? ( order => $args->{order} ) : (), | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 185 | ] | ||||||||||||||||||||||||||||||
| 186 | ); | ||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 188 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 189 | 0 | return; | |||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | if ( $resp->content =~ 'ERROR_NAME_IS_EMPTY' ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 192 | 0 | $errstr = $resp->content; | |||||||||||||||||||||||||||||
| 193 | 0 | return; | |||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||
| 196 | 0 | my $data = $self->{json}->decode( $resp->content ); | |||||||||||||||||||||||||||||
| 197 | 0 | return $data; | |||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | sub updateProject { | ||||||||||||||||||||||||||||
|
Subroutine
updateProject: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 201 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 202 | 0 | ▶ | my $args = scalar @_ % 2 ? shift : {@_}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||
| 204 | # validate | ||||||||||||||||||||||||||||||
| 205 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 207 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | defined $args->{project_id} or croak 'project_id is required.'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||
| 210 | my $resp = $self->{ua}->post( | ||||||||||||||||||||||||||||||
| 211 | 'https://todoist.com/API/updateProject', | ||||||||||||||||||||||||||||||
| 212 | [ | ||||||||||||||||||||||||||||||
| 213 | token => $self->{token}, | ||||||||||||||||||||||||||||||
| 214 | project_id => $args->{project_id}, | ||||||||||||||||||||||||||||||
| 215 | $args->{name} ? ( order => $args->{name} ) : (), | ||||||||||||||||||||||||||||||
| 216 | $args->{color} ? ( color => $args->{color} ) : (), | ||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | $args->{indent} ? ( indent => $args->{indent} ) : (), | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 218 | ] | ||||||||||||||||||||||||||||||
| 219 | ); | ||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 221 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 222 | 0 | return; | |||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if ( $resp->content =~ 'ERROR_PROJECT_NOT_FOUND' ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 225 | 0 | $errstr = $resp->content; | |||||||||||||||||||||||||||||
| 226 | 0 | return; | |||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||
| 229 | 0 | my $data = $self->{json}->decode( $resp->content ); | |||||||||||||||||||||||||||||
| 230 | 0 | return $data; | |||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | sub deleteProject { | ||||||||||||||||||||||||||||
|
Subroutine
deleteProject: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 234 | 0 | my ( $self, $project_id ) = @_; | |||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||
| 236 | # validate | ||||||||||||||||||||||||||||||
| 237 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 239 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||
| 241 | my $resp = | ||||||||||||||||||||||||||||||
| 242 | $self->{ua}->get( | ||||||||||||||||||||||||||||||
| 243 | 0 | "http://todoist.com/API/deleteProject?token=$self->{token}&project_id=$project_id" | |||||||||||||||||||||||||||||
| 244 | ); | ||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 246 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 247 | 0 | return; | |||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | return ( $resp->content =~ /ok/i ) ? 1 : 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | sub getLabels { | ||||||||||||||||||||||||||||
|
Subroutine
getLabels: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 254 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||
| 256 | # validate | ||||||||||||||||||||||||||||||
| 257 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 259 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||
| 261 | my $resp = | ||||||||||||||||||||||||||||||
| 262 | 0 | $self->{ua}->get("http://todoist.com/API/getLabels?token=$self->{token}"); | |||||||||||||||||||||||||||||
| 263 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 264 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 265 | 0 | return; | |||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||
| 268 | 0 | my $data = $self->{json}->decode( $resp->content ); | |||||||||||||||||||||||||||||
| 269 | 0 | ▶ | return wantarray ? @$data : $data; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | sub updateLabel { | ||||||||||||||||||||||||||||
|
Subroutine
updateLabel: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||
| 273 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 274 | 0 | ▶ | my $args = scalar @_ % 2 ? shift : {@_}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||
| 276 | # validate | ||||||||||||||||||||||||||||||
| 277 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 279 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | defined $args->{old_name} or croak 'old_name is required.'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | defined $args->{new_name} or croak 'new_name is required.'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||
| 283 | my $resp = $self->{ua}->post( | ||||||||||||||||||||||||||||||
| 284 | 'https://todoist.com/API/updateLabel', | ||||||||||||||||||||||||||||||
| 285 | [ | ||||||||||||||||||||||||||||||
| 286 | token => $self->{token}, | ||||||||||||||||||||||||||||||
| 287 | old_name => $args->{old_name}, | ||||||||||||||||||||||||||||||
| 288 | new_name => $args->{new_name}, | ||||||||||||||||||||||||||||||
| 289 | 0 | ] | |||||||||||||||||||||||||||||
| 290 | ); | ||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 292 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 293 | 0 | return; | |||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | return ( $resp->content =~ /ok/i ) ? 1 : 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | sub deleteLabel { | ||||||||||||||||||||||||||||
|
Subroutine
deleteLabel: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 300 | 0 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||
| 302 | # validate | ||||||||||||||||||||||||||||||
| 303 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 305 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||
| 307 | my $resp = $self->{ua}->get( | ||||||||||||||||||||||||||||||
| 308 | 0 | "http://todoist.com/API/deleteLabel?token=$self->{token}&name=$name"); | |||||||||||||||||||||||||||||
| 309 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 310 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 311 | 0 | return; | |||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | return ( $resp->content =~ /ok/i ) ? 1 : 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | sub getUncompletedItems { | ||||||||||||||||||||||||||||
|
Subroutine
getUncompletedItems: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 318 | 0 | my ( $self, $project_id, $js_date ) = @_; | |||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||
| 320 | # validate | ||||||||||||||||||||||||||||||
| 321 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 323 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||
| 325 | 0 | my $url = | |||||||||||||||||||||||||||||
| 326 | "http://todoist.com/API/getUncompletedItems?token=$self->{token}&project_id=$project_id"; | ||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | $url .= '&js_date=1' if $js_date; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 328 | 0 | my $resp = $self->{ua}->get($url); | |||||||||||||||||||||||||||||
| 329 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 330 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 331 | 0 | return; | |||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||
| 334 | 0 | my $data = $self->{json}->decode( $resp->content ); | |||||||||||||||||||||||||||||
| 335 | 0 | ▶ | return wantarray ? @$data : $data; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | sub getCompletedItems { | ||||||||||||||||||||||||||||
|
Subroutine
getCompletedItems: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 339 | 0 | my ( $self, $project_id, $js_date ) = @_; | |||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||
| 341 | # validate | ||||||||||||||||||||||||||||||
| 342 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 344 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||
| 346 | 0 | my $url = | |||||||||||||||||||||||||||||
| 347 | "http://todoist.com/API/getCompletedItems?token=$self->{token}&project_id=$project_id"; | ||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | $url .= '&js_date=1' if $js_date; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 349 | 0 | my $resp = $self->{ua}->get($url); | |||||||||||||||||||||||||||||
| 350 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 351 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 352 | 0 | return; | |||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||
| 355 | 0 | my $data = $self->{json}->decode( $resp->content ); | |||||||||||||||||||||||||||||
| 356 | 0 | ▶ | return wantarray ? @$data : $data; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | sub getItemsById { | ||||||||||||||||||||||||||||
|
Subroutine
getItemsById: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||
| 360 | 0 | my ( $self, $item_ids, $js_date ) = @_; | |||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||
| 362 | # validate | ||||||||||||||||||||||||||||||
| 363 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 365 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | $item_ids = [$item_ids] unless ref $item_ids eq 'ARRAY'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||
| 369 | 0 | my $url = "http://todoist.com/API/getItemsById?token=$self->{token}&ids=" | |||||||||||||||||||||||||||||
| 370 | . join( ',', @$item_ids ); | ||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | $url .= '&js_date=1' if $js_date; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 372 | 0 | my $resp = $self->{ua}->get($url); | |||||||||||||||||||||||||||||
| 373 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 374 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 375 | 0 | return; | |||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||
| 378 | 0 | my $data = $self->{json}->decode( $resp->content ); | |||||||||||||||||||||||||||||
| 379 | 0 | ▶ | return wantarray ? @$data : $data; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | sub addItem { | ||||||||||||||||||||||||||||
|
Subroutine
addItem: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 383 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 384 | 0 | ▶ | my $args = scalar @_ % 2 ? shift : {@_}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||
| 386 | # validate | ||||||||||||||||||||||||||||||
| 387 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 389 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | defined $args->{project_id} or croak 'project_id is required.'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | defined $args->{content} or croak 'content is required.'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||
| 393 | my $resp = $self->{ua}->post( | ||||||||||||||||||||||||||||||
| 394 | 'https://todoist.com/API/addItem', | ||||||||||||||||||||||||||||||
| 395 | [ | ||||||||||||||||||||||||||||||
| 396 | token => $self->{token}, | ||||||||||||||||||||||||||||||
| 397 | project_id => $args->{project_id}, | ||||||||||||||||||||||||||||||
| 398 | content => $args->{content}, | ||||||||||||||||||||||||||||||
| 399 | $args->{date_string} ? ( date_string => $args->{date_string} ) : (), | ||||||||||||||||||||||||||||||
| 400 | $args->{priority} ? ( priority => $args->{priority} ) : (), | ||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | $args->{js_date} ? ( js_date => $args->{js_date} ) : (), | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 402 | ] | ||||||||||||||||||||||||||||||
| 403 | ); | ||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 405 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 406 | 0 | return; | |||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | unless ( $resp->content =~ 'id' ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 409 | 0 | $errstr = $resp->content; | |||||||||||||||||||||||||||||
| 410 | 0 | return; | |||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||
| 413 | 0 | my $data = $self->{json}->decode( $resp->content ); | |||||||||||||||||||||||||||||
| 414 | 0 | return $data; | |||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||
| 417 | 0 | ▶ | sub updateItem { | ||||||||||||||||||||||||||||
|
Subroutine
updateItem: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||
| 418 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 419 | 0 | ▶ | my $args = scalar @_ % 2 ? shift : {@_}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||
| 421 | # validate | ||||||||||||||||||||||||||||||
| 422 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 424 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | defined $args->{id} or croak 'id is required.'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||
| 427 | my $resp = $self->{ua}->post( | ||||||||||||||||||||||||||||||
| 428 | 'https://todoist.com/API/updateItem', | ||||||||||||||||||||||||||||||
| 429 | [ | ||||||||||||||||||||||||||||||
| 430 | token => $self->{token}, | ||||||||||||||||||||||||||||||
| 431 | id => $args->{id}, | ||||||||||||||||||||||||||||||
| 432 | $args->{content} ? ( content => $args->{content} ) : (), | ||||||||||||||||||||||||||||||
| 433 | $args->{date_string} ? ( date_string => $args->{date_string} ) : (), | ||||||||||||||||||||||||||||||
| 434 | $args->{priority} ? ( priority => $args->{priority} ) : (), | ||||||||||||||||||||||||||||||
| 435 | $args->{indent} ? ( indent => $args->{indent} ) : (), | ||||||||||||||||||||||||||||||
| 436 | $args->{item_order} ? ( item_order => $args->{item_order} ) : (), | ||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | $args->{js_date} ? ( js_date => $args->{js_date} ) : (), | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 438 | ] | ||||||||||||||||||||||||||||||
| 439 | ); | ||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 441 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 442 | 0 | return; | |||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | unless ( $resp->content =~ 'id' ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 445 | 0 | $errstr = $resp->content; | |||||||||||||||||||||||||||||
| 446 | 0 | return; | |||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||
| 449 | 0 | my $data = $self->{json}->decode( $resp->content ); | |||||||||||||||||||||||||||||
| 450 | 0 | return $data; | |||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | sub updateOrders { | ||||||||||||||||||||||||||||
|
Subroutine
updateOrders: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||
| 454 | 0 | my ( $self, $project_id, $item_ids ) = @_; | |||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||
| 456 | # validate | ||||||||||||||||||||||||||||||
| 457 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 459 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 460 | 0 | ▶ | defined $project_id or croak 'project_id is required.'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | $item_ids = [$item_ids] unless ref $item_ids eq 'ARRAY'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||
| 464 | 0 | my $url = | |||||||||||||||||||||||||||||
| 465 | "http://todoist.com/API/updateOrders?token=$self->{token}&project_id=$project_id&item_id_list=[" | ||||||||||||||||||||||||||||||
| 466 | . join( ',', @$item_ids ) . ']'; | ||||||||||||||||||||||||||||||
| 467 | 0 | my $resp = $self->{ua}->get($url); | |||||||||||||||||||||||||||||
| 468 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 469 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 470 | 0 | return; | |||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | return ( $resp->content =~ /ok/i ) ? 1 : 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | sub updateRecurringDate { | ||||||||||||||||||||||||||||
|
Subroutine
updateRecurringDate: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||
| 477 | 0 | my ( $self, $item_ids, $js_date ) = @_; | |||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||
| 479 | # validate | ||||||||||||||||||||||||||||||
| 480 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 481 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 482 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||
| 484 | 0 | ▶ | $item_ids = [$item_ids] unless ref $item_ids eq 'ARRAY'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||
| 486 | 0 | my $url = | |||||||||||||||||||||||||||||
| 487 | "http://todoist.com/API/updateRecurringDate?token=$self->{token}&ids=[" | ||||||||||||||||||||||||||||||
| 488 | . join( ',', @$item_ids ) . ']'; | ||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | $url .= '&js_date=1' if $js_date; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 490 | 0 | my $resp = $self->{ua}->get($url); | |||||||||||||||||||||||||||||
| 491 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 492 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 493 | 0 | return; | |||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||
| 496 | 0 | my $data = $self->{json}->decode( $resp->content ); | |||||||||||||||||||||||||||||
| 497 | 0 | ▶ | return wantarray ? @$data : $data; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||
| 500 | 0 | ▶ | sub deleteItems { | ||||||||||||||||||||||||||||
|
Subroutine
deleteItems: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||
| 501 | 0 | my ( $self, @item_ids ) = @_; | |||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||
| 503 | # validate | ||||||||||||||||||||||||||||||
| 504 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 506 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 507 | 0 | ▶ | @item_ids = @{ $item_ids[0] } | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
scalar @item_ids == 1 and ref $item_ids[0] eq "ARRAY"
MC/DC0%0/2
scalar @item_ids == 1 and ref $item_ids[0] eq "ARRAY"
scalar @item_ids == 1
ref $item_ids[0] eq "ARRAY"
Truth table0%0/3
A and B
A= scalar @item_ids == 1B= ref $item_ids[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||
| 508 | if scalar(@item_ids) == 1 and ref $item_ids[0] eq 'ARRAY'; | ||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||
| 510 | 0 | my $url = "http://todoist.com/API/deleteItems?token=$self->{token}&ids=[" | |||||||||||||||||||||||||||||
| 511 | . join( ',', @item_ids ) . ']'; | ||||||||||||||||||||||||||||||
| 512 | 0 | my $resp = $self->{ua}->get($url); | |||||||||||||||||||||||||||||
| 513 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 514 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 515 | 0 | return; | |||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||
| 518 | 0 | ▶ | return ( $resp->content =~ /ok/i ) ? 1 : 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||
| 521 | 0 | ▶ | sub completeItems { | ||||||||||||||||||||||||||||
|
Subroutine
completeItems: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||
| 522 | 0 | my ( $self, $item_ids, $in_history ) = @_; | |||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||
| 524 | # validate | ||||||||||||||||||||||||||||||
| 525 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 526 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 527 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | $item_ids = [$item_ids] unless ref $item_ids eq 'ARRAY'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||
| 530 | 0 | my $url = "http://todoist.com/API/completeItems?token=$self->{token}&ids=[" | |||||||||||||||||||||||||||||
| 531 | . join( ',', @$item_ids ) . ']'; | ||||||||||||||||||||||||||||||
| 532 | 0 | ▶ | $url .= '&in_history=1' if $in_history; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 533 | 0 | my $resp = $self->{ua}->get($url); | |||||||||||||||||||||||||||||
| 534 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 535 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 536 | 0 | return; | |||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||
| 539 | 0 | ▶ | return ( $resp->content =~ /ok/i ) ? 1 : 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||
| 542 | 0 | ▶ | sub uncompleteItems { | ||||||||||||||||||||||||||||
|
Subroutine
uncompleteItems: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||
| 543 | 0 | my ( $self, @item_ids ) = @_; | |||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||
| 545 | # validate | ||||||||||||||||||||||||||||||
| 546 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 547 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 548 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 549 | 0 | ▶ | @item_ids = @{ $item_ids[0] } | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
scalar @item_ids == 1 and ref $item_ids[0] eq "ARRAY"
MC/DC0%0/2
scalar @item_ids == 1 and ref $item_ids[0] eq "ARRAY"
scalar @item_ids == 1
ref $item_ids[0] eq "ARRAY"
Truth table0%0/3
A and B
A= scalar @item_ids == 1B= ref $item_ids[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||
| 550 | if scalar(@item_ids) == 1 and ref $item_ids[0] eq 'ARRAY'; | ||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||
| 552 | 0 | my $url = | |||||||||||||||||||||||||||||
| 553 | "http://todoist.com/API/uncompleteItems?token=$self->{token}&ids=[" | ||||||||||||||||||||||||||||||
| 554 | . join( ',', @item_ids ) . ']'; | ||||||||||||||||||||||||||||||
| 555 | 0 | my $resp = $self->{ua}->get($url); | |||||||||||||||||||||||||||||
| 556 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 557 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 558 | 0 | return; | |||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||
| 561 | 0 | ▶ | return ( $resp->content =~ /ok/i ) ? 1 : 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||
| 564 | 0 | ▶ | sub query { | ||||||||||||||||||||||||||||
|
Subroutine
query: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 565 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 566 | 0 | ▶ | my $args = scalar @_ % 2 ? shift : {@_}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||
| 568 | # validate | ||||||||||||||||||||||||||||||
| 569 | defined $self->{token} | ||||||||||||||||||||||||||||||
| 570 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 571 | 'token must be passed to ->new, or call ->login, ->register before this.'; | ||||||||||||||||||||||||||||||
| 572 | 0 | ▶ | defined $args->{queries} or croak 'queries is required.'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 573 | 0 | my $queries = $args->{queries}; | |||||||||||||||||||||||||||||
| 574 | 0 | ▶ | $queries = [$queries] unless ref $queries eq 'ARRAY'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||
| 576 | my $resp = $self->{ua}->post( | ||||||||||||||||||||||||||||||
| 577 | 'https://todoist.com/API/query', | ||||||||||||||||||||||||||||||
| 578 | [ | ||||||||||||||||||||||||||||||
| 579 | token => $self->{token}, | ||||||||||||||||||||||||||||||
| 580 | queries => '[' . join( ',', @$queries ) . ']', | ||||||||||||||||||||||||||||||
| 581 | $args->{as_count} ? ( as_count => $args->{as_count} ) : (), | ||||||||||||||||||||||||||||||
| 582 | 0 | ▶ | $args->{js_date} ? ( js_date => $args->{js_date} ) : (), | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 583 | ] | ||||||||||||||||||||||||||||||
| 584 | ); | ||||||||||||||||||||||||||||||
| 585 | 0 | ▶ | unless ( $resp->is_success ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 586 | 0 | $errstr = $resp->status_line; | |||||||||||||||||||||||||||||
| 587 | 0 | return; | |||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||
| 590 | 0 | my $data = $self->{json}->decode( $resp->content ); | |||||||||||||||||||||||||||||
| 591 | 0 | ▶ | return wantarray ? @$data : $data; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||
| 594 | 2 | 1; | |||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||
| 596 | __END__ | ||||||||||||||||||||||||||||||