root/trunk/plagger/lib/Plagger/Plugin/Publish/GoogleCalendar.pm

Revision 1929 (checked in by franck, 13 years ago)

in the example:
it's password, not pass

Line 
1 package Plagger::Plugin::Publish::GoogleCalendar;
2
3 use strict;
4 use base qw( Plagger::Plugin );
5 use Net::Google::Calendar;
6
7 sub register {
8     my ( $self, $context ) = @_;
9     $context->register_hook(
10         $self,
11         'plugin.init'  => \&initialize,
12         'publish.feed' => \&publish_feed,
13     );
14 }
15
16 sub initialize {
17     my ( $self, $c ) = @_;
18     $self->{cal} = Net::Google::Calendar->new( url => $self->conf->{url} );
19     $self->{cal}->login( $self->conf->{user}, $self->conf->{password} );
20 }
21
22 sub publish_feed {
23     my ( $self, $c, $args ) = @_;
24
25     my $feed = $args->{feed};
26     for my $entry ( $feed->entries ) {
27         my $gc_entry = Net::Google::Calendar::Entry->new();
28         $gc_entry->title( $entry->permalink
29             ? "["
30                 . $feed->title
31                 . "] <a href=\""
32                 . $entry->permalink . "\">"
33                 . $entry->title . "</a>"
34             : "[" . $feed->title . "] " . $entry->title );
35         $gc_entry->content( $entry->summary ? $entry->summary->plaintext : '',
36         );
37         $gc_entry->when( $entry->date,
38             $entry->date + DateTime::Duration->new( minutes => 5 ) );
39         my $tmp = $self->{cal}->add_entry($gc_entry);
40         $c->log( warn => "Failed to add entry to google calendar" )
41             if !defined $tmp;
42         sleep(1);
43     }
44 }
45
46 1;
47 __END__
48
49 =head1 NAME
50
51 Plagger::Plugin::Publish::GoogleCalendar - Publish feeds to google calendar
52
53 =head1 SYNOPSIS
54
55   - module: Publish::GoogleCalendar
56     config:
57       url:
58                 user:
59                 password:
60
61 =head1 DESCRIPTION
62
63
64 =head1 CONFIG
65
66 =over 4
67
68 =item url
69
70         URL for publishing on you calendar.
71
72         See
73
74             http://code.google.com/apis/gdata/calendar.html#find_feed_url
75
76 =back
77
78 =head1 AUTHOR
79
80 Franck Cuny
81
82 =head1 SEE ALSO
83
84 L<Plagger>
85
86 =cut
Note: See TracBrowser for help on using the browser.