diff options
author | franck cuny <franck@lumberjaph.net> | 2010-05-11 11:22:58 +0200 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-06-08 08:02:41 +0200 |
commit | e71ee6fc097b832df6808a4a97f89029d971e196 (patch) | |
tree | 65ce4819db1b2ddc104cd20c5d70e5d4136d3920 /lib/AnyEvent/Riak/Role/HTTPUtils.pm | |
parent | update tests (diff) | |
download | anyevent-riak-e71ee6fc097b832df6808a4a97f89029d971e196.tar.gz |
switch to dzil; rename tests; update changelog
Diffstat (limited to 'lib/AnyEvent/Riak/Role/HTTPUtils.pm')
-rw-r--r-- | lib/AnyEvent/Riak/Role/HTTPUtils.pm | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/AnyEvent/Riak/Role/HTTPUtils.pm b/lib/AnyEvent/Riak/Role/HTTPUtils.pm index 399f369..701af5d 100644 --- a/lib/AnyEvent/Riak/Role/HTTPUtils.pm +++ b/lib/AnyEvent/Riak/Role/HTTPUtils.pm @@ -1,15 +1,23 @@ package AnyEvent::Riak::Role::HTTPUtils; +# ABSTRACT: HTTP methods + use Moose::Role; use AnyEvent; use AnyEvent::HTTP; use URI; - use MIME::Base64; +has client_id => (is => 'rw', isa => 'Str', lazy_build => 1,); + +sub _build_client_id { + "perl_anyevent_riak" . encode_base64(int(rand(10737411824)), ''); +} + sub _build_uri { my ($self, $path, $options) = @_; + my $uri = URI->new($self->host); $uri->path(join("/", @$path)); $uri->query_form($self->_build_query($options)); @@ -17,8 +25,8 @@ sub _build_uri { } sub _build_headers { - my ($self, $options) = @_; - my $headers = delete $options->{headers} || {}; + my $self = shift; + my $headers = shift || {}; $headers->{'X-Riak-ClientId'} = $self->client_id; $headers->{'Content-Type'} = 'application/json' @@ -28,7 +36,7 @@ sub _build_headers { sub _build_query { my ($self, $options) = @_; - my $valid_options = [qw/props keys returnbody/]; + my $valid_options = [qw/props keys returnbody w r dw/]; my $query; foreach (@$valid_options) { $query->{$_} = $options->{$_} if exists $options->{$_}; |