Class: Transmission::RPC::Connector

Inherits:
Object
  • Object
show all
Defined in:
lib/transmission/rpc/connector.rb

Defined Under Namespace

Classes: AuthError, ConnectionError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Connector

Returns a new instance of Connector.



12
13
14
15
16
17
18
19
# File 'lib/transmission/rpc/connector.rb', line 12

def initialize(options = {})
  @host = options[:host] || 'localhost'
  @port = options[:port] || 9091
  @ssl  = !!options[:ssl]
  @credentials = options[:credentials] || nil
  @path = options[:path] || '/transmission/rpc'
  @session_id = options[:session_id] || ''
end

Instance Attribute Details

#credentialsObject

Returns the value of attribute credentials.



10
11
12
# File 'lib/transmission/rpc/connector.rb', line 10

def credentials
  @credentials
end

#hostObject

Returns the value of attribute host.



10
11
12
# File 'lib/transmission/rpc/connector.rb', line 10

def host
  @host
end

#pathObject

Returns the value of attribute path.



10
11
12
# File 'lib/transmission/rpc/connector.rb', line 10

def path
  @path
end

#portObject

Returns the value of attribute port.



10
11
12
# File 'lib/transmission/rpc/connector.rb', line 10

def port
  @port
end

#responseObject

Returns the value of attribute response.



10
11
12
# File 'lib/transmission/rpc/connector.rb', line 10

def response
  @response
end

#session_idObject

Returns the value of attribute session_id.



10
11
12
# File 'lib/transmission/rpc/connector.rb', line 10

def session_id
  @session_id
end

#sslObject

Returns the value of attribute ssl.



10
11
12
# File 'lib/transmission/rpc/connector.rb', line 10

def ssl
  @ssl
end

Instance Method Details

#post(params = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/transmission/rpc/connector.rb', line 21

def post(params = {})
  response = connection.post do |req|
    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, params
end