From 898fc6cd1834ef9fb6e9dfbd4572dbe0a20cf8f5 Mon Sep 17 00:00:00 2001
From: Anton Soldatov <igelhaus@gmail.com>
Date: Mon, 28 Apr 2014 14:35:17 +0400
Subject: [PATCH] Fixed issues with handling `expect_single_object`

---
 lib/WebService/Redmine.pm | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/WebService/Redmine.pm b/lib/WebService/Redmine.pm
index d617567..d7d4a46 100644
--- a/lib/WebService/Redmine.pm
+++ b/lib/WebService/Redmine.pm
@@ -362,7 +362,8 @@ sub _response
 	}
 
 	if ($self->{expect_single_object} && $self->{no_wrapper_object}) {
-		$content = delete $content->{$self->{expect_single_object}};
+		my @key  = grep { !/^(total_count|offset|limit)$/ } keys %$content;
+		$content = delete $content->{$key[0]} if @key == 1;
 	}
 
 	return $content;
@@ -411,7 +412,9 @@ sub _dispatch_name
 		}
 		$data->{content} = pop @args;
 	}
-
+	
+	delete $self->{expect_single_object};
+	
 	$objects = $self->_normalize_objects($objects);
 	my $i = 0;
 	my @objects;
@@ -453,11 +456,9 @@ sub _dispatch_last_object
 	my $object = shift;
 	my $data   = shift;
 
-	delete $self->{expect_single_object};
-
 	if (length $object) {
 		if ($action eq 'get' || $action eq 'create') {
-			$self->{expect_single_object} = $object;
+			$self->{expect_single_object} = 1;
 		}
 		if ($self->{no_wrapper_object}) {
 			if ($action eq 'create' || $action eq 'update') {
-- 
GitLab