Class: TransmissionClient
- Inherits:
-
Object
- Object
- TransmissionClient
- Defined in:
- lib/transmission_client.rb
Instance Method Summary collapse
- #add_magnets(magnets) ⇒ Object
- #add_torrents(torrents) ⇒ Object
- #count ⇒ Object
- #history ⇒ Object
-
#initialize(args = {}) ⇒ TransmissionClient
constructor
A new instance of TransmissionClient.
- #purge_all ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ TransmissionClient
Returns a new instance of TransmissionClient.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/transmission_client.rb', line 6 def initialize(args={}) @host = args[:host] || "localhost" @port = args[:port] || 9091 @user = args[:user] || "transmission" @pass = args[:pass] || "transmission" @database = args[:database] || ":memory:" @logger = args[:logger] || Logger.new(IO::NULL) @sqlite = SQLite3::Database.new @database @sqlite.execute <<~SQL CREATE TABLE IF NOT EXISTS links ( id INTEGER PRIMARY KEY, link TEXT UNIQUE, created_at TEXT DEFAULT CURRENT_TIMESTAMP ) SQL end |
Instance Method Details
#add_magnets(magnets) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/transmission_client.rb', line 24 def add_magnets(magnets) magnets.each do |m| record_link m @logger.info Magnet.name(m) transmission.add_magnet m rescue SQLite3::ConstraintException next end end |
#add_torrents(torrents) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/transmission_client.rb', line 34 def add_torrents(torrents) torrents.each do |t| record_link t @logger.info t transmission.add_torrentfile t rescue SQLite3::ConstraintException next end end |
#count ⇒ Object
44 45 46 |
# File 'lib/transmission_client.rb', line 44 def count list_all.length end |
#history ⇒ Object
54 55 56 |
# File 'lib/transmission_client.rb', line 54 def history sqlite.get_first_value "SELECT COUNT(id) FROM links" end |
#purge_all ⇒ Object
48 49 50 51 52 |
# File 'lib/transmission_client.rb', line 48 def purge_all transmission.list.each do |t| transmission.delete(t["id"], true) end end |