Net::Google::CalendarでQuickAddできるようにするパッチ

Net::Google::CalendarでQuickAddできそうなネタをここで偶然見つけたので適当に実装。

30boxesのevents.AddByOneBoxみたいにできる。以下使用方法。

#!/usr/bin/perl                                                                              

use strict;
use warnings;
use LWP::UserAgent;
use Net::Google::Calendar;

my $url  = $config->{URL} || "http://www.google.com/calendar/feeds/mail/full/basic";

my $ctext = join (' ', @ARGV);

my $cal = Net::Google::Calendar->new(url => $url);
$cal->login('user', 'pass');
$cal->add_quick_add($ctext);

http://www.google.com/calendar/compose?ctext=もあるが、かえってきたJSONをパースする必要があるので少し面倒。認証もあるし。

以下がパッチ。

$ diff -u perl/lib/Net/Google/Calendar.pm.org perl/lib/Net/Google/Calendar.pm     
--- perl/lib/Net/Google/Calendar.pm.org Sat Mar 17 22:11:40 2007
+++ perl/lib/Net/Google/Calendar.pm     Sat Mar 17 22:17:38 2007
@@ -357,6 +357,21 @@
 
 }
 
+sub add_quick_add {
+  my ($self, $ctext) = @_;
+  my $url = "http://www.google.com/calendar/feeds/$self->{calendar_id}/private/full"; 
+  # http://groups.google.co.jp/group/google-calendar-help-dataapi/browse_thread/thread/6f96fba5e1013af5
+  my $entry = <<EOF;
+<atom:entry xmlns:atom='http://www.w3.org/2005/Atom'>
+  <atom:category scheme='http://schemas.google.com/g/2005#kind'
+term='http://schemas.google.com/g/2005#event'></atom:category>
+  <atom:content type='text'>$ctext</atom:content>
+  <gCal:quickadd xmlns:gCal='http://schemas.google.com/gCal/2005'
+value='true'></gCal:quickadd>
+</atom:entry> 
+EOF
+  return $self->_do($entry, $url, 'POST');
+}
 
 =head2 delete_entry <Net::Google::Calendar::Entry>
 
@@ -398,8 +413,13 @@
         $url = "$tmp";
     }
 
-    my $xml = $entry->as_xml;
-    _utf8_off($xml);
+    my $xml;
+    if ($entry =~ m!<atom:entry!) {
+      $xml = $entry;
+    } else {
+      $xml = $entry->as_xml;
+      _utf8_off($xml);
+    }
     my %params = ( Content_Type => 'application/atom+xml; charset=UTF-8',
                    Authorization => "GoogleLogin auth=".$self->{_auth},
                    Content => $xml );