Class: Astrobot::Torrent

Inherits:
Object
  • Object
show all
Defined in:
lib/astrobot/torrent.rb

Class Method Summary collapse

Class Method Details

.all(fields = Astrobot::TORRENT_FIELDS) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/astrobot/torrent.rb', line 4

def self.all(fields = Astrobot::TORRENT_FIELDS)
  Logger.add "get_torrents"
  opts = { :fields => fields }
  response = Astrobot::Client.build("torrent-get", opts)

  convert_hash_keys(response["arguments"]["torrents"])
end

.create(filename, download_dir = nil) ⇒ Object

Raises:

  • (StandardError)


22
23
24
25
26
27
28
29
30
# File 'lib/astrobot/torrent.rb', line 22

def self.create(filename, download_dir = nil)
  raise StandardError, "missing :filename in params" unless filename
  Logger.add "add_torrent: #{filename}"
  opts = {:filename => filename}
  opts.merge!('download-dir': download_dir ) if download_dir

  response = Astrobot::Client.build("torrent-add", opts)
  response["arguments"]["torrent-added"]
end

.destroy(id) ⇒ Object

Raises:

  • (StandardError)


32
33
34
35
36
37
38
39
# File 'lib/astrobot/torrent.rb', line 32

def self.destroy(id)
  raise StandardError, "missing :id in params" unless id

  Logger.add "remove_torrent: #{id}"
  opts = { :ids => [id], :"delete-local-data" => true }

  Astrobot::Client.build("torrent-remove", opts)
end

.find(id, fields = Astrobot::TORRENT_FIELDS) ⇒ Object

Raises:

  • (StandardError)


12
13
14
15
16
17
18
19
20
# File 'lib/astrobot/torrent.rb', line 12

def self.find(id, fields = Astrobot::TORRENT_FIELDS)
  raise StandardError, "missing :id in params" unless id
  Logger.add "get_torrent: #{id}"
  id = [id] unless id.class == Array
  opts = { :fields => fields, :ids => id }

  response = Astrobot::Client.build("torrent-get", opts)
  convert_hash_keys(response["arguments"]["torrents"]).first
end