WebService::30Boxes::API::Todo - Object returned by WebService::30Boxes::API::call("todo.Get")


WebService-30Boxes-API documentation Contained in the WebService-30Boxes-API distribution.

Index


Code Index:

NAME

Top

WebService::30Boxes::API::Todo - Object returned by WebService::30Boxes::API::call("todo.Get")

SYNOPSIS

Top

  #$api_key and $auth_token are defined before
  my $boxes = WebService::30Boxes::API->new(api_key => $api_key);

  my $todos = $boxes->call('todos.Get', {authorizedUserToken => $auth_token});
  if($todos->{'success'}){
  	#while ($todos->nextTodoId){ - if you use this, you don't need to specify
  	#$_ as an argument
  	#foreach (@{$todos->get_ref_todoIds}){
  	foreach ($todos->get_todoIds){
  		print "Todo id: $_\n";
  		print "Title: " . $todos->get_title($_) . "\n";
  		print "Tags: ";
  		foreach ($todos->get_tags($_)){print "$_\n";}
  		print "Done: " . $todos->isDone($_) . "\n";
  		print "Position: " . $todos->get_position($_) . "\n";
  		print "External UID: " . $todos->get_externalUID($_) . "\n";
  	}
  }
  else{
  	print "An error occured (" . $todos->{'error_code'} . ": " .
  		$todos->{'error_msg'} . ")\n";
  }

DESCRIPTION

Top

An object of this type is returned by the WebService::30Boxes::API::call("todos.Get") function

METHODS

The following methods can be used

new

Create a new WebService::30Boxes::API::Todo object.

result

(Mandatory) Result must be the the hash function returned by the XML parser. Results are undefined if some other hash is passed in.

success

(Mandatory) If the API call was successful or not.

error_code

(Optional) If success is false, this must be supplied

error_message

(Optional) If success is false, this must be supplied

get_todoIds

Returns an array of todo ids.

You can then use this to call any of the following functions.

get_ref_todoIds

Returns a reference to an array of todo ids.

You can then use this to call any of the following functions.

nextTodoId

Advances the todo index and returns the new todoID (for convenience)

Arguments:

todoId

(Optional) The todoId of the todo for which you want to retreive the information. If not present, the next todoId will be used as an index. The next todoId is set by calling nextTodoId.

get_tags

Returns a list of tags.

Arguments:

todoId

(Optional) The todoId of the todo for which you want to retreive the information. If not present, the next todoId will be used as an index. The next todoId is set by calling nextTodoId.

get_title

Returns the title for the todo.

Arguments:

todoId

(Optional) The todoId of the todo for which you want to retreive the information. If not present, the next todoId will be used as an index. The next todoId is set by calling nextTodoId.

isDone

Returns the todo is done or not Returns 1 if yes, 0 if not

Arguments:

todoId

(Optional) The todoId of the todo for which you want to retreive the information. If not present, the next todoId will be used as an index. The next todoId is set by calling nextTodoId.

get_position

Returns the position of the todo as the user defined it

Arguments:

todoId

(Optional) The todoId of the todo for which you want to retreive the information. If not present, the next todoId will be used as an index. The next todoId is set by calling nextTodoId.

get_externalUID

Returns the user defined ID for this todo The return value is a string

Arguments:

todoId

(Optional) The todoId of the todo for which you want to retreive the information. If not present, the next todoId will be used as an index. The next todoId is set by calling nextTodoId.

TODO

Top

Add more error checking. Compact the code and make it more efficient. Please email me for feature requests.

BUGS

Top

Please notify chitoiup@umich.edu of any bugs.

SEE ALSO

Top

http://30boxes.com/, http://30boxes.com/api/

WebService::30Boxes::API

WebService::30Boxes::API::Event

AUTHOR

Top

Robert Chitoiu, <chitoiup@umich.edu>

COPYRIGHT AND LICENSE

Top


WebService-30Boxes-API documentation Contained in the WebService-30Boxes-API distribution.

package WebService::30Boxes::API::Todo;

use strict;
use warnings;
use Carp qw/croak/;

our $VERSION = '1.05';

sub new {
	my ($class, $result, $success, $error_code, $error_message) = @_;
	croak "The response from 30Boxes was not a success" unless $result->{'success'};

	#%{$result->{'_xml'}->{'todoList'}->{'todo'}} is a hash with todo ids as keys
	my $self = {	todo => $result->{'_xml'}->{'todoList'}->{'todo'},
			todoIds => [sort keys %{$result->{'_xml'}->{'todoList'}->{'todo'}}],
			todoIndex => -1,
			success => $success,
			error_code => $error_code,
			error_message => $error_message,
	};
	bless $self, $class;
	return $self;
}

#return an array of todo ids
sub get_todoIds {
	my ($self) = @_;
	return @{$self->{'todoIds'}};
}

#return a reference to an array of todo ids
sub get_ref_todoIds {
	my ($self) = @_;
	return $self->{'todoIds'};
}

#advance the todoIndex
sub nextTodoId {
	my ($self) = @_;
	return 0 if $self->{'todoIndex'} == scalar(@{$self->{'todoIds'}}) - 1;
	return $self->{'todoIds'}->[$self->{'todoIndex'}++];
}
	
#returns a list of tags
sub get_tags {
	my ($self, $todoId) = @_;
	$todoId = $self->{'todoIds'}->[$self->{'todoIndex'}] if 0 == $#_;
	my $temp = $self->{'todo'}->{$todoId}->{'tags'};
	return "" if ref($temp);#it's a hash if empty
	$temp =~ s/\s+/ /;
	return split(/ /, $temp);
}

#gets the title for the todos
sub get_title {
	my ($self, $todoId) = @_;
	$todoId = $self->{'todoIds'}->[$self->{'todoIndex'}] if 0 == $#_;
	return $self->{'todo'}->{$todoId}->{'summary'};
}

#get if the the todo is marked as done
#returns 1 if yes, 0 if not
sub isDone {
	my ($self, $todoId) = @_;
	$todoId = $self->{'todoIds'}->[$self->{'todoIndex'}] if 0 == $#_;
	return $self->{'todo'}->{$todoId}->{'done'};
}

#returns the position of the todo in the list
sub get_position {
	my ($self, $todoId) = @_;
	$todoId = $self->{'todoIds'}->[$self->{'todoIndex'}] if 0 == $#_;
	return $self->{'todo'}->{$todoId}->{'position'};
}

sub get_externalUID {
	my ($self, $todoId) = @_;
	$todoId = $self->{'todoIds'}->[$self->{'todoIndex'}] if 0 == $#_;
	my $temp = $self->{'todo'}->{$todoId}->{'externalUID'};
	return "" if ref($temp);#it's a hash if empty
	$temp =~ s/\s+/ /;
	return split(/ /, $temp);
}


1;
__END__