Module: Transmission::RPC::Client

Defined in:
lib/transmission-rpc/client.rb

Overview

This communicates with Transmission's RPC server. Transmission's RPC is just an HTTP server with a JSON API It implements part of the RPC 1.7.X spec

Constant Summary collapse

API_VERSION =
'1.7'

Class Method Summary collapse

Class Method Details

.connected?Boolean

Checks if we're connected to the Trasmission Daemon. If you're having problems, make sure you have the Transmission Daemon installed and then try running transmission-daemon -f in your shell

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
# File 'lib/transmission-rpc/client.rb', line 10

def self.connected?
	begin
		request("session-get")
		true
	rescue
		false
	end
end

.request(method, arguments = {}, ids = []) ⇒ Object

Sends out a request to Transmission's RPC server If you're curious about the formatting, read this



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

def self.request(method, arguments = {}, ids = [])
	arguments = self.add_ids(arguments, ids) if ids.present?
	begin
		@response = RestClient.post(self.url, { :method => method, :arguments => arguments }.to_json, :x_transmission_session_id => self.session_id)
		JSON.parse(@response.body)
	rescue
		puts "Couldn't connect to Transmission. Is Transmission running at http://#{Transmission.configuration.ip}:#{Transmission.configuration.port}?"
	end
end