AI-CleverbotIO

 view release on metacpan or  search on metacpan

LICENSE  view on Meta::CPAN

modifying or distributing the Package, you accept this license. Do not
use, modify, or distribute the Package, if you do not accept this
license.

(11)  If your Modified Version has been derived from a Modified
Version made by someone other than you, you are nevertheless required
to ensure that your Modified Version complies with the requirements of
this license.

(12)  This license does not grant you the right to use any trademark,
service mark, tradename, or logo of the Copyright Holder.

(13)  This license includes the non-exclusive, worldwide,
free-of-charge patent license to make, have made, use, offer to sell,
sell, import and otherwise transfer the Package with respect to any
patent claims licensable by the Copyright Holder that are necessarily
infringed by the Package. If you institute patent litigation
(including a cross-claim or counterclaim) against any party alleging
that the Package constitutes direct or contributory patent
infringement, then this Artistic License to you shall terminate on the
date that such litigation is filed.

README  view on Meta::CPAN


    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

README  view on Meta::CPAN


 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);

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

         create => 'https://cleverbot.io/1.0/create',
      };
   },
);

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

has logger => (
   is      => 'ro',
   lazy    => 1,
   builder => 'BUILD_logger',
);

has nick => (
   is        => 'rw',
   lazy      => 1,
   predicate => 1,
);

has user => (
   is       => 'ro',
   required => 1,
);

has ua => (
   is      => 'ro',
   lazy    => 1,
   builder => 'BUILD_ua',
);

sub BUILD_logger {
   return Log::Any->get_logger;
}

sub BUILD_ua {
   my $self = shift;
   require HTTP::Tiny;
   return HTTP::Tiny->new;
}

sub ask {
   my ($self, $question) = @_;

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

   $self->nick($data->{nick}) if exists($data->{nick});

   return $data;
}

sub _parse_response {
   my ($self, $response) = @_;

   {
      local $Data::Dumper::Indent = 1;
      $self->logger->debug('got response: ' . Dumper($response));
   }

   ouch 500, 'no response (possible bug in HTTP::Tiny though?)'
     unless ref($response) eq 'HASH';

   my $status = $response->{status};
   ouch $status, $response->{reason}
      if ($status != 200) && ($status != 400);

   my $data = __decode_content($response);

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


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

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

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);



( run in 1.117 second using v1.01-cache-2.11-cpan-49f99fa48dc )