AI-CleverbotIO

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

       my $api_key = $obj->key;

    Read-only accessor to the API key. MUST be provided upon instantiation.

 endpoints

       my $endpoints_hashref = $obj->endpoints;

    Read-only accessor to a hash reference whose keys are the strings ask
    and create and the corresponding values are the API endoints (URIs).
    The default is:

       {
          ask    => 'https://cleverbot.io/1.0/ask',
          create => 'https://cleverbot.io/1.0/create',
       }

 logger

       my $logger = $obj->logger;

    Read-only accessor to the logger object (Log::Any compatible). See
    "BUILD_logger" for the default value.

 nick

       $obj->nick($some_string);
       my $nick = $obj->nick;

    Read-write accessor to the nick for invoking API calls. If not set, it
    is set after a call to "create". See also "has_nick".

 ua

       my $ua = $obj->ua;

    Read-only accessor to the user agent object (HTTP::Tiny compatible).
    See BUILD_ua for the default value.

 user

       my $api_user = $obj->user;

    Read-only accessor to the API user. MUST be provided upon
    instantiation.

METHODS

 BUILD_logger

    Called automatically if "logger" is not set. By default, it returns
    whatever "get_logger" in Log::Any provides, but you can easily override
    this in a derived class.

 BUILD_ua

    Called automatically if "ua" is not set. By default, it returns a plain
    new instance of HTTP::Tiny, without options.

 ask

       my $answer = $obj->ask($some_text);

    Send a ask API request. The returned $answer is a hash reference
    derived by the JSON decoding of the response body, e.g.:

       {

lib/AI/CleverbotIO.pm  view on Meta::CPAN

{ our $VERSION = '0.002'; }

use Moo;
use Ouch;
use Log::Any ();
use Data::Dumper;
use JSON::PP qw< decode_json >;

has endpoints => (
   is      => 'ro',
   default => sub {
      return {
         ask    => 'https://cleverbot.io/1.0/ask',
         create => 'https://cleverbot.io/1.0/create',
      };
   },
);

has key => (
   is       => 'ro',
   required => 1,

lib/AI/CleverbotIO.pod  view on Meta::CPAN

   my $api_key = $obj->key;

Read-only accessor to the API key. MUST be provided upon instantiation.

=head2 endpoints

   my $endpoints_hashref = $obj->endpoints;

Read-only accessor to a hash reference whose keys are the strings C<ask>
and C<create> and the corresponding values are the API endoints (URIs).
The default is:

   {
      ask    => 'https://cleverbot.io/1.0/ask',
      create => 'https://cleverbot.io/1.0/create',
   }

=head2 logger

   my $logger = $obj->logger;

Read-only accessor to the logger object (L<Log::Any> compatible). See
L</BUILD_logger> for the default value.

=head2 nick

   $obj->nick($some_string);
   my $nick = $obj->nick;

Read-write accessor to the nick for invoking API calls. If not set, it
is set after a call to L</create>. See also L</has_nick>.

=head2 ua

   my $ua = $obj->ua;

Read-only accessor to the user agent object (L<HTTP::Tiny> compatible). See
L<BUILD_ua> for the default value.

=head2 user

   my $api_user = $obj->user;

Read-only accessor to the API user. MUST be provided upon instantiation.

=head1 METHODS

=head2 BUILD_logger

Called automatically if L</logger> is not set. By default, it
returns whatever L<Log::Any/get_logger> provides, but you can
easily override this in a derived class.

=head2 BUILD_ua

Called automatically if L</ua> is not set. By default, it returns
a plain new instance of L<HTTP::Tiny>, without options.

=head2 ask

   my $answer = $obj->ask($some_text);

Send a I<ask> API request. The returned C<$answer> is a hash reference
derived by the JSON decoding of the response body, e.g.:

   {



( run in 0.699 second using v1.01-cache-2.11-cpan-0a6323c29d9 )