Class: Transmission::RPC::Torrent
- Inherits:
-
Object
- Object
- Transmission::RPC::Torrent
- 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
Instance Attribute Summary collapse
-
#bytes_left ⇒ Object
Returns the value of attribute bytes_left.
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#date_added ⇒ Object
Returns the value of attribute date_added.
-
#description ⇒ Object
Returns the value of attribute description.
-
#download_directory ⇒ Object
Returns the value of attribute download_directory.
-
#download_speed ⇒ Object
Returns the value of attribute download_speed.
-
#eta ⇒ Object
Returns the value of attribute eta.
-
#files ⇒ Object
Returns the value of attribute files.
-
#hash ⇒ Object
Returns the value of attribute hash.
-
#id ⇒ Object
Returns the value of attribute id.
-
#leechers ⇒ Object
Returns the value of attribute leechers.
-
#name ⇒ Object
Returns the value of attribute name.
-
#percent_done ⇒ Object
Returns the value of attribute percent_done.
-
#seeders ⇒ Object
Returns the value of attribute seeders.
-
#status ⇒ Object
Returns the value of attribute status.
-
#torrent_file ⇒ Object
Returns the value of attribute torrent_file.
-
#total_size ⇒ Object
Returns the value of attribute total_size.
Class Method Summary collapse
-
.+(url) ⇒ Object
Adds a torrent by URL or file path.
-
.add(options = {}) ⇒ Object
Adds a torrent by file path or URL (.torrent file’s only right now).
-
.all ⇒ Object
Gets all the torrents.
-
.find(id) ⇒ Object
Finds a torrent by ID.
-
.start! ⇒ Object
Starts all torrents.
-
.stop! ⇒ Object
Stops all torrents.
Instance Method Summary collapse
-
#delete!(delete_data = false) ⇒ Object
Deletes the current torrent, and, optionally, the data for that torrent.
-
#downloading? ⇒ Boolean
Checks if torrent is currently downloading.
-
#initialize(options = {}) ⇒ Torrent
constructor
A new instance of Torrent.
-
#paused? ⇒ Boolean
Checks if torrent is paused.
-
#start! ⇒ Object
Starts downloading the current torrent.
-
#stop! ⇒ Object
Stops downloading the current torrent.
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( = {}) self.id = ['id'] self.date_added = ['addedDate'] self.comment = ['comment'] self.eta = ['eta'] self.bytes_left = ['leftUntilDone'] self.name = ['name'] self.percent_done = ['percentDone'] self.torrent_file = ['torrentFile'] self.total_size = ['totalSize'] self.hash = ['hashString'] self.status = ['status'] self.download_speed = ['rateDownload'] end |
Instance Attribute Details
#bytes_left ⇒ Object
Returns the value of attribute bytes_left.
5 6 7 |
# File 'lib/transmission-rpc/torrent.rb', line 5 def bytes_left @bytes_left end |
#comment ⇒ Object
Returns the value of attribute comment.
5 6 7 |
# File 'lib/transmission-rpc/torrent.rb', line 5 def comment @comment end |
#date_added ⇒ Object
Returns the value of attribute date_added.
5 6 7 |
# File 'lib/transmission-rpc/torrent.rb', line 5 def date_added @date_added end |
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/transmission-rpc/torrent.rb', line 5 def description @description end |
#download_directory ⇒ Object
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_speed ⇒ Object
Returns the value of attribute download_speed.
5 6 7 |
# File 'lib/transmission-rpc/torrent.rb', line 5 def download_speed @download_speed end |
#eta ⇒ Object
Returns the value of attribute eta.
5 6 7 |
# File 'lib/transmission-rpc/torrent.rb', line 5 def eta @eta end |
#files ⇒ Object
Returns the value of attribute files.
5 6 7 |
# File 'lib/transmission-rpc/torrent.rb', line 5 def files @files end |
#hash ⇒ Object
Returns the value of attribute hash.
5 6 7 |
# File 'lib/transmission-rpc/torrent.rb', line 5 def hash @hash end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/transmission-rpc/torrent.rb', line 5 def id @id end |
#leechers ⇒ Object
Returns the value of attribute leechers.
5 6 7 |
# File 'lib/transmission-rpc/torrent.rb', line 5 def leechers @leechers end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/transmission-rpc/torrent.rb', line 5 def name @name end |
#percent_done ⇒ Object
Returns the value of attribute percent_done.
5 6 7 |
# File 'lib/transmission-rpc/torrent.rb', line 5 def percent_done @percent_done end |
#seeders ⇒ Object
Returns the value of attribute seeders.
5 6 7 |
# File 'lib/transmission-rpc/torrent.rb', line 5 def seeders @seeders end |
#status ⇒ Object
Returns the value of attribute status.
5 6 7 |
# File 'lib/transmission-rpc/torrent.rb', line 5 def status @status end |
#torrent_file ⇒ Object
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_size ⇒ Object
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( = {}) @response = Client.request("torrent-add", :filename => [:url]) if @response['result'] == 'success' self.find(@response['arguments']['torrent-added']['id']) else nil end end |
.all ⇒ Object
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 |
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
39 40 41 |
# File 'lib/transmission-rpc/torrent.rb', line 39 def downloading? self.status == 4 end |
#paused? ⇒ Boolean
Checks if torrent is paused
44 45 46 |
# File 'lib/transmission-rpc/torrent.rb', line 44 def paused? self.status == 0 end |