sub Imgur::API::request { package Imgur::API; { my ($this,$path,$method,$params) = @_; $params->{_format}="json"; $this->ua->agent("Imgur::API/0.0,1"); my $auth; if ($this->access_token) { $auth="Bearer ".$this->access_token; } else { $auth="Client-ID ".$this->client_id; } say STDERR $auth; my $response; if ($method=~/(?:post|put)/) { $response = $this->ua->$method($path,$params,'Authorization'=>$auth); } else { $response = $this->ua->$method($path,'Authorization'=>$auth); } say Dumper($response); if ($response->content_type eq "application/json") { $this->stats->update($response); my $json = JSON::XS::decode_json($response->decoded_content); if (!$json->{success}) { my $e = Imgur::API::Exception->new(code=>$json->{status},message=>$json->{data}->{error}); say Dumper($json); say "BUG!!\n"; return $e; } return Imgur::API::Response->new($json); } else { return Imgur::API::Exception->new(code=>$response->code,message=>$response->status_line); } }