Class: Deluge::Rpc::Client
- Inherits:
-
Object
- Object
- Deluge::Rpc::Client
- Defined in:
- lib/deluge/rpc/client.rb
Instance Attribute Summary collapse
-
#api_methods ⇒ Object
readonly
Returns the value of attribute api_methods.
-
#auth_level ⇒ Object
readonly
Returns the value of attribute auth_level.
-
#namespaces ⇒ Object
readonly
Returns the value of attribute namespaces.
Instance Method Summary collapse
- #close ⇒ Object
- #connect ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #register_event(event_name, &block) ⇒ Object
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( = {}) @connection = Deluge::Rpc::Connection.new() @login = .fetch(:login) @password = .fetch(:password) @namespaces = {} @api_methods = [] end |
Instance Attribute Details
#api_methods ⇒ Object (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_level ⇒ Object (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 |
#namespaces ⇒ Object (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
#close ⇒ Object
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 |
#connect ⇒ Object
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 |