Acme-Free-Advice-Unsolicited

 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-Unsolicited/issues"
      },
      "homepage" : "https://github.com/sanko/Acme-Free-Advice-Unsolicited",
      "repository" : {
         "type" : "git",
         "url" : "https://github.com/sanko/Acme-Free-Advice-Unsolicited.git",
         "web" : "https://github.com/sanko/Acme-Free-Advice-Unsolicited"
      }
   },
   "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::Unsolicited:
    file: lib/Acme/Free/Advice/Unsolicited.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-Unsolicited/issues
  homepage: https://github.com/sanko/Acme-Free-Advice-Unsolicited
  repository: https://github.com/sanko/Acme-Free-Advice-Unsolicited.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/Unsolicited.pm  view on Meta::CPAN

package Acme::Free::Advice::Unsolicited 1.1 {    # https://kk-advice.koyeb.app/api
    use v5.38;
    use HTTP::Tiny;
    use JSON::Tiny qw[decode_json];
    use parent 'Exporter';
    our %EXPORT_TAGS = ( all => [ our @EXPORT_OK = qw[advice all] ] );
    #
    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 ( $advice_id //= () ) {
        my $res = _http( 'https://kk-advice.koyeb.app/api/advice' . ( $advice_id ? '/' . $advice_id : '' ) );
        defined $res->{error} ? () : bless $res, __PACKAGE__;
    }

    sub all () {
        my $res = _http('https://kk-advice.koyeb.app/api/advice/all');

script/advice_kk.pl  view on Meta::CPAN

#~ @ARGV = qw[-all];
#~ @ARGV = qw[-json];
#~ @ARGV = qw[-id 5 -json];
#~ @ARGV = qw[-json -id 333];
#~ @ARGV = qw[-all -json];
#~ @ARGV = qw[-id 216];
#
my $raw = 0;
my ( $id, $all );

sub _echo ($slip) {    # JSON::Tiny is loaded in Acme::Free::Advice::Unsolicited anyway
    $raw ? JSON::Tiny::encode_json($slip) : $slip;
}
GetOptions( 'json' => \$raw, 'help' => sub { pod2usage( -exitval => 1 ) }, 'id=i' => \$id, 'all!' => \$all );
if ( defined $all ) {
    my @slips = Acme::Free::Advice::Unsolicited::all();
    exit say $raw ? '[]' : 'No advice matches query' unless +@slips;
    exit !say _echo( \@slips ) if $raw;
    say _echo($_) for @slips;
    exit !@slips;
}
my $slip = Acme::Free::Advice::Unsolicited::advice($id);

script/advice_kk.pl  view on Meta::CPAN

=head1 SYNOPSIS

    advice_kk                     # gather random wisdom
    advice_kk -id 5               # specific advice by ID
    advice_kk -id 5 -json         # specific advice by ID but you're a robot
    advice_kk -all                # get all advice
    advice_kk -help               # get help

=head1 OPTIONS

    -json               Echo raw JSON encoded data
    -id     <number>    Specify an ID
    -all                Gather all advice
    -help               Display this help message

=head1 DESCRIPTION

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

=head1 LICENSE & LEGAL



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