Changeset 447 for cybozu2ical/trunk/lib/WWW
- Timestamp:
- 10/16/07 17:33:37 (15 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
cybozu2ical/trunk/lib/WWW/CybozuOffice6/Calendar.pm
r446 r447 35 35 } 36 36 37 sub get_items { 38 my $this = shift; 39 40 my $res = $this->_request(); 37 sub request { 38 my $this = shift; 39 40 my $res = $this->{ua}->post($this->{url} . '?page=SyncCalendar', { 41 _System => 'login', 42 _Login => 1, 43 csv => 1, 44 notimecard => 1, 45 defined $this->{username} ? (_Account => $this->{username}) : (), 46 defined $this->{userid} ? (_Id => $this->{userid} ) : (), 47 Password => $this->{password} || '', 48 }); 41 49 die 'Failed to access Cybozu Office 6: ' . $res->status_line 42 50 unless $res->is_success; … … 45 53 from_to($content, $this->{input_encoding} || 'shiftjis', 'utf8'); 46 54 my @lines = grep /^\d+,ts\.\d+,/, split(/\r?\n/, $content); 55 $this->{response} = \@lines; 56 57 scalar @lines ? \@lines : undef; 58 } 59 60 sub read_from_csv_file { 61 my $this = shift; 62 my ($file) = @_; 63 local *FH; 64 open FH, $file or die "Failed to read $file"; 65 my @lines; 66 while (<FH>) { 67 chomp; push @lines, $_; 68 } 69 close(FH); 70 $this->{response} = \@lines; 71 72 scalar @lines ? \@lines : undef; 73 } 74 75 sub response { 76 my $res = $_[0]->{response} || {}; 77 wantarray ? @$res : $res; 78 } 79 80 sub get_items { 81 my $this = shift; 47 82 48 83 my @items; 49 84 my $csv = Text::CSV_XS->new({ binary => 1 }); 50 for my $line ( @lines) {85 for my $line ($this->response) { 51 86 $csv->parse($line) 52 87 or die 'Failed to parse CSV input'; … … 103 138 } 104 139 105 sub _request {106 my $this = shift;107 $this->{ua}->post($this->{url} . '?page=SyncCalendar', {108 _System => 'login',109 _Login => 1,110 csv => 1,111 notimecard => 1,112 defined $this->{username} ? (_Account => $this->{username}) : (),113 defined $this->{userid} ? (_Id => $this->{userid} ) : (),114 Password => $this->{password} || '',115 });116 }117 118 140 package WWW::CybozuOffice6::Calendar::Event; 119 141 … … 268 290 ); 269 291 292 # request calendar contents 293 $calendar->request(); 294 270 295 # get list of items in the calendar 271 296 my @items = $calendar->get_items(); … … 346 371 Gets/sets the Cybozu Office 6 encoding. 347 372 373 =item request() 374 375 Requests to obtain the contents of Cybozu Office 6 Calendar. 376 377 =item read_from_csv_file($filename) 378 379 Instead of requesting Cybozu Office 6 server, reads from a local CSV file. 380 348 381 =item get_items() 349 382
![(please configure the [header_logo] section in trac.ini)](/public/chrome/common/trac_banner.png)