1 package Arvados::Request;
7 @Arvados::HTTP::ISA = qw(LWP::UserAgent);
13 bless ($self, $class);
14 return $self->_init(@_);
20 $self->{'ua'} = new LWP::UserAgent(@_);
21 $self->{'ua'}->agent ("libarvados-perl/".$Arvados::VERSION);
28 $self->{'uri'} = shift;
35 $req{$self->{'method'}} = $self->{'uri'};
36 $self->{'req'} = new HTTP::Request (%req);
37 $self->{'req'}->header('Authorization' => ('OAuth2 ' . $self->{'authToken'})) if $self->{'authToken'};
38 $self->{'req'}->header('Accept' => 'application/json');
41 while (($p, $v) = each %{$self->{'queryParams'}}) {
42 $content{$p} = (ref($v) eq "") ? $v : JSON::encode_json($v);
45 while (($p, $v) = each %content) {
46 $content .= '&' unless $content eq '';
47 $content .= uri_escape($p);
49 $content .= uri_escape($v);
51 $self->{'req'}->content_type("application/x-www-form-urlencoded; charset='utf8'");
52 $self->{'req'}->content(Encode::encode('utf8', $content));
53 $self->{'res'} = $self->{'ua'}->request ($self->{'req'});
59 return ($self->{'res'}->code(),
60 $self->{'res'}->message());
66 return $self->{'res'}->content;
72 $self->{'method'} = shift;
78 $self->{'queryParams'} = shift;
84 $self->{'authToken'} = shift;