From 79656128704e907d2b33f648dd0b53cb599e9bb6 Mon Sep 17 00:00:00 2001 From: bilalghouri Date: Sun, 19 Oct 2014 15:28:44 +0500 Subject: [PATCH] Update ResponseValidator.php Issue #35 I debugged the behaviour, the response from transmission rpc was fine, it was sending result object as "duplicate torrent" and argument object was empty. the validator for addtorrent was parsing it as invalid because of absence of torrent-duplicate object inside arguments. I have fixed it and requested a pull. --- lib/Transmission/Util/ResponseValidator.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/Transmission/Util/ResponseValidator.php b/lib/Transmission/Util/ResponseValidator.php index ee5a1b7..fcb98bc 100644 --- a/lib/Transmission/Util/ResponseValidator.php +++ b/lib/Transmission/Util/ResponseValidator.php @@ -59,7 +59,18 @@ public static function validateGetResponse(\stdClass $response) */ public static function validateAddResponse(\stdClass $response) { - $fields = array('torrent-added', 'torrent-duplicate'); + // fix for issue #35 + if ($response -> result == 'success' && + isset ($response->arguments -> {torrent-added}) && + count($response->arguments -> {torrent-added})) + { + return $response->arguments -> {torrent-added}; + } + if ($response -> result == 'duplicate torrent') + return $response -> result; + + + /*$fields = array('torrent-added', 'torrent-duplicate'); foreach ($fields as $field) { if (isset($response->arguments) && @@ -67,7 +78,7 @@ public static function validateAddResponse(\stdClass $response) count($response->arguments->$field)) { return $response->arguments->$field; } - } + }*/ throw new \RuntimeException('Invalid response received from Transmission'); }