From 25980a90fec600a9c4fd60af0d4ed243b011d806 Mon Sep 17 00:00:00 2001 From: gaurav Date: Fri, 27 May 2016 19:05:35 +0530 Subject: Added Pod::Usage to improve documentation. Added a 'help' command to display synopsis and a fallback to display the full documentation if no commands are given. --- lib/WWW/Pocket/Script.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/WWW/Pocket/Script.pm b/lib/WWW/Pocket/Script.pm index daf237f..068ec3d 100644 --- a/lib/WWW/Pocket/Script.pm +++ b/lib/WWW/Pocket/Script.pm @@ -6,6 +6,7 @@ use JSON::PP; use List::Util 'sum'; use Path::Class; use URI; +use Pod::Usage; use WWW::Pocket; @@ -55,7 +56,7 @@ sub run { return $self->$method(@argv); } else { - die "insert usage here"; + pod2usage(-verbose => 2); } } @@ -63,6 +64,7 @@ sub _method_is_command { my $self = shift; my ($name) = @_; + return unless $name; return if $name eq 'run' || $name eq 'meta'; return if $name =~ /^_/; my $method = $self->meta->find_method_by_name($name); @@ -72,6 +74,12 @@ sub _method_is_command { return 1; } +# Display help about this script. +sub help { + my $self = shift; + pod2usage(-verbose => 1); +} + sub authenticate { my $self = shift; $self->pocket; -- cgit v1.2.3 From ad1a4bc33623b9bca05f827014b64097907aacfb Mon Sep 17 00:00:00 2001 From: gaurav Date: Fri, 27 May 2016 19:16:44 +0530 Subject: Improved synopsis, added 'man' command for manual. --- bin/pocket | 25 +++++++++++++++++++++++++ lib/WWW/Pocket/Script.pm | 10 +++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/bin/pocket b/bin/pocket index b335ae1..f2e33d8 100644 --- a/bin/pocket +++ b/bin/pocket @@ -4,8 +4,32 @@ use warnings; # PODNAME: pocket # ABSTRACT: interact with the Pocket API from the command line +=head1 NAME + +pocket - A command-line tool for Pocket (http://www.getpocket.com/) + =head1 SYNOPSIS +pocket [command] [options ...] + +Commands: + + help Displays this synopsis. + man Displays full documentation. + list Print all unread URLs in your account. + search Print all URLs whose title or URL contains C. + favorites Print all unread, favorite URLs. + add Add URL, optionally with title. + archive Archive URL. + readd Unread/unarchive URL. + favorite Favorite URL. + delete Delete URL. + words Print the number of words in all unread articles. + authenticate Authenticate and store credentials in C<~/.pocket>. + (all commands will do this automatically) + +Example usage: + $ pocket list Enter your consumer key: ... Visit https://getpocket.com/auth/authorize?request_token=...&redirect_uri=https://getpocket.com/ and log in. When you're done, press enter to continue. @@ -13,6 +37,7 @@ use warnings; http://the-toast.net/2015/04/27/looking-back-fragments-from-womens-shelters-1981-1996/view-all/ https://modelviewculture.com/pieces/dreaming-holding-onto-the-hope-of-justice-in-technology-and-america [...] + $ pocket words --archive 2233913 diff --git a/lib/WWW/Pocket/Script.pm b/lib/WWW/Pocket/Script.pm index 068ec3d..005d126 100644 --- a/lib/WWW/Pocket/Script.pm +++ b/lib/WWW/Pocket/Script.pm @@ -74,12 +74,20 @@ sub _method_is_command { return 1; } -# Display help about this script. +# Display quick usage help on this script. sub help { my $self = shift; pod2usage(-verbose => 1); } +# Display comprehensive help about this script. +sub man { + my $self = shift; + pod2usage(-verbose => 2); +} + + + sub authenticate { my $self = shift; $self->pocket; -- cgit v1.2.3 From 2736f75202266adcc06c46a887ad252b231160ce Mon Sep 17 00:00:00 2001 From: gaurav Date: Fri, 27 May 2016 19:28:34 +0530 Subject: Improved consumer key input documentation. --- lib/WWW/Pocket/Script.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/WWW/Pocket/Script.pm b/lib/WWW/Pocket/Script.pm index 005d126..b060afc 100644 --- a/lib/WWW/Pocket/Script.pm +++ b/lib/WWW/Pocket/Script.pm @@ -134,8 +134,16 @@ sub _authenticate { sub _prompt_for_consumer_key { my $self = shift; + print "Consumer key required. You can sign up for a consumer key as a\n" . + "Pocket developer at https://getpocket.com/developer/apps/new.\n"; + print "Enter your consumer key: "; - chomp(my $key = ); + my $key = ; + + # Trim start and end. + $key =~ s/^\s*(.*)\s*$/$1/; + # print "Key entered: '$key'\n"; + return $key; } -- cgit v1.2.3 From e307a8443dede3013016167031720d53b527dd7a Mon Sep 17 00:00:00 2001 From: gaurav Date: Fri, 27 May 2016 19:30:11 +0530 Subject: Improved error reporting from WWW::Pocket and displaying HTTP::Tiny errors. Also: added IO::Socket::SSL so it appears as a pre-req for this program. --- lib/WWW/Pocket.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/WWW/Pocket.pm b/lib/WWW/Pocket.pm index 645f30c..6567a94 100644 --- a/lib/WWW/Pocket.pm +++ b/lib/WWW/Pocket.pm @@ -3,7 +3,9 @@ use Moose; # ABSTRACT: Wrapper for the Pocket v3 API use HTTP::Tiny; +use IO::Socket::SSL; # Necessary for https URLs on HTTP::Tiny. use JSON::PP; +use Carp; =head1 SYNOPSIS @@ -263,7 +265,7 @@ sub _request { }, }, ); - die "Request for $uri failed ($response->{status}): $response->{reason}" + croak "Request for $uri failed ($response->{status}): $response->{content}" unless $response->{success}; return decode_json($response->{content}); -- cgit v1.2.3