Changeset 506 for cybozu2ical/trunk/lib
- Timestamp:
- 08/28/08 16:52:19 (4 months ago)
- Location:
- cybozu2ical/trunk/lib/WWW
- Files:
-
- 2 modified
-
CybozuOffice6/Calendar.pm (modified) (6 diffs)
-
CybozuOffice7/Calendar.pm (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cybozu2ical/trunk/lib/WWW/CybozuOffice6/Calendar.pm
r505 r506 9 9 use Encode qw( from_to ); 10 10 use LWP::UserAgent; 11 use URI;12 11 use WWW::CybozuOffice6::Calendar::Event; 13 12 use WWW::CybozuOffice6::Calendar::RecurrentEvent; 14 13 15 our $VERSION = '0. 20';14 our $VERSION = '0.30'; 16 15 17 16 sub new { 18 17 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}; 22 19 bless \%param, $class; 23 20 } 24 21 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 )); 27 23 28 24 sub 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 44 39 unless $res->is_success; 45 40 46 41 my $content = $res->content; 47 from_to( $content, $ this->{input_encoding} || 'shiftjis', 'utf8' );42 from_to( $content, $cal->{input_encoding} || 'shiftjis', 'utf8' ); 48 43 my @lines = grep /^\d+,ts\.\d+,/, split( /\r?\n/, $content ); 49 $ this->{response} = \@lines;44 $cal->{response} = \@lines; 50 45 51 46 scalar @lines ? \@lines : undef; … … 53 48 54 49 sub read_from_csv_file { 55 my $ this= shift;50 my $cal = shift; 56 51 my ($file) = @_; 57 52 local *FH; … … 63 58 } 64 59 close(FH); 65 $ this->{response} = \@lines;60 $cal->{response} = \@lines; 66 61 67 62 scalar @lines ? \@lines : undef; … … 74 69 75 70 sub get_items { 76 my $ this= shift;71 my $cal = shift; 77 72 78 73 my $csv; … … 88 83 89 84 my @items; 90 for my $line ( $ this->response ) {85 for my $line ( $cal->response ) { 91 86 $csv->parse($line) 92 87 or confess 'Failed to parse CSV input'; … … 117 112 qw(id created start_time end_time freq freq_value abbrev summary description) 118 113 } = @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'; 120 115 121 116 my $item; -
cybozu2ical/trunk/lib/WWW/CybozuOffice7/Calendar.pm
r505 r506 10 10 use Encode qw( from_to ); 11 11 use LWP::UserAgent; 12 use URI;13 12 use DateTime; 14 13 use WWW::CybozuOffice6::Calendar::Event; 15 14 use WWW::CybozuOffice6::Calendar::RecurrentEvent; 16 15 17 our $VERSION = '0. 20';16 our $VERSION = '0.30'; 18 17 19 18 sub 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; 22 21 23 22 my $now = DateTime->now; … … 27 26 $now->clone->add( days => $date_range )->strftime('da.%Y.%m.%d'); 28 27 29 my $params = { 28 my $ua = LWP::UserAgent->new; 29 my $auth_param = { 30 30 _System => 'login', 31 31 _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} || '', 35 35 }; 36 36 37 37 # 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', 40 40 { 41 %$ params,41 %$auth_param, 42 42 SetDate => $setdate, 43 43 EndDate => $enddate, 44 44 } 45 45 ); 46 confess 'Failed to access Cybozu Office 7: ' . $res->status_line46 confess 'Failed to access ApiCalendar API: ' . $res->status_line 47 47 unless $res->is_success; 48 48 … … 52 52 53 53 # 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', 56 56 { 57 %$ params,57 %$auth_param, 58 58 EID => $1, 59 59 Date => $2, … … 66 66 67 67 my $content = $res->content; 68 from_to( $content, $ this->{input_encoding} || 'shiftjis', 'utf8' );68 from_to( $content, $cal->{input_encoding} || 'shiftjis', 'utf8' ); 69 69 my $line = ( split( /\r?\n/, $content ) )[0]; 70 70 … … 74 74 } 75 75 76 $ this->{response} = \@lines;76 $cal->{response} = \@lines; 77 77 scalar @lines ? \@lines : undef; 78 78 } 79 79 80 80 sub get_items { 81 my $ this= shift;81 my $cal = shift; 82 82 83 83 my $csv; … … 93 93 94 94 my @items; 95 for my $line ( $ this->response ) {95 for my $line ( $cal->response ) { 96 96 $csv->parse($line) 97 97 or confess 'Failed to parse CSV input'; … … 123 123 } = @fields[ 0, 1, 4, 5, 8 .. 11, 12 .. 14 ]; 124 124 125 $param{time_zone} = $ this->{time_zone} || 'Asia/Tokyo';125 $param{time_zone} = $cal->{time_zone} || 'Asia/Tokyo'; 126 126 127 127 my $item;
![(please configure the [header_logo] section in trac.ini)](/public/chrome/common/trac_banner.png)