Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

support clientId

  • Loading branch information...
commit 72ccd2cc937333bde76cb8091c45acb45ce9c4c1 1 parent fcc8055
@trung authored
Showing with 44 additions and 6 deletions.
  1. +18 −2 README
  2. +22 −4 lib/AnyEvent/Riak.pm
  3. +4 −0 t/basic.t
View
20 README
@@ -1,13 +1,28 @@
This is Perl module AnyEvent::Riak.
+============
INSTALLATION
+============
+
+CPAN
+====
+
+Noted: I haven't uploaded to CPAN, please proceed to Build section
AnyEvent::Riak installation is straightforward. If your CPAN shell is set up,
you should just be able to do
% cpan AnyEvent::Riak
-Download it, unpack it, then build it as per the usual:
+Build
+=====
+
+If you wish to run test cases, you will need to set your environment variable
+ % export RIAK_TEST_SERVER=http://localhost:8098;riak
+
+Noted: it's semicolon (;), not slash (/)
+
+Download the source, unpack it, then build it as per the usual:
% perl Makefile.PL
% make && make test
@@ -16,8 +31,9 @@ Then install it:
% make install
+=============
DOCUMENTATION
-
+=============
AnyEvent::Riak documentation is available as in POD. So you can do:
% perldoc AnyEvent::Riak
View
26 lib/AnyEvent/Riak.pm
@@ -6,18 +6,23 @@ use URI;
use JSON::XS;
use AnyEvent;
use AnyEvent::HTTP;
+use Data::UUID;
-our $VERSION = '0.01';
+our $VERSION = '0.02';
sub new {
my ( $class, %args ) = @_;
+ my $uuid = Data::UUID->new;
+
my $host = delete $args{host} || 'http://127.0.0.1:8098';
- my $path = delete $args{path} || 'jiak';
+ my $path = delete $args{path} || 'riak';
+ my $clientId = delete $args{clientId} || $uuid->create_b64;
bless {
host => $host,
path => $path,
+ clientId => $clientId,
%args,
}, $class;
}
@@ -95,6 +100,11 @@ sub walk {
return $self->_request( 'GET', $path, 200 );
}
+sub get_clientId {
+ my ($self) = @_;
+ return $self->{clientId};
+}
+
sub _build_spec {
my ( $self, $spec ) = @_;
my $acc = '/';
@@ -133,7 +143,7 @@ sub _request {
if ($body) {
http_request(
$method => $uri,
- headers => { 'Content-Type' => 'application/json', },
+ headers => $self->_build_headers,
body => $body,
$cb
);
@@ -141,13 +151,21 @@ sub _request {
else {
http_request(
$method => $uri,
- headers => { 'Content-Type' => 'application/json', },
+ headers => $self->_build_headers,
$cb
);
}
$cv;
}
+sub _build_headers {
+ my ($self) = @_;
+ return {
+ 'Content-Type' => 'application/json',
+ 'X-Riak-ClientId' => $self->{clientId},
+ };
+}
+
1;
__END__
View
4 t/basic.t
@@ -16,6 +16,10 @@ BEGIN {
my $jiak = AnyEvent::Riak->new( host => $host, path => $path );
+ok my $clientId = $jiak->get_clientId, "... get clientId";
+
+ok defined $clientId, "... clientId defined. Value is $clientId";
+
ok my $buckets = $jiak->list_bucket('bar')->recv, "... fetch bucket list";
is scalar @{ $buckets->{keys} }, '0', '... no keys';
Please sign in to comment.
Something went wrong with that request. Please try again.