Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

support clientId

  • Loading branch information...
commit 72ccd2cc937333bde76cb8091c45acb45ce9c4c1 1 parent fcc8055
Nguyen Kien Trung authored

Showing 3 changed files with 44 additions and 6 deletions. Show diff stats Hide diff stats

  1. +18 2 README
  2. +22 4 lib/AnyEvent/Riak.pm
  3. +4 0 t/basic.t
20 README
... ... @@ -1,13 +1,28 @@
1 1 This is Perl module AnyEvent::Riak.
2 2
  3 +============
3 4 INSTALLATION
  5 +============
  6 +
  7 +CPAN
  8 +====
  9 +
  10 +Noted: I haven't uploaded to CPAN, please proceed to Build section
4 11
5 12 AnyEvent::Riak installation is straightforward. If your CPAN shell is set up,
6 13 you should just be able to do
7 14
8 15 % cpan AnyEvent::Riak
9 16
10   -Download it, unpack it, then build it as per the usual:
  17 +Build
  18 +=====
  19 +
  20 +If you wish to run test cases, you will need to set your environment variable
  21 + % export RIAK_TEST_SERVER=http://localhost:8098;riak
  22 +
  23 +Noted: it's semicolon (;), not slash (/)
  24 +
  25 +Download the source, unpack it, then build it as per the usual:
11 26
12 27 % perl Makefile.PL
13 28 % make && make test
@@ -16,8 +31,9 @@ Then install it:
16 31
17 32 % make install
18 33
  34 +=============
19 35 DOCUMENTATION
20   -
  36 +=============
21 37 AnyEvent::Riak documentation is available as in POD. So you can do:
22 38
23 39 % perldoc AnyEvent::Riak
26 lib/AnyEvent/Riak.pm
@@ -6,18 +6,23 @@ use URI;
6 6 use JSON::XS;
7 7 use AnyEvent;
8 8 use AnyEvent::HTTP;
  9 +use Data::UUID;
9 10
10   -our $VERSION = '0.01';
  11 +our $VERSION = '0.02';
11 12
12 13 sub new {
13 14 my ( $class, %args ) = @_;
14 15
  16 + my $uuid = Data::UUID->new;
  17 +
15 18 my $host = delete $args{host} || 'http://127.0.0.1:8098';
16   - my $path = delete $args{path} || 'jiak';
  19 + my $path = delete $args{path} || 'riak';
  20 + my $clientId = delete $args{clientId} || $uuid->create_b64;
17 21
18 22 bless {
19 23 host => $host,
20 24 path => $path,
  25 + clientId => $clientId,
21 26 %args,
22 27 }, $class;
23 28 }
@@ -95,6 +100,11 @@ sub walk {
95 100 return $self->_request( 'GET', $path, 200 );
96 101 }
97 102
  103 +sub get_clientId {
  104 + my ($self) = @_;
  105 + return $self->{clientId};
  106 +}
  107 +
98 108 sub _build_spec {
99 109 my ( $self, $spec ) = @_;
100 110 my $acc = '/';
@@ -133,7 +143,7 @@ sub _request {
133 143 if ($body) {
134 144 http_request(
135 145 $method => $uri,
136   - headers => { 'Content-Type' => 'application/json', },
  146 + headers => $self->_build_headers,
137 147 body => $body,
138 148 $cb
139 149 );
@@ -141,13 +151,21 @@ sub _request {
141 151 else {
142 152 http_request(
143 153 $method => $uri,
144   - headers => { 'Content-Type' => 'application/json', },
  154 + headers => $self->_build_headers,
145 155 $cb
146 156 );
147 157 }
148 158 $cv;
149 159 }
150 160
  161 +sub _build_headers {
  162 + my ($self) = @_;
  163 + return {
  164 + 'Content-Type' => 'application/json',
  165 + 'X-Riak-ClientId' => $self->{clientId},
  166 + };
  167 +}
  168 +
151 169 1;
152 170 __END__
153 171
4 t/basic.t
@@ -16,6 +16,10 @@ BEGIN {
16 16
17 17 my $jiak = AnyEvent::Riak->new( host => $host, path => $path );
18 18
  19 +ok my $clientId = $jiak->get_clientId, "... get clientId";
  20 +
  21 +ok defined $clientId, "... clientId defined. Value is $clientId";
  22 +
19 23 ok my $buckets = $jiak->list_bucket('bar')->recv, "... fetch bucket list";
20 24 is scalar @{ $buckets->{keys} }, '0', '... no keys';
21 25

0 comments on commit 72ccd2c

Please sign in to comment.
Something went wrong with that request. Please try again.