Acme-Free-Advice-Slip

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

            "Test::Pod" : "1.41",
            "Test::Spellunker" : "v0.2.7",
            "Version::Next" : "0"
         }
      },
      "runtime" : {
         "requires" : {
            "Getopt::Long" : "0",
            "HTTP::Tiny" : "0.088",
            "IO::Socket::SSL" : "1.42",
            "JSON::Tiny" : "0.58",
            "Mozilla::CA" : "0",
            "Net::SSLeay" : "1.49",
            "perl" : "v5.38.0"
         }
      },
      "test" : {
         "requires" : {
            "Test2::V0" : "0.000159"
         }
      }

META.json  view on Meta::CPAN

         "web" : "https://github.com/sanko/Acme-Free-Advice-Slip/issues"
      },
      "homepage" : "https://github.com/sanko/Acme-Free-Advice-Slip",
      "repository" : {
         "type" : "git",
         "url" : "https://github.com/sanko/Acme-Free-Advice-Slip.git",
         "web" : "https://github.com/sanko/Acme-Free-Advice-Slip"
      }
   },
   "version" : "1.1",
   "x_serialization_backend" : "JSON::PP version 4.16",
   "x_static_install" : 1
}

META.yml  view on Meta::CPAN

    - author
    - builder
provides:
  Acme::Free::Advice::Slip:
    file: lib/Acme/Free/Advice/Slip.pm
    version: '1.1'
requires:
  Getopt::Long: '0'
  HTTP::Tiny: '0.088'
  IO::Socket::SSL: '1.42'
  JSON::Tiny: '0.58'
  Mozilla::CA: '0'
  Net::SSLeay: '1.49'
  perl: v5.38.0
resources:
  bugtracker: https://github.com/sanko/Acme-Free-Advice-Slip/issues
  homepage: https://github.com/sanko/Acme-Free-Advice-Slip
  repository: https://github.com/sanko/Acme-Free-Advice-Slip.git
version: '1.1'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
x_static_install: 1

cpanfile  view on Meta::CPAN

requires 'perl', '5.038000';
requires 'Getopt::Long';
requires 'HTTP::Tiny'      => '0.088';
requires 'JSON::Tiny'      => '0.58';
requires 'IO::Socket::SSL' => '1.42';
requires 'Net::SSLeay'     => '1.49';
requires 'Mozilla::CA';
on 'test' => sub {
    requires 'Test2::V0' => 0.000159;
};
on 'configure' => sub {
    requires 'Archive::Tar';
    requires 'CPAN::Meta';
    requires 'ExtUtils::Config'  => 0.003;

lib/Acme/Free/Advice/Slip.pm  view on Meta::CPAN

package Acme::Free::Advice::Slip 1.1 {    # https://api.adviceslip.com/
    use v5.38;
    use HTTP::Tiny;
    use JSON::Tiny qw[decode_json];
    use parent 'Exporter';
    our %EXPORT_TAGS = ( all => [ our @EXPORT_OK = qw[advice search] ] );
    #
    use overload '""' => sub ( $s, $u, $b ) { $s->{advice} // () };
    #
    sub _http ($uri) {
        state $http
            //= HTTP::Tiny->new( default_headers => { Accept => 'application/json' }, agent => sprintf '%s/%.2f ', __PACKAGE__, our $VERSION );
        my $res = $http->get($uri);    # {success} is true even when advice is not found but we'll at least know when we have valid JSON
        $res->{success} ? decode_json( $res->{content} ) : ();
    }
    #
    sub advice ( $slip_id //= () ) {
        my $res = _http( 'https://api.adviceslip.com/advice' . ( $slip_id ? '/' . $slip_id : '' ) );
        defined $res->{slip} ? bless $res->{slip}, __PACKAGE__ : ();
    }

    sub search ($query) {
        my $res = _http( 'https://api.adviceslip.com/advice/search/' . $query );

script/advice_slip.pl  view on Meta::CPAN

#~ @ARGV = qw[-json];
#~ @ARGV = qw[-search time -json];
#~ @ARGV = qw[-id 5 -json];
#~ @ARGV = qw[-json -id 333];
#~ @ARGV = qw[-json -id 2];
#~ @ARGV = qw[-help];
#
my $raw = 0;
my ( $id, $query );

sub _echo ($slip) {    # JSON::Tiny is loaded in Acme::Free::Advice::* anyway
    $raw ?
        JSON::Tiny::encode_json(
        builtin::blessed $slip ? {%$slip} : [
            map {
                {%$_}
            } @$slip
        ]
        ) :
        $slip;
}
GetOptions( 'json' => \$raw, 'help' => sub { pod2usage( -exitval => 1 ) }, 'id=i' => \$id, 'search=s' => \$query );
if ( defined $query ) {

script/advice_slip.pl  view on Meta::CPAN

=head1 SYNOPSIS

    advice_slip                     # gather random wisdom
    advice_slip -id 5               # specific advice by ID
    advice_slip -search time        # query advice by keyword
    advice_slip -json -search hero  # get help like you're a robot
    advice_slip -help               # get help

=head1 OPTIONS

    -json               Echo raw JSON encoded data
    -id     <number>    Specify an ID
    -search <string>    Specify a search query
    -help               Display this help message

=head1 DESCRIPTION

This script wraps Acme::Free::Advice::Slip.

=head1 LICENSE & LEGAL



( run in 0.755 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )