summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2009-12-14 11:50:44 +0100
committerfranck cuny <franck@lumberjaph.net>2009-12-14 11:50:44 +0100
commit199ebd27ee9bb66ed318ba9870b31f5ccf50887b (patch)
tree71dc5a23cd70ceef70ccd0c8f8ad1d59c07cc6d3
parentw r and dw can be set (diff)
downloadanyevent-riak-199ebd27ee9bb66ed318ba9870b31f5ccf50887b.tar.gz
add walk method
-rw-r--r--lib/AnyEvent/Riak.pm27
-rw-r--r--t/basic.t15
2 files changed, 41 insertions, 1 deletions
diff --git a/lib/AnyEvent/Riak.pm b/lib/AnyEvent/Riak.pm
index 9292d4b..0f9d66e 100644
--- a/lib/AnyEvent/Riak.pm
+++ b/lib/AnyEvent/Riak.pm
@@ -53,7 +53,7 @@ sub fetch {
     my ( $self, $bucket, $key, $r ) = @_;
     $r = $self->{r} || 2 if !$r;
     return $self->_request( 'GET',
-        $self->_build_uri( [ $bucket, $key ], { r =>  $r} ), '200' );
+        $self->_build_uri( [ $bucket, $key ], { r => $r } ), '200' );
 }
 
 sub store {
@@ -88,6 +88,25 @@ sub delete {
         $self->_build_uri( [ $bucket, $key ], { dw => $rw } ), 204 );
 }
 
+sub walk {
+    my ( $self, $bucket, $key, $spec ) = @_;
+    my $path = $self->_build_uri( [ $bucket, $key ] );
+    $path .= $self->_build_spec($spec);
+    return $self->_request( 'GET', $path, 200 );
+}
+
+sub _build_spec {
+    my ( $self, $spec ) = @_;
+    my $acc = '/';
+    foreach my $item (@$spec) {
+        $acc
+            .= ( $item->{bucket} || '_' ) . ','
+            . ( $item->{tag} || '_' ) . ','
+            . ( $item->{acc} || '_' ) . '/';
+    }
+    return $acc;
+}
+
 sub _build_uri {
     my ( $self, $path, $query ) = @_;
     my $uri = URI->new( $self->{host} );
@@ -155,6 +174,12 @@ AnyEvent::Riak - Non-blocking Riak client
 
 AnyEvent::Riak is a non-blocking riak client using anyevent.
 
+=head2 METHODS
+
+=over 4
+
+=back
+
 =head1 AUTHOR
 
 franck cuny E<lt>franck@lumberjaph.netE<gt>
diff --git a/t/basic.t b/t/basic.t
index cb011f7..ecb1d05 100644
--- a/t/basic.t
+++ b/t/basic.t
@@ -7,6 +7,8 @@ use AnyEvent::Riak;
 
 my $jiak = AnyEvent::Riak->new(
     host => 'http://127.0.0.1:8098',
+
+    #host => 'http://192.168.0.11:8098',
     path => 'jiak'
 );
 
@@ -32,4 +34,17 @@ ok $res = $jiak->delete( 'foo', 'bar' )->recv, '... delete our key';
 dies_ok { $jiak->fetch( 'foo', 'foo' )->recv } '... dies when error';
 like $@, qr/404/, '... 404 response';
 
+ok $res = $jiak->store($value)->recv, '... set a new key';
+my $second_value = {
+    bucket => 'foo',
+    key    => 'baz',
+    object => { foo => "bar", baz => 2 },
+    links  => [ [ 'foo', 'bar', 'tagged' ] ],
+};
+ok $res = $jiak->store($second_value)->recv, '... set another new key';
+
+ok $res = $jiak->walk( 'foo', 'baz', [ { bucket => 'foo', } ] )->recv,
+    '... walk';
+is $res->{results}->[0]->[0]->{key}, "bar", "... walked to bar";
+
 done_testing();