AI-CleverbotIO

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

SYNOPSIS

       use AI::CleverbotIO;
    
       my $cleverbot = AI::CleverbotIO->new(
          key => $ENV{CLEVERBOT_API_KEY},
          nick => $ENV{CLEVERBOT_NICK},
          user => $ENV{CLEVERBOT_API_USER},
       );
    
       # call to create() is mostly safe, you might get an error
       # back but still 200 OK. You can avoid this (and wasting one
       # API call) if you know the nick is already active for these
       # API credentials.
       $cleverbot->create();
    
       # then, it's just... ask()
       my $answer = $cleverbot->ask('Hello darling!');
       say $answer->{response};

DESCRIPTION

README  view on Meta::CPAN

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

README  view on Meta::CPAN

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

       {
          status => 'success',
          nick   => 'NickTheRobot',
       }

    If the current "nick" has already been used for creation, the API call
    will fail partially in that status 200 will be returned, but the status
    field in the answer will contain an error about the fact that the nick
    already exists (Error: reference name already exists). You can safely
    ignore this error.

    You can optionally pass a different other_nick. This will be set as
    "nick" and used for creation (this will overwrite whatever "nick"
    contains though).

 has_nick

       say $obj->nick if $obj->has_nick;
       say 'no nick yet' unless $obj->has_nick;

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

=head1 SYNOPSIS

   use AI::CleverbotIO;

   my $cleverbot = AI::CleverbotIO->new(
      key => $ENV{CLEVERBOT_API_KEY},
      nick => $ENV{CLEVERBOT_NICK},
      user => $ENV{CLEVERBOT_API_USER},
   );

   # call to create() is mostly safe, you might get an error
   # back but still 200 OK. You can avoid this (and wasting one
   # API call) if you know the nick is already active for these
   # API credentials.
   $cleverbot->create();

   # then, it's just... ask()
   my $answer = $cleverbot->ask('Hello darling!');
   say $answer->{response};

=head1 DESCRIPTION

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

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

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

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

   {
      status => 'success',
      nick   => 'NickTheRobot',
   }

If the current L</nick> has already been used for creation, the API call
will fail partially in that status 200 will be returned, but the C<status>
field in the answer will contain an error about the fact that the nick
already exists (C<Error: reference name already exists>). You can safely
ignore this error.

You can optionally pass a different C<other_nick>. This will be set as
L</nick> and used for creation (this will overwrite whatever L</nick>
contains though).

=head2 has_nick

   say $obj->nick if $obj->has_nick;
   say 'no nick yet' unless $obj->has_nick;

t/01-basic.t  view on Meta::CPAN

use Test::Exception;
use Log::Any::Adapter;
use 5.010;

use AI::CleverbotIO;

plan skip_all => 'no CLEVERBOT_API_USER/CLEVERBOT_API_KEY pair set'
  unless exists($ENV{CLEVERBOT_API_USER})
  && exists($ENV{CLEVERBOT_API_KEY});

Log::Any::Adapter->set('Stderr') if $ENV{CLEVERBOT_STDERR};

my $cleverbot;
lives_ok {
   $cleverbot = AI::CleverbotIO->new(
      key  => $ENV{CLEVERBOT_API_KEY},
      nick => $ENV{CLEVERBOT_NICK} // "AI::CleverbotIO Tester",
      user => $ENV{CLEVERBOT_API_USER},
   );
} ## end lives_ok
'AI::CleverbotIO instantiation lives';



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