Class: Deluge::Rpc::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/deluge/rpc/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
12
13
# File 'lib/deluge/rpc/client.rb', line 6

def initialize(options = {})
  @connection = Deluge::Rpc::Connection.new(options)
  @login = options.fetch(:login)
  @password = options.fetch(:password)

  @namespaces = {}
  @api_methods = []
end

Instance Attribute Details

#api_methodsObject (readonly)

Returns the value of attribute api_methods.



4
5
6
# File 'lib/deluge/rpc/client.rb', line 4

def api_methods
  @api_methods
end

#auth_levelObject (readonly)

Returns the value of attribute auth_level.



4
5
6
# File 'lib/deluge/rpc/client.rb', line 4

def auth_level
  @auth_level
end

#namespacesObject (readonly)

Returns the value of attribute namespaces.



4
5
6
# File 'lib/deluge/rpc/client.rb', line 4

def namespaces
  @namespaces
end

Instance Method Details

#closeObject



37
38
39
40
41
42
43
44
45
# File 'lib/deluge/rpc/client.rb', line 37

def close
  @connection.close
  @auth_level = nil
  @api_methods = []
  @namespaces.each_key do |ns|
    self.singleton_class.send :undef_method, ns
  end
  @namespaces = {}
end

#connectObject



15
16
17
18
19
20
21
22
23
# File 'lib/deluge/rpc/client.rb', line 15

def connect
  @connection.start

  @auth_level = @connection.authenticate(@login, @password)

  register_methods!

  true
end

#register_event(event_name, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/deluge/rpc/client.rb', line 25

def register_event(event_name, &block)
  raise "Provide block for event" unless block

  if event_name.is_a?(Symbol)
    event_name = "#{event_name}_event"
    # convert to CamelCase
    event_name.gsub!(/(?:_|^)(.)/) { |match| $1.upcase }
  end

  @connection.register_event(event_name, &block)
end