Class: Configuration::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_dirObject

Returns the value of attribute download_dir.



55
56
57
# File 'lib/transmission-connect/configuration.rb', line 55

def download_dir
  @download_dir
end

#hostObject (readonly)

Returns the value of attribute host.



54
55
56
# File 'lib/transmission-connect/configuration.rb', line 54

def host
  @host
end

#intervalObject (readonly)

Returns the value of attribute interval.



54
55
56
# File 'lib/transmission-connect/configuration.rb', line 54

def interval
  @interval
end

#peer_portObject

Returns the value of attribute peer_port.



55
56
57
# File 'lib/transmission-connect/configuration.rb', line 55

def peer_port
  @peer_port
end

#portObject (readonly)

Returns the value of attribute port.



54
55
56
# File 'lib/transmission-connect/configuration.rb', line 54

def port
  @port
end

#transmissionObject (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

Returns:

  • (Boolean)


92
93
94
# File 'lib/transmission-connect/configuration.rb', line 92

def down?
  @down
end

#optionsObject



96
97
98
99
100
101
102
103
104
# File 'lib/transmission-connect/configuration.rb', line 96

def options
  @options ||= {
      :port => peer_port,
      :up => up?,
      :down => down?,
      :download_dir => download_dir,
      :host => @host
  }
end

#reportObject



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 => options}
    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_statsObject



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 => options)
    EM::HttpRequest.new("#{HOST}/transmission/stat").post :body => {:session_stat => result.to_json}
  end
end

#up?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/transmission-connect/configuration.rb', line 88

def up?
  @up
end