Class: RUTorrent::Server
- Inherits:
-
Object
- Object
- RUTorrent::Server
- Defined in:
- lib/rutorrent/server.rb
Constant Summary collapse
- TOKEN_PATH =
'/gui/token.html'
Instance Attribute Summary collapse
-
#build ⇒ Object
readonly
Returns the value of attribute build.
-
#cookie ⇒ Object
readonly
Returns the value of attribute cookie.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(host, port, user, pass) ⇒ Server
constructor
A new instance of Server.
- #inspect ⇒ Object
- #labels ⇒ Object
- #reload ⇒ Object
- #request(args) ⇒ Object
- #rssfilters ⇒ Object
- #settings ⇒ Object
- #torrents ⇒ Object
Constructor Details
#initialize(host, port, user, pass) ⇒ Server
Returns a new instance of Server.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rutorrent/server.rb', line 12 def initialize(host, port, user, pass) @host = host @port = port @user = user @pass = pass @cookie = '' @token = nil @build = nil @http = Net::HTTP.new(@host, @port) get_token end |
Instance Attribute Details
#build ⇒ Object (readonly)
Returns the value of attribute build.
10 11 12 |
# File 'lib/rutorrent/server.rb', line 10 def build @build end |
#cookie ⇒ Object (readonly)
Returns the value of attribute cookie.
10 11 12 |
# File 'lib/rutorrent/server.rb', line 10 def @cookie end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
10 11 12 |
# File 'lib/rutorrent/server.rb', line 10 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
10 11 12 |
# File 'lib/rutorrent/server.rb', line 10 def port @port end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
10 11 12 |
# File 'lib/rutorrent/server.rb', line 10 def token @token end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
10 11 12 |
# File 'lib/rutorrent/server.rb', line 10 def user @user end |
Instance Method Details
#inspect ⇒ Object
82 83 84 |
# File 'lib/rutorrent/server.rb', line 82 def inspect '#<%s:0x%8x %s@%s:%s>' % [self.class, object_id * 2, @user, @host, @port] end |
#labels ⇒ Object
31 32 33 34 |
# File 'lib/rutorrent/server.rb', line 31 def labels reload unless @labels @labels end |
#reload ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rutorrent/server.rb', line 63 def reload json = request(:list => 1) @labels = [] json['label'].each do |label| @labels << Label.new(label) end @torrents = [] json['torrents'].each do |torrent| @torrents << Torrent.new(self, torrent) end @rssfilters = [] json['rssfilters'].each do |rssfilter| @rssfilters << RSSFilter.new(rssfilter) end end |
#request(args) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rutorrent/server.rb', line 46 def request(args) args[:token] ||= @token if @token path = RUTorrent::Helpers::URLHelper.path_for(args) resp = request_raw(path) begin json = JSON.parse(resp.body) @build = json['build'] if json.has_key?('build') ret = json rescue ret = resp.body end ret end |
#rssfilters ⇒ Object
41 42 43 44 |
# File 'lib/rutorrent/server.rb', line 41 def rssfilters reload unless @rssfilters @rssfilters end |
#settings ⇒ Object
27 28 29 |
# File 'lib/rutorrent/server.rb', line 27 def settings @settings ||= RUTorrent::Settings.new(self) end |
#torrents ⇒ Object
36 37 38 39 |
# File 'lib/rutorrent/server.rb', line 36 def torrents reload unless @torrents @torrents end |