Changeset 506 for cybozu2ical/trunk/lib

Show
Ignore:
Timestamp:
08/28/08 16:52:19 (4 months ago)
Author:
ogawa
Message:

Remove host and ua methods from WWW::CybozuOffice??::Calendar.

Location:
cybozu2ical/trunk/lib/WWW
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • cybozu2ical/trunk/lib/WWW/CybozuOffice6/Calendar.pm

    r505 r506  
    99use Encode qw( from_to ); 
    1010use LWP::UserAgent; 
    11 use URI; 
    1211use WWW::CybozuOffice6::Calendar::Event; 
    1312use WWW::CybozuOffice6::Calendar::RecurrentEvent; 
    1413 
    15 our $VERSION = '0.20'; 
     14our $VERSION = '0.30'; 
    1615 
    1716sub new { 
    1817    my ( $class, %param ) = @_; 
    19     $param{url}  ||= delete $param{cybozu_url}; 
    20     $param{host} ||= URI->new( $param{url} )->host; 
    21     $param{ua}   ||= LWP::UserAgent->new(); 
     18    $param{url} ||= delete $param{cybozu_url}; 
    2219    bless \%param, $class; 
    2320} 
    2421 
    25 __PACKAGE__->mk_accessors( 
    26     qw( url host username userid password ua input_encoding )); 
     22__PACKAGE__->mk_accessors(qw( url username userid password input_encoding )); 
    2723 
    2824sub request { 
    29     my $this = shift; 
    30  
    31     my $res = $this->{ua}->post( 
    32         $this->{url} . '?page=SyncCalendar', 
    33         { 
    34             _System    => 'login', 
    35             _Login     => 1, 
    36             csv        => 1, 
    37             notimecard => 1, 
    38             defined $this->{username} ? ( _Account => $this->{username} ) : (), 
    39             defined $this->{userid}   ? ( _Id      => $this->{userid} )   : (), 
    40             Password => $this->{password} || '', 
    41         } 
    42     ); 
    43     confess 'Failed to access Cybozu Office 6: ' . $res->status_line 
     25    my $cal = shift; 
     26    my $date_range = $cal->{date_range} || 30; 
     27 
     28    my $ua         = LWP::UserAgent->new; 
     29    my $auth_param = { 
     30        _System => 'login', 
     31        _Login  => 1, 
     32        defined $cal->{username} ? ( _Account => $cal->{username} ) : (), 
     33        defined $cal->{userid}   ? ( _Id      => $cal->{userid} )   : (), 
     34        Password => $cal->{password} || '', 
     35    }; 
     36 
     37    my $res = $ua->post( $cal->{url} . '?page=SyncCalendar', $auth_param ); 
     38    confess 'Failed to access SyncCalendar API: ' . $res->status_line 
    4439      unless $res->is_success; 
    4540 
    4641    my $content = $res->content; 
    47     from_to( $content, $this->{input_encoding} || 'shiftjis', 'utf8' ); 
     42    from_to( $content, $cal->{input_encoding} || 'shiftjis', 'utf8' ); 
    4843    my @lines = grep /^\d+,ts\.\d+,/, split( /\r?\n/, $content ); 
    49     $this->{response} = \@lines; 
     44    $cal->{response} = \@lines; 
    5045 
    5146    scalar @lines ? \@lines : undef; 
     
    5348 
    5449sub read_from_csv_file { 
    55     my $this = shift; 
     50    my $cal = shift; 
    5651    my ($file) = @_; 
    5752    local *FH; 
     
    6358    } 
    6459    close(FH); 
    65     $this->{response} = \@lines; 
     60    $cal->{response} = \@lines; 
    6661 
    6762    scalar @lines ? \@lines : undef; 
     
    7469 
    7570sub get_items { 
    76     my $this = shift; 
     71    my $cal = shift; 
    7772 
    7873    my $csv; 
     
    8883 
    8984    my @items; 
    90     for my $line ( $this->response ) { 
     85    for my $line ( $cal->response ) { 
    9186        $csv->parse($line) 
    9287          or confess 'Failed to parse CSV input'; 
     
    117112            qw(id created start_time end_time freq freq_value abbrev summary description) 
    118113          } = @fields[ 0, 1, 5 .. 8, 11 .. 13 ]; 
    119         $param{time_zone} = $this->{time_zone} || 'Asia/Tokyo'; 
     114        $param{time_zone} = $cal->{time_zone} || 'Asia/Tokyo'; 
    120115 
    121116        my $item; 
  • cybozu2ical/trunk/lib/WWW/CybozuOffice7/Calendar.pm

    r505 r506  
    1010use Encode qw( from_to ); 
    1111use LWP::UserAgent; 
    12 use URI; 
    1312use DateTime; 
    1413use WWW::CybozuOffice6::Calendar::Event; 
    1514use WWW::CybozuOffice6::Calendar::RecurrentEvent; 
    1615 
    17 our $VERSION = '0.20'; 
     16our $VERSION = '0.30'; 
    1817 
    1918sub request { 
    20     my $this = shift; 
    21     my $date_range = $this->{date_range} || 30; 
     19    my $cal = shift; 
     20    my $date_range = $cal->{date_range} || 30; 
    2221 
    2322    my $now = DateTime->now; 
     
    2726      $now->clone->add( days => $date_range )->strftime('da.%Y.%m.%d'); 
    2827 
    29     my $params = { 
     28    my $ua         = LWP::UserAgent->new; 
     29    my $auth_param = { 
    3030        _System => 'login', 
    3131        _Login  => 1, 
    32         defined $this->{username} ? ( _Account => $this->{username} ) : (), 
    33         defined $this->{userid}   ? ( _Id      => $this->{userid} )   : (), 
    34         Password => $this->{password} || '', 
     32        defined $cal->{username} ? ( _Account => $cal->{username} ) : (), 
     33        defined $cal->{userid}   ? ( _Id      => $cal->{userid} )   : (), 
     34        Password => $cal->{password} || '', 
    3535    }; 
    3636 
    3737    # First, get a list of EID 
    38     my $res = $this->{ua}->post( 
    39         $this->{url} . '?page=ApiCalendar', 
     38    my $res = $ua->post( 
     39        $cal->{url} . '?page=ApiCalendar', 
    4040        { 
    41             %$params, 
     41            %$auth_param, 
    4242            SetDate => $setdate, 
    4343            EndDate => $enddate, 
    4444        } 
    4545    ); 
    46     confess 'Failed to access Cybozu Office 7: ' . $res->status_line 
     46    confess 'Failed to access ApiCalendar API: ' . $res->status_line 
    4747      unless $res->is_success; 
    4848 
     
    5252 
    5353        # Second, get a complete event from EID 
    54         my $res = $this->{ua}->post( 
    55             $this->{url} . '?page=ApiCalendar', 
     54        my $res = $ua->post( 
     55            $cal->{url} . '?page=ApiCalendar', 
    5656            { 
    57                 %$params, 
     57                %$auth_param, 
    5858                EID  => $1, 
    5959                Date => $2, 
     
    6666 
    6767        my $content = $res->content; 
    68         from_to( $content, $this->{input_encoding} || 'shiftjis', 'utf8' ); 
     68        from_to( $content, $cal->{input_encoding} || 'shiftjis', 'utf8' ); 
    6969        my $line = ( split( /\r?\n/, $content ) )[0]; 
    7070 
     
    7474    } 
    7575 
    76     $this->{response} = \@lines; 
     76    $cal->{response} = \@lines; 
    7777    scalar @lines ? \@lines : undef; 
    7878} 
    7979 
    8080sub get_items { 
    81     my $this = shift; 
     81    my $cal = shift; 
    8282 
    8383    my $csv; 
     
    9393 
    9494    my @items; 
    95     for my $line ( $this->response ) { 
     95    for my $line ( $cal->response ) { 
    9696        $csv->parse($line) 
    9797          or confess 'Failed to parse CSV input'; 
     
    123123          } = @fields[ 0, 1, 4, 5, 8 .. 11, 12 .. 14 ]; 
    124124 
    125         $param{time_zone} = $this->{time_zone} || 'Asia/Tokyo'; 
     125        $param{time_zone} = $cal->{time_zone} || 'Asia/Tokyo'; 
    126126 
    127127        my $item;