Class: Transmission::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/transmission-connect/client.rb

Constant Summary collapse

SESSION_STAT_ARGS =
%w(activeTorrentCount downloadSpeed pausedTorrentCount torrentCount uploadSpeed cumulative-stats current-stats)
TORRENT_ARGS =
%w(downloadDir hashString id isFinished name percentDone status totalSize error errorString rateDownload rateUpload)
CHECK_WAIT =
1
CHECK =
2
DOWNLOAD =
4
SEED =
8
STOPPED =
16
STATUS =
{
    1 => :check_wait,
    2 => :check,
    4 => :download,
    8 => :seed,
    16 => :stopped
}

Instance Method Summary collapse

Constructor Details

#initialize(host = '127.0.0.1', port = 9091, username = nil, password = nil) ⇒ Client

Returns a new instance of Client.



20
21
22
23
24
# File 'lib/transmission-connect/client.rb', line 20

def initialize(host = '127.0.0.1', port = 9091, username = nil, password = nil)
  @header = username.nil? ? {} : {'Authorization' => Base64.encode64("#{username}:#{password}")}
  @uri = URI.parse("http://#{host}:#{port}/#{RPC_PATH}")
  new_connection
end

Instance Method Details

#add_bt_magnet(hash) ⇒ Object



34
35
36
37
# File 'lib/transmission-connect/client.rb', line 34

def add_bt_magnet(hash)
  hash = "magnet:?xt=urn:btih:#{hash}"
  request('torrent-add', {:filename => hash})
end

#get_info(hash = nil) ⇒ Object



51
52
53
54
55
# File 'lib/transmission-connect/client.rb', line 51

def get_info(hash = nil)
  args = hash.nil? ? {} : {:ids => hash.to_a}
  args = {:fields => TORRENT_ARGS}.merge(args)
  request('torrent-get', args)
end

#new_connectionObject



26
27
28
# File 'lib/transmission-connect/client.rb', line 26

def new_connection
  @connection = Net::HTTP.start(@uri.host, @uri.port)
end

#pause_magnet(hash) ⇒ Object



43
44
45
# File 'lib/transmission-connect/client.rb', line 43

def pause_magnet(hash)
  request('torrent-stop', {:ids => hash.to_a})
end

#rem_bt_magnet(hash) ⇒ Object



39
40
41
# File 'lib/transmission-connect/client.rb', line 39

def rem_bt_magnet(hash)
  request('torrent-remove', {:ids => hash.to_a, 'delete-local-data' => true})
end

#session_stats(args = {}) ⇒ Object



30
31
32
# File 'lib/transmission-connect/client.rb', line 30

def session_stats(args = {})
  request('session-stats', args)
end

#unpause_magnet(hash) ⇒ Object



47
48
49
# File 'lib/transmission-connect/client.rb', line 47

def unpause_magnet(hash)
  request('torrent-start', {:ids => hash.to_a})
end