Changeset 1168

Show
Ignore:
Timestamp:
11/06/07 11:03:26 (6 years ago)
Author:
tokuhirom
Message:

lang/perl/misc/todo-pl-wassr: split Net::Wassr::TODO from this script.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/misc/todo-pl-wassr/wassr-todo.pl

    r1164 r1168  
    22use strict; 
    33use warnings; 
    4 use LWP::UserAgent; 
    54use autobox; 
    65use autobox::Core; 
    7  
    8 # ------------------------------------------------------------------------- 
    9  
    10 package Net::Wassr::TODO; 
    11 use strict; 
    12 use warnings; 
    13 use JSON::Syck; 
    14 use Carp; 
    15  
    16 our $VERSION = 0.01; 
    17 our $BASE_URL = 'http://api.wassr.jp/todo'; 
    18 our $APIHOST  = 'api.wassr.jp:80'; 
    19 our $APIREALM = 'API Authentication'; 
    20  
    21 sub new { 
    22     my $class = shift; 
    23     my $args = shift; 
    24  
    25     croak "username missing" unless $args->{username}; 
    26     croak "password missing" unless $args->{password}; 
    27  
    28     my $ua = LWP::UserAgent->new(agent => __PACKAGE__."/".$VERSION); 
    29     $ua->env_proxy; 
    30     $ua->credentials( 
    31         $APIHOST,  $APIREALM, 
    32         $args->{username}, $args->{password} 
    33     ); 
    34  
    35     bless {ua => $ua}, $class; 
    36 } 
    37  
    38 sub list { 
    39     my ($self, ) = @_; 
    40  
    41     my $ret = []; 
    42     my $page = 1; 
    43     while (1) { 
    44         my $res = $self->{ua}->get("$BASE_URL/list.json?page=$page"); 
    45         if ($res->is_success) { 
    46             my $dat = JSON::Syck::Load($res->content); 
    47             if ($dat->size()) { 
    48                 $ret->push( @$dat ); 
    49             } else { 
    50                 return $ret; 
    51             } 
    52         } else { 
    53             croak $res->status_line; 
    54         } 
    55  
    56         $page++; 
    57     } 
    58 } 
    59  
    60 sub done { 
    61     my ($self, $todo_rid) = @_; 
    62  
    63     my $res = $self->{ua}->post("$BASE_URL/done.json", [todo_rid => $todo_rid]); 
    64     if ($res->is_success) { 
    65         return $res->content; 
    66     } else { 
    67         croak $res->status_line; 
    68     } 
    69 } 
    70  
    71 sub add { 
    72     my ($self, $body) = @_; 
    73  
    74     my $res = $self->{ua}->post("$BASE_URL/add.json", [body => $body]); 
    75     if ($res->is_success) { 
    76         return $res->content; 
    77     } else { 
    78         croak $res->status_line; 
    79     } 
    80 } 
    81  
    82 package main; 
    83 use strict; 
    84 use warnings; 
    856use Switch; 
    867use YAML::Syck; 
    878use IO::File; 
    889use IO::Prompt; 
     10use Net::Wassr::TODO; 
    8911 
    9012our $CONFFILE = "$ENV{HOME}/.wassr-todo";