NAME
WWW::KeenIO - Perl API for Keen.IO http://keen.io event storage and analytics
VERSION
Version 0.01
SYNOPSIS
use WWW::KeenIO qw(:operators);
use Text::CSV_XS;
use Data::Dumper;
my $csv = Text::CSV_XS->new;
my $keen = WWW::KeenIO->new( {
project => '123',
api_key => '456',
write_key => '789'
}) or die 'Cannot create KeenIO object';
# process a CSV file with 3 columns: name, in|out, date-time
# import them as keenIO events
while(<>) {
chomp;
my $status = $csv->parse($_);
unless ($status) {
warn qq{Cannot parse '$_':}.$csv->error_diag();
next;
}
my @fields = $csv->fields();
my $data = {
keen => {
timestamp => $fields[2]
},
name => $fields[0],
type => $fields[1]
};
my $res = $keen->put('in_out_log', $data);
unless ($res) {
warn "Unable to store the data in keenIO";
}
}
# now read the data
my $data = $keen->select('in_out_log', 'this_7_days',
[ $keen->filter('name', $KEEN_OP_EQ, 'John Doe') ] );
print Dumper($data);
CONSTRUCTOR
new( hashref )
Creates a new object, acceptable parameters are:
api_key
- (required) the key to be used for read operationsproject
- (required) the ID of KeenIO projectwrite_key
- the key to be used for write operations (if different from api_key)base_url
- https://api.keen.io/3.0/ by default; in case if you are using KeenIO-compatible API on some other server you can specify your own URL here
METHODS
put( $collection_name, $data )
Inserts an event ($data
is a hashref) into the collection. Returns a reference to a hash, which contains the response received from the server (typically there is a key created
with true
value). Returns undef
on failure, application then may call error_message()
method to get the detailed info about the error.
my $res = $keen->put('in_out_log', $data);
unless ($res) {
warn 'Something went wrong '.$keen->error_message();
}
batch_put( $data )
Inserts multiple events into Keen. $data
is a hashref, where every key represents a collection name, where data should be inserted. Value of the key is a reference to an array, which contains references to individual event data (hashes).
Returns undef
on total failure (e.g. unable to access the servers). Otherwise returns a reference to a hash; each key represents a collection name and the value is a reference to an array of statuses for individual events.
my $res = $keen->batch_put( {
payments => [
{
name => 'John Doe',
customer_id => 123,
amount => 35.00
},
{
name => 'Peter Smith',
customer_id => 125,
amount => '10.00'
}
],
purchases => [
{
name => 'John Doe',
customer_id => 123,
product_id => 567,
quantity => 1,
date => '2015-11-01 15:06:34'
}
]
});
unless ($res) {
warn 'Something went wrong '.$keen->error_message();
}
get($collection_name, $interval [, $filters ] )
Retrieves a list of events from the collection. $collection_name
is self-explanatory. $interval
is a string, which describes the time period we are interested in (see https://keen.io/docs/api/#timeframe)). $filters
is optional. If provided - should be an arrayref, each element is an additional condition according to https://keen.io/docs/api/#query-parameters.
Returns a reference to an array on hashrefs; each element is a reference to an actual events. Upon failure returns undef
.
my $data = $keen->select('in_out_log', 'this_7_days',
[ $keen->filter('name', $KEEN_OP_EQ, 'John Doe') ]);
print Dumper($data);
filter($field, $operator, $value)
Creates a filter for retrieving events via select() method.
use WWW::KeenIO qw(:operators);
my $res = $keen->select('tests', 'this_10_years', [
$keen->filter('Author', $KEEN_OP_CONTAINS, 'Andrew'),
$keen->filter('Status', $KEEN_OP_EQ, 'resolved')
] );
Please refer to Keen API documentation regarding all available operators and their usage. For convenience constants for most frequently used operators are exported via :operators tag: $KEEN_OP_EQ, $KEEN_OP_NE, $KEEN_OP_EXISTS, $KEEN_OP_IN, $KEEN_OP_CONTAINS
error_message()
Returns the detailed explanation of the last error. Empty string if everything went fine.
my $res = $keen->put('in_out_log', $data);
unless ($res) {
warn 'Something went wrong '.$keen->error_message();
}
AUTHOR
Andrew Zhilenko, <perl at putinhuylo.org>
(c) Putin Huylo LLC, 2015
BUGS
Please report any bugs or feature requests to bug-www-keenio at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-KeenIO. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc WWW::KeenIO
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
LICENSE AND COPYRIGHT
Copyright 2015 Putin Huylo LLC
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:
http://www.perlfoundation.org/artistic_license_2_0
Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.
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.
This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.
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.
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.