[Bps-public-commit] r9739 - in Net-Hiveminder: bin lib/Net

sartak at bestpractical.com sartak at bestpractical.com
Fri Nov 23 19:08:23 EST 2007


Author: sartak
Date: Fri Nov 23 19:08:23 2007
New Revision: 9739

Added:
   Net-Hiveminder/bin/sync_tasks   (contents, props changed)
Modified:
   Net-Hiveminder/   (props changed)
   Net-Hiveminder/lib/Net/Hiveminder.pm

Log:
 r45555 at onn:  sartak | 2007-11-23 18:15:16 -0500
 Add (up|down)load_(text|file)
 Add a script to keep a text file synced with your task list


Added: Net-Hiveminder/bin/sync_tasks
==============================================================================
--- (empty file)
+++ Net-Hiveminder/bin/sync_tasks	Fri Nov 23 19:08:23 2007
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Net::Hiveminder;
+
+my $file = shift
+    or die "Usage: $0 file";
+
+my $hm = Net::Hiveminder->new(use_config => 1);
+
+# update any tasks with the changes you've made
+$hm->upload_file($file)
+    if -e $file;
+
+# and sync your file with any other changes made
+$hm->download_file($file);
+

Modified: Net-Hiveminder/lib/Net/Hiveminder.pm
==============================================================================
--- Net-Hiveminder/lib/Net/Hiveminder.pm	(original)
+++ Net-Hiveminder/lib/Net/Hiveminder.pm	Fri Nov 23 19:08:23 2007
@@ -236,6 +236,73 @@
                 ->{message};
 }
 
+=head2 upload_text TEXT
+
+Uploads C<TEXT> to BTDT::Action::UploadTasks.
+
+=cut
+
+sub upload_text {
+    my $self = shift;
+    my $text = shift;
+
+    return $self->act(UploadTasks => content => $text, format => 'sync')
+                ->{message};
+}
+
+=head2 upload_file FILENAME
+
+Uploads C<FILENAME> to BTDT::Action::UploadTasks.
+
+=cut
+
+sub upload_file {
+    my $self = shift;
+    my $file = shift;
+
+    my $text = do { local (@ARGV, $/) = $file; <> };
+
+    return $self->upload_text($text);
+}
+
+=head2 download_tasks
+
+Downloads your tasks. This also gets the metadata so that you can edit the text
+and upload it, and it'll make the same changes to your task list.
+
+This does not currently accept query arguments, because Hiveminder expects a
+"/not/owner/me/group/personal" type argument string, when all we can produce is
+"owner_not => 'me', group => 'personal'"
+
+=cut
+
+sub download_text {
+    my $self = shift;
+
+    return $self->act(DownloadTasks => query => 'not/complete/starts/before/tomorrow/accepted/but_first/nothing', format => 'sync')->{content}{result};
+}
+
+=head2 download_file FILENAME
+
+Downloads your tasks and puts them into C<FILENAME>.
+
+This does not currently accept query arguments, because Hiveminder expects a
+"/not/owner/me/group/personal" type argument string, when all we can produce is
+"owner_not => 'me', group => 'personal'"
+
+=cut
+
+sub download_file {
+    my $self = shift;
+    my $file = shift;
+
+    my $text = $self->download_text(@_);
+    open my $handle, '>', $file
+        or confess "Unable to open $file for writing: $!";
+    print $handle $text;
+    close $handle;
+}
+
 =head2 canonicalize_priority PRIORITY
 
 Attempts to understand a variety of different priority formats and change



More information about the Bps-public-commit mailing list