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

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

publish feeds to you google calendar

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