Class: RUTorrent::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/rutorrent/server.rb

Constant Summary

TOKEN_PATH =
'/gui/token.html'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, user, pass) ⇒ 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

#buildObject (readonly)

Returns the value of attribute build



10
11
12
# File 'lib/rutorrent/server.rb', line 10

def build
  @build
end

Returns the value of attribute cookie



10
11
12
# File 'lib/rutorrent/server.rb', line 10

def cookie
  @cookie
end

#hostObject (readonly)

Returns the value of attribute host



10
11
12
# File 'lib/rutorrent/server.rb', line 10

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port



10
11
12
# File 'lib/rutorrent/server.rb', line 10

def port
  @port
end

#tokenObject (readonly)

Returns the value of attribute token



10
11
12
# File 'lib/rutorrent/server.rb', line 10

def token
  @token
end

#userObject (readonly)

Returns the value of attribute user



10
11
12
# File 'lib/rutorrent/server.rb', line 10

def user
  @user
end

Instance Method Details

#inspectObject



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

#labelsObject



31
32
33
34
# File 'lib/rutorrent/server.rb', line 31

def labels
  reload unless @labels
  @labels
end

#reloadObject



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

#rssfiltersObject



41
42
43
44
# File 'lib/rutorrent/server.rb', line 41

def rssfilters
  reload unless @rssfilters
  @rssfilters
end

#settingsObject



27
28
29
# File 'lib/rutorrent/server.rb', line 27

def settings
    @settings ||= RUTorrent::Settings.new(self)
end

#torrentsObject



36
37
38
39
# File 'lib/rutorrent/server.rb', line 36

def torrents
  reload unless @torrents
  @torrents
end