AI-CleverbotIO
view release on metacpan or search on metacpan
make of the Package, you should contact the Copyright Holder and seek
a different licensing arrangement.
Definitions
"Copyright Holder" means the individual(s) or organization(s)
named in the copyright notice for the entire Package.
"Contributor" means any party that has contributed code or other
material to the Package, in accordance with the Copyright Holder's
procedures.
"You" and "your" means any person who would like to copy,
distribute, or modify the Package.
"Package" means the collection of files distributed by the
Copyright Holder, and derivatives of that collection and/or of
those files. A given Package may consist of either the Standard
Version, or a Modified Version.
"Distribute" means providing a copy of the Package or making it
Holder.
"Original License" means this Artistic License as Distributed with
the Standard Version of the Package, in its current version or as
it may be modified by The Perl Foundation in the future.
"Source" form means the source code, documentation source, and
configuration files for the Package.
"Compiled" form means the compiled bytecode, object code, binary,
or any other form resulting from mechanical transformation or
translation of the Source form.
Permission for Use and Modification Without Distribution
(1) You are permitted to use the Standard Version and create and use
Modified Versions for any purpose without restriction, provided that
you do not Distribute the Modified Version.
Permissions for Redistribution of the Standard Version
(2) You may Distribute verbatim copies of the Source form of the
Standard Version of this Package in any medium without restriction,
either gratis or for a Distributor Fee, provided that you duplicate
all of the original copyright notices and associated disclaimers. At
your discretion, such verbatim copies may or may not include a
Compiled form of the Package.
(3) You may apply any bug fixes, portability changes, and other
modifications made available from the Copyright Holder. The resulting
Package will still be considered the Standard Version, and as such
will be subject to the Original License.
Distribution of Modified Versions of the Package as Source
(4) You may Distribute your Modified Version as Source (either gratis
or for a Distributor Fee, and with or without a Compiled form of the
Modified Version) provided that you clearly document how it differs
from the Standard Version, including, but not limited to, documenting
any non-standard features, executables, or modules, and provided that
you do at least ONE of the following:
(a) make the Modified Version available to the Copyright Holder
of the Standard Version, under the Original License, so that the
Copyright Holder may include your modifications in the Standard
Version.
(b) ensure that installation of your Modified Version does not
prevent the user installing or running the Standard Version. In
addition, the Modified Version must bear a name that is different
(c) allow anyone who receives a copy of the Modified Version to
make the Source form of the Modified Version available to others
under
(i) the Original License or
(ii) a license that permits the licensee to freely copy,
modify and redistribute the Modified Version using the same
licensing terms that apply to the copy that the licensee
received, and requires that the Source form of the Modified
Version, and of any works derived from it, be made freely
available in that license fees are prohibited but Distributor
Fees are allowed.
Distribution of Compiled Forms of the Standard Version
or Modified Versions without the Source
(5) You may Distribute Compiled forms of the Standard Version without
the Source, provided that you include complete instructions on how to
get the Source of the Standard Version. Such instructions must be
valid at the time of your distribution. If these instructions, at any
time while you are carrying out such distribution, become invalid, you
must provide new instructions on demand or cease further distribution.
If you provide valid instructions or cease distribution within thirty
days after you become aware that the instructions are invalid, then
you do not forfeit any of your rights under this license.
(6) You may Distribute a Modified Version in Compiled form without
the Source, provided that you comply with Section 4 with respect to
the Source of the Modified Version.
Aggregating or Linking the Package
(7) You may aggregate the Package (either the Standard Version or
Modified Version) with other packages and Distribute the resulting
aggregation provided that you do not charge a licensing fee for the
Package. Distributor Fees are permitted, and licensing fees for other
components in the aggregation are permitted. The terms of this license
apply to the use and Distribution of the Standard or Modified Versions
as included in the aggregation.
(8) You are permitted to link Modified and Standard Versions with
other works, to embed the Package in a larger work of your own, or to
build stand-alone binary or bytecode versions of applications that
include the Package, and Distribute the result without restriction,
provided the result does not expose a direct interface to the Package.
Items That are Not Considered Part of a Modified Version
(9) Works (including, but not limited to, modules and scripts) that
merely extend or make use of the Package, do not, by themselves, cause
the Package to be a Modified Version. In addition, such works are not
considered parts of the Package itself, and are not subject to the
terms of 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.
(14) Disclaimer of Warranty:
THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS
IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
"eg",
"examples",
"inc",
"share",
"t",
"xt"
]
},
"prereqs" : {
"configure" : {
"requires" : {
"Module::Build::Tiny" : "0.034"
}
},
"develop" : {
"requires" : {
"Dist::Milla" : "v1.0.15",
"Path::Tiny" : "0.096",
"Template::Perlish" : "1.52",
"Test::Pod" : "1.41"
}
},
"runtime" : {
"requires" : {
"HTTP::Tiny" : "0.070",
"IO::Socket::SSL" : "1.56",
"JSON::PP" : "0",
"Log::Any" : "1.045",
"Moo" : "2.003000",
"Net::SSLeay" : "1.49",
"Ouch" : "0.0410",
"perl" : "5.010"
}
},
"test" : {
"requires" : {
"Path::Tiny" : "0.096",
"Test::Exception" : "0.43",
"Test::More" : "0.88"
}
}
},
"release_status" : "stable",
"resources" : {
"bugtracker" : {
"web" : "https://github.com/polettix/AI-CleverbotIO/issues"
},
"homepage" : "https://github.com/polettix/AI-CleverbotIO",
"repository" : {
"type" : "git",
"url" : "https://github.com/polettix/AI-CleverbotIO.git",
"web" : "https://github.com/polettix/AI-CleverbotIO"
}
},
---
abstract: 'A Perl wrapper for the cleverbot.io API'
author:
- 'Flavio Poletti <polettix@cpan.org>'
build_requires:
Path::Tiny: '0.096'
Test::Exception: '0.43'
Test::More: '0.88'
configure_requires:
Module::Build::Tiny: '0.034'
dynamic_config: 0
generated_by: 'Dist::Zilla version 5.041, Dist::Milla version v1.0.15, CPAN::Meta::Converter version 2.150005'
license: artistic_2
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: AI-CleverbotIO
no_index:
directory:
- eg
- examples
- inc
- share
- t
- xt
requires:
HTTP::Tiny: '0.070'
IO::Socket::SSL: '1.56'
JSON::PP: '0'
Log::Any: '1.045'
Moo: '2.003000'
Net::SSLeay: '1.49'
Ouch: '0.0410'
perl: '5.010'
resources:
bugtracker: https://github.com/polettix/AI-CleverbotIO/issues
homepage: https://github.com/polettix/AI-CleverbotIO
repository: https://github.com/polettix/AI-CleverbotIO.git
version: '0.002'
x_contributors:
- 'Flavio Poletti <flavio@polettix.it>'
);
# 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
This module allows you to interact with the API served by
https://cleverbot.io.
ACCESSORS
key
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;
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.:
{
status => 'success',
response => 'Hullo'
}
create
my $answer = $obj->create();
my $other = $obj->create($other_nick);
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
requires 'perl', '5.010';
requires 'HTTP::Tiny', '0.070';
requires 'IO::Socket::SSL', '1.56'; # from HTTP::Tiny 0.070 docs
requires 'JSON::PP'; # core from 5.14, any should do
requires 'Log::Any', '1.045';
requires 'Moo', '2.003000';
requires 'Net::SSLeay', '1.49'; # from HTTP::Tiny 0.070 docs
requires 'Ouch', '0.0410';
on test => sub {
requires 'Test::More', '0.88';
requires 'Path::Tiny', '0.096';
requires 'Test::Exception', '0.43';
};
on develop => sub {
requires 'Path::Tiny', '0.096';
requires 'Template::Perlish', '1.52';
};
lib/AI/CleverbotIO.pm view on Meta::CPAN
}
sub ask {
my ($self, $question) = @_;
my %ps = (
key => $self->key,
text => $question,
user => $self->user,
);
$ps{nick} = $self->nick if $self->has_nick;
return $self->_parse_response(
$self->ua->post_form($self->endpoints->{ask}, \%ps));
}
sub create {
my $self = shift;
$self->nick(shift) if @_;
# build request parameters
my %ps = (
key => $self->key,
user => $self->user,
);
$ps{nick} = $self->nick if $self->has_nick && length $self->nick;
my $data =
$self->_parse_response(
$self->ua->post_form($self->endpoints->{create}, \%ps));
$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);
return $data if $response->{success};
ouch 400, $data->{status};
} ## end sub _parse_response
sub __decode_content {
my $response = shift;
my $encoded = $response->{content};
if (!$encoded) {
my $url = $response->{url} // '*unknown url, check HTTP::Tiny*';
ouch 500, "response status $response->{status}, nothing from $url)";
}
my $decoded = eval { decode_json($encoded) }
or ouch 500, "response status $response->{status}, exception: $@";
return $decoded;
} ## end sub __decode_content
1;
lib/AI/CleverbotIO.pod view on Meta::CPAN
);
# 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
This module allows you to interact with the API served by
L<https://cleverbot.io>.
=head1 ACCESSORS
=head2 key
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;
lib/AI/CleverbotIO.pod view on Meta::CPAN
=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.:
{
status => 'success',
response => 'Hullo'
}
=head2 create
my $answer = $obj->create();
my $other = $obj->create($other_nick);
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
t/01-basic.t view on Meta::CPAN
success
| Error:\ reference\ name\ already\ exists
)
\z
)}, 'create() outcome';
diag 'real nick: ' . $cleverbot->nick;
my $answer;
lives_ok {
$answer = $cleverbot->ask('Hi, I am ' . $cleverbot->nick)->{response};
}
'ask() lives';
like $answer, qr{(?imxs:[a-z])}, 'response has at least... one letter';
diag "received answer: $answer";
done_testing();
( run in 1.103 second using v1.01-cache-2.11-cpan-49f99fa48dc )