diff options
author | Jesse Luehrs <doy@tozt.net> | 2016-05-29 00:51:36 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2016-05-29 00:51:36 -0400 |
commit | bbc2887a8efdf6323d0b4bf3d8bde6d17e8b4565 (patch) | |
tree | 1afd9fadc3c00154d001479105e17d0b7dc5a502 | |
parent | 73914c7b31b2cb1b6617544a9eda92cf8387e9f6 (diff) | |
parent | e307a8443dede3013016167031720d53b527dd7a (diff) | |
download | www-pocket-bbc2887a8efdf6323d0b4bf3d8bde6d17e8b4565.tar.gz www-pocket-bbc2887a8efdf6323d0b4bf3d8bde6d17e8b4565.zip |
Merge pull request #1 from gaurav/develop
Improved usage
-rw-r--r-- | bin/pocket | 25 | ||||
-rw-r--r-- | lib/WWW/Pocket.pm | 4 | ||||
-rw-r--r-- | lib/WWW/Pocket/Script.pm | 28 |
3 files changed, 54 insertions, 3 deletions
@@ -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 <string> Print all URLs whose title or URL contains C<string>. + favorites Print all unread, favorite URLs. + add <url [title]> Add URL, optionally with title. + archive <url> Archive URL. + readd <url> Unread/unarchive URL. + favorite <url> Favorite URL. + delete <url> 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.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}); diff --git a/lib/WWW/Pocket/Script.pm b/lib/WWW/Pocket/Script.pm index daf237f..b060afc 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,20 @@ sub _method_is_command { return 1; } +# 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; @@ -118,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 = <STDIN>); + my $key = <STDIN>; + + # Trim start and end. + $key =~ s/^\s*(.*)\s*$/$1/; + # print "Key entered: '$key'\n"; + return $key; } |