Class: Retort::Torrent
- Inherits:
-
Object
- Object
- Retort::Torrent
- Defined in:
- lib/retort/torrent.rb
Class Method Summary collapse
- .action(name, info_hash) ⇒ Object
- .all(view = "main") ⇒ Object
- .attr_mappings ⇒ Object
- .load(url) ⇒ Object
- .views ⇒ Object
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Torrent
constructor
A new instance of Torrent.
Constructor Details
#initialize(attributes) ⇒ Torrent
Returns a new instance of Torrent.
51 52 53 54 55 |
# File 'lib/retort/torrent.rb', line 51 def initialize(attributes) attributes.each do |attrib, value| self.instance_variable_set "@#{attrib}".to_sym, value end end |
Class Method Details
.action(name, info_hash) ⇒ Object
44 45 46 |
# File 'lib/retort/torrent.rb', line 44 def action(name, info_hash) Service.call "d.#{name}", info_hash end |
.all(view = "main") ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/retort/torrent.rb', line 28 def all(view="main") methods = attr_mappings.map {|key,value| "#{value}="} Service.call("d.multicall", view, *methods).map do |r| attributes = Hash[attr_mappings.keys.zip(r)] Torrent.new attributes end end |
.attr_mappings ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/retort/torrent.rb', line 6 def attr_mappings { info_hash: 'd.hash', name: 'd.name', connection_current: 'd.connection_current', size_bytes: 'd.size_bytes', completed_bytes: 'd.completed_bytes', creation_date: 'd.creation_date', bytes_done: 'd.bytes_done', up_rate: 'd.up.rate', down_rate: 'd.down.rate', seeders: 'd.peers_complete', leechers: 'd.peers_connected', is_completed: 'd.complete', is_active: 'd.is_active', is_hash_checked: 'd.is_hash_checked', is_hash_checking: 'd.is_hash_checking', is_multifile: 'd.is_multi_file', is_open: 'd.is_open' } end |
.load(url) ⇒ Object
40 41 42 |
# File 'lib/retort/torrent.rb', line 40 def load(url) Service.call "load_start", url end |
.views ⇒ Object
36 37 38 |
# File 'lib/retort/torrent.rb', line 36 def views Service.call "view.list" end |