blob: 701af5d3fd90c7af91409922e9c1b17dba89057b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
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));
return $uri->as_string;
}
sub _build_headers {
my $self = shift;
my $headers = shift || {};
$headers->{'X-Riak-ClientId'} = $self->client_id;
$headers->{'Content-Type'} = 'application/json'
unless exists $headers->{'Content-Type'};
return $headers;
}
sub _build_query {
my ($self, $options) = @_;
my $valid_options = [qw/props keys returnbody w r dw/];
my $query;
foreach (@$valid_options) {
$query->{$_} = $options->{$_} if exists $options->{$_};
}
$query;
}
1;
|