| 1 | # | ||
| 2 | # $Id$ | ||
| 3 | # | ||
| 4 | # client::rest Brik | ||
| 5 | # | ||
| 6 | package Metabrik::Client::Rest; | ||
| 7 | 3 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 3 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 3 | ▶ | use base qw(Metabrik::Client::Www); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | sub brik_properties { | ||
| 13 | return { | ||
| 14 | revision => '$Revision$', | ||
| 15 | tags => [ qw(unstable http api) ], | ||
| 16 | author => 'GomoR <GomoR[at]metabrik.org>', | ||
| 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 | my $self = shift; | ||
| 51 | my ($output_mode) = @_; | ||
| 52 | |||
| 53 | my $last = $self->_last; | ||
| 54 | if (! defined($last)) { | ||
| 55 | return $self->log->error("content: no request has been made yet"); | ||
| 56 | } | ||
| 57 | |||
| 58 | my $sm; | ||
| 59 | $output_mode ||= $self->output_mode; | ||
| 60 | if ($output_mode eq 'json') { | ||
| 61 | $sm = Metabrik::String::Json->new_from_brik_init($self) or return; | ||
| 62 | } | ||
| 63 | elsif ($output_mode eq 'xml') { | ||
| 64 | $sm = Metabrik::String::Xml->new_from_brik_init($self) or return; | ||
| 65 | } | ||
| 66 | else { | ||
| 67 | 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 | return $sm->decode($last->decoded_content); | ||
| 72 | } | ||
| 73 | |||
| 74 | 1; | ||
| 75 | |||
| 76 | __END__ | ||