line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# client::rest Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Client::Rest; |
7
|
3
|
|
|
3
|
|
25
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
85
|
|
8
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
79
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
14
|
use base qw(Metabrik::Client::Www); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1609
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable http api) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
attributes => { |
19
|
|
|
|
|
|
|
uri => [ qw(uri) ], # Inherited |
20
|
|
|
|
|
|
|
username => [ qw(username) ], # Inherited |
21
|
|
|
|
|
|
|
password => [ qw(password) ], # Inherited |
22
|
|
|
|
|
|
|
ssl_verify => [ qw(0|1) ], # Inherited |
23
|
|
|
|
|
|
|
output_mode => [ qw(json|xml) ], |
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
attributes_default => { |
26
|
|
|
|
|
|
|
output_mode => 'json', |
27
|
|
|
|
|
|
|
}, |
28
|
|
|
|
|
|
|
commands => { |
29
|
|
|
|
|
|
|
reset_user_agent => [ ], |
30
|
|
|
|
|
|
|
get => [ qw(uri|OPTIONAL username|OPTIONAL password|OPTIONAL) ], |
31
|
|
|
|
|
|
|
post => [ qw(content_hash uri|OPTIONAL username|OPTIONAL password|OPTIONAL) ], |
32
|
|
|
|
|
|
|
patch => [ qw(content_hash uri|OPTIONAL username|OPTIONAL password|OPTIONAL) ], |
33
|
|
|
|
|
|
|
put => [ qw(content_hash uri|OPTIONAL username|OPTIONAL password|OPTIONAL) ], |
34
|
|
|
|
|
|
|
head => [ qw(uri|OPTIONAL username|OPTIONAL password|OPTIONAL) ], |
35
|
|
|
|
|
|
|
delete => [ qw(uri|OPTIONAL username|OPTIONAL password|OPTIONAL) ], |
36
|
|
|
|
|
|
|
options => [ qw(uri|OPTIONAL username|OPTIONAL password|OPTIONAL) ], |
37
|
|
|
|
|
|
|
code => [ ], |
38
|
|
|
|
|
|
|
content => [ qw(output_mode|OPTIONAL) ], |
39
|
|
|
|
|
|
|
get_content => [ qw(uri|OPTIONAL username|OPTIONAL password|OPTIONAL) ], |
40
|
|
|
|
|
|
|
post_content => [ qw(content_hash uri|OPTIONAL username|OPTIONAL password|OPTIONAL) ], |
41
|
|
|
|
|
|
|
}, |
42
|
|
|
|
|
|
|
require_modules => { |
43
|
|
|
|
|
|
|
'Metabrik::String::Xml' => [ ], |
44
|
|
|
|
|
|
|
'Metabrik::String::Json' => [ ], |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub content { |
50
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
51
|
0
|
|
|
|
|
|
my ($output_mode) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $last = $self->_last; |
54
|
0
|
0
|
|
|
|
|
if (! defined($last)) { |
55
|
0
|
|
|
|
|
|
return $self->log->error("content: no request has been made yet"); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $sm; |
59
|
0
|
|
0
|
|
|
|
$output_mode ||= $self->output_mode; |
60
|
0
|
0
|
|
|
|
|
if ($output_mode eq 'json') { |
|
|
0
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
$sm = Metabrik::String::Json->new_from_brik_init($self) or return; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
elsif ($output_mode eq 'xml') { |
64
|
0
|
0
|
|
|
|
|
$sm = Metabrik::String::Xml->new_from_brik_init($self) or return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
else { |
67
|
0
|
|
|
|
|
|
return $self->log->error("content: output_mode not supported [$output_mode]"); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# We must decode content cause it may be gzipped, for instance. |
71
|
0
|
|
|
|
|
|
return $sm->decode($last->decoded_content); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |