Class: Configuration::Client
- Inherits:
-
Object
- Object
- Configuration::Client
- Defined in:
- lib/transmission-connect/configuration.rb
Constant Summary collapse
- HOST =
HOST = ‘127.0.0.1:3000’
'http://peerlize.hitlan.ru'
- FIELDS =
['downloadDir', 'error', 'errorString', 'eta', 'hashString', 'id', 'name', 'peersConnected', 'peersKnown', 'peersSendingToUs', 'percentDone', 'rateDownload', 'rateUpload', 'recheckProgress', 'startDate', 'status', 'totalSize', 'torrentFile']
Instance Attribute Summary collapse
-
#download_dir ⇒ Object
Returns the value of attribute download_dir.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#peer_port ⇒ Object
Returns the value of attribute peer_port.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#transmission ⇒ Object
readonly
Returns the value of attribute transmission.
Instance Method Summary collapse
- #down? ⇒ Boolean
-
#initialize(args) ⇒ Client
constructor
A new instance of Client.
- #options ⇒ Object
- #report ⇒ Object
- #session_stats ⇒ Object
- #up? ⇒ Boolean
Constructor Details
#initialize(args) ⇒ Client
Returns a new instance of Client.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/transmission-connect/configuration.rb', line 56 def initialize(args) @host = args.delete(:host) || '127.0.0.1' @port = args.delete(:port) || 9091 @username = args[:username] @password = args[:password] @interval = args.delete(:interval) || 5 @up = args.delete(:up) || false @down = args.delete(:down) || false @transmission = Transmission::Client.new(@host, @port, @username, @password) @transmission.session do |session| self.peer_port = session.peer_port self.download_dir = session.download_dir end end |
Instance Attribute Details
#download_dir ⇒ Object
Returns the value of attribute download_dir.
55 56 57 |
# File 'lib/transmission-connect/configuration.rb', line 55 def download_dir @download_dir end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
54 55 56 |
# File 'lib/transmission-connect/configuration.rb', line 54 def host @host end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
54 55 56 |
# File 'lib/transmission-connect/configuration.rb', line 54 def interval @interval end |
#peer_port ⇒ Object
Returns the value of attribute peer_port.
55 56 57 |
# File 'lib/transmission-connect/configuration.rb', line 55 def peer_port @peer_port end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
54 55 56 |
# File 'lib/transmission-connect/configuration.rb', line 54 def port @port end |
#transmission ⇒ Object (readonly)
Returns the value of attribute transmission.
54 55 56 |
# File 'lib/transmission-connect/configuration.rb', line 54 def transmission @transmission end |
Instance Method Details
#down? ⇒ Boolean
92 93 94 |
# File 'lib/transmission-connect/configuration.rb', line 92 def down? @down end |
#options ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/transmission-connect/configuration.rb', line 96 def @options ||= { :port => peer_port, :up => up?, :down => down?, :download_dir => download_dir, :host => @host } end |
#report ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/transmission-connect/configuration.rb', line 71 def report @transmission.torrents(FIELDS) do |torrents| result = {:client => } torrents.each do |torrent| result[torrent.hashString.to_sym] = torrent.attributes end EM::HttpRequest.new("#{HOST}/transmission/").post :body => {:torrents => result.to_json} end end |
#session_stats ⇒ Object
81 82 83 84 85 86 |
# File 'lib/transmission-connect/configuration.rb', line 81 def session_stats @transmission.session_stat do |ss| result = ss.attributes.merge(:client => ) EM::HttpRequest.new("#{HOST}/transmission/stat").post :body => {:session_stat => result.to_json} end end |
#up? ⇒ Boolean
88 89 90 |
# File 'lib/transmission-connect/configuration.rb', line 88 def up? @up end |