Class: NZBGet::RemoteConnection
- Inherits:
-
Object
- Object
- NZBGet::RemoteConnection
show all
- Includes:
- HTTParty
- Defined in:
- lib/nzbget.rb
Constant Summary
collapse
- DEFAULT_OPTIONS =
{
:method => :json,
:password => 'tegbzn6789',
:port => 6789,
:uri => 'http://localhost',
:username => 'nzbget'
}
Instance Method Summary
collapse
Constructor Details
Returns a new instance of RemoteConnection.
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/nzbget.rb', line 20
def initialize(options = {})
@options = DEFAULT_OPTIONS.merge(options)
uri = URI.parse(@options[:uri])
uri.port = @options[:port]
self.class.base_uri(uri.to_s)
self.class.basic_auth(@options[:username], @options[:password])
case @options[:method]
when :json
require 'json'
when :xml
raise ArgumentError
else
raise ArgumentError
end
self.class.format(@options[:method])
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
72
73
74
|
# File 'lib/nzbget.rb', line 72
def method_missing(name, *args)
invoke name, args
end
|
Instance Method Details
#enqueue(path, options = {}) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/nzbget.rb', line 41
def enqueue(path, options = {})
extname = File.extname(path)
raise ArgumentError unless extname.downcase == '.nzb'
filename = options[:filename] || File.basename(path).sub(/#{extname}$/, '')
category = options[:category] || ''
add_to_top = options[:to_top] || false
content = open(path).read
send :append, filename, category, add_to_top, Base64.encode64(content).strip
end
|
#groups ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/nzbget.rb', line 57
def groups
groups = []
send(:listgroups)['result'].each_with_index do |hash, idx|
groups << NZBGet::Group.new(self, idx, hash)
end
groups
end
|
#paused? ⇒ Boolean
53
54
55
|
# File 'lib/nzbget.rb', line 53
def paused?
send(:status)['result']['ServerPaused']
end
|