lib/transmission/rpc/connector.rb in transmission-rpc-ruby-0.1.0 vs lib/transmission/rpc/connector.rb in transmission-rpc-ruby-0.2.0

- old
+ new

@@ -4,11 +4,10 @@ module Transmission class RPC class Connector class AuthError < StandardError; end class ConnectionError < StandardError; end - class InvalidSessionError < StandardError; end attr_accessor :host, :port, :ssl, :credentials, :path, :session_id, :response def initialize(options = {}) @host = options[:host] || 'localhost' @@ -24,25 +23,25 @@ req.url @path req.headers['X-Transmission-Session-Id'] = @session_id req.headers['Content-Type'] = 'application/json' req.body = JSON.generate(params) end - handle_response response + handle_response response, params end private def json_body(response) JSON.parse response.body rescue {} end - def handle_response(response) + def handle_response(response, params) @response = response if response.status == 409 @session_id = response.headers['x-transmission-session-id'] - raise InvalidSessionError + return self.post(params) end body = json_body response raise AuthError if response.status == 401 raise ConnectionError, body['result'] unless response.status == 200 && body['result'] == 'success' body['arguments'] \ No newline at end of file