Class: Transmission::RPC::Torrent

Inherits:
Object
  • Object
show all
Includes:
Transmission::RPC
Defined in:
lib/transmission-rpc/torrent.rb

Overview

A nice wrapper around Transmission’s RPC

Constant Summary

Constants included from Transmission::RPC

VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Torrent

Returns a new instance of Torrent.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/transmission-rpc/torrent.rb', line 8

def initialize(options = {})
	self.id 				 	  = options['id']
	self.date_added 	  = options['addedDate']
	self.comment 			  = options['comment']
	self.eta 					  = options['eta']
	self.bytes_left 	  = options['leftUntilDone'] 
	self.name           = options['name']
	self.percent_done   = options['percentDone']
	self.torrent_file   = options['torrentFile']
	self.total_size     = options['totalSize']
	self.hash  				  = options['hashString']
	self.status 			  = options['status']
	self.download_speed = options['rateDownload']
end

Instance Attribute Details

#bytes_leftObject

Returns the value of attribute bytes_left.



5
6
7
# File 'lib/transmission-rpc/torrent.rb', line 5

def bytes_left
  @bytes_left
end

#commentObject

Returns the value of attribute comment.



5
6
7
# File 'lib/transmission-rpc/torrent.rb', line 5

def comment
  @comment
end

#date_addedObject

Returns the value of attribute date_added.



5
6
7
# File 'lib/transmission-rpc/torrent.rb', line 5

def date_added
  @date_added
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/transmission-rpc/torrent.rb', line 5

def description
  @description
end

#download_directoryObject

Returns the value of attribute download_directory.



5
6
7
# File 'lib/transmission-rpc/torrent.rb', line 5

def download_directory
  @download_directory
end

#download_speedObject

Returns the value of attribute download_speed.



5
6
7
# File 'lib/transmission-rpc/torrent.rb', line 5

def download_speed
  @download_speed
end

#etaObject

Returns the value of attribute eta.



5
6
7
# File 'lib/transmission-rpc/torrent.rb', line 5

def eta
  @eta
end

#filesObject

Returns the value of attribute files.



5
6
7
# File 'lib/transmission-rpc/torrent.rb', line 5

def files
  @files
end

#hashObject

Returns the value of attribute hash.



5
6
7
# File 'lib/transmission-rpc/torrent.rb', line 5

def hash
  @hash
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/transmission-rpc/torrent.rb', line 5

def id
  @id
end

#leechersObject

Returns the value of attribute leechers.



5
6
7
# File 'lib/transmission-rpc/torrent.rb', line 5

def leechers
  @leechers
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/transmission-rpc/torrent.rb', line 5

def name
  @name
end

#percent_doneObject

Returns the value of attribute percent_done.



5
6
7
# File 'lib/transmission-rpc/torrent.rb', line 5

def percent_done
  @percent_done
end

#seedersObject

Returns the value of attribute seeders.



5
6
7
# File 'lib/transmission-rpc/torrent.rb', line 5

def seeders
  @seeders
end

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/transmission-rpc/torrent.rb', line 5

def status
  @status
end

#torrent_fileObject

Returns the value of attribute torrent_file.



5
6
7
# File 'lib/transmission-rpc/torrent.rb', line 5

def torrent_file
  @torrent_file
end

#total_sizeObject

Returns the value of attribute total_size.



5
6
7
# File 'lib/transmission-rpc/torrent.rb', line 5

def total_size
  @total_size
end

Class Method Details

.+(url) ⇒ Object

Adds a torrent by URL or file path



49
50
51
# File 'lib/transmission-rpc/torrent.rb', line 49

def self.+(url)
	self.add(:url => url)
end

.add(options = {}) ⇒ Object

Adds a torrent by file path or URL (.torrent file’s only right now)



71
72
73
74
75
76
77
78
# File 'lib/transmission-rpc/torrent.rb', line 71

def self.add(options = {})
	@response = Client.request("torrent-add", :filename => options[:url])
	if @response['result'] == 'success'
		self.find(@response['arguments']['torrent-added']['id'])
	else
		nil
	end
end

.allObject

Gets all the torrents



54
55
56
57
# File 'lib/transmission-rpc/torrent.rb', line 54

def self.all
	@unprocessed_torrents = Client.request("torrent-get", { :fields => self.fields })['arguments']['torrents']
	@unprocessed_torrents.collect { |torrent| self.new(torrent) }				
end

.find(id) ⇒ Object

Finds a torrent by ID



60
61
62
63
64
65
66
67
68
# File 'lib/transmission-rpc/torrent.rb', line 60

def self.find(id)
	@unprocessed_response = Client.request("torrent-get", { :fields => self.fields }, [id])
	@torrents = @unprocessed_response['arguments']['torrents']
	if @torrents.count > 0
		return self.new(@torrents.first)
	else
		return nil
	end
end

.start!Object

Starts all torrents



81
82
83
# File 'lib/transmission-rpc/torrent.rb', line 81

def self.start!
	Client.request "torrent-start"
end

.stop!Object

Stops all torrents



86
87
88
# File 'lib/transmission-rpc/torrent.rb', line 86

def self.stop!
	Client.request "torrent-stop"
end

Instance Method Details

#delete!(delete_data = false) ⇒ Object

Deletes the current torrent, and, optionally, the data for that torrent



34
35
36
# File 'lib/transmission-rpc/torrent.rb', line 34

def delete!(delete_data = false)
	Client.request("torrent-remove", { :delete_local_data => delete_data }, [self.id])
end

#downloading?Boolean

Checks if torrent is currently downloading

Returns:

  • (Boolean)


39
40
41
# File 'lib/transmission-rpc/torrent.rb', line 39

def downloading?
	self.status == 4
end

#paused?Boolean

Checks if torrent is paused

Returns:

  • (Boolean)


44
45
46
# File 'lib/transmission-rpc/torrent.rb', line 44

def paused?
	self.status == 0
end

#start!Object

Starts downloading the current torrent



24
25
26
# File 'lib/transmission-rpc/torrent.rb', line 24

def start!
	Client.request("torrent-start", nil, [self.id])
end

#stop!Object

Stops downloading the current torrent



29
30
31
# File 'lib/transmission-rpc/torrent.rb', line 29

def stop!
	Client.request("torrent-stop", nil, [self.id])
end