Skip to content

Commit

Permalink
Handle plaintext results if requested
Browse files Browse the repository at this point in the history
  • Loading branch information
mickenordin authored Feb 15, 2017
1 parent 5c63924 commit 84a6967
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions SU/API/Icinga2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ sub new {
};

sub do_request {
my ($self,$method,$uri,$params,$data) = @_;
my ($self,$method,$uri,$params,$data, $plaintext) = @_;

my $request_url;
$request_url = "$self->{url}/${uri}";
Expand All @@ -59,9 +59,17 @@ sub do_request {
if (!$self->{res}->is_success) {
return undef;
};

# Try with first plaintext if plaintext is set
if($plaintext) {
my $str = encode_utf8($self->{res}->content);
if($str) {
return $str;
}
}

# Handle non utf8 chars
my $json_result = decode_json(encode_utf8($self->{res}->content));

if ($json_result) {
return $json_result;
};
Expand Down

0 comments on commit 84a6967

Please sign in to comment.