Class: Openfire::Client

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::Configurable
Defined in:
lib/openfire/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, secret) ⇒ Client

Returns a new instance of Client.



7
8
9
# File 'lib/openfire/client.rb', line 7

def initialize(url,secret)
  @services = config.services.map { |s| "Openfire::Service::#{s}".constantize.new url: url, secret: secret }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/openfire/client.rb', line 18

def method_missing(meth, *args, &block)
  @services.each do |service|
    if service.respond_to?(meth)
      return service.send meth, *args
    end
  end
  super
end

Instance Method Details

#get_service(service) ⇒ Object



11
12
13
14
15
16
# File 'lib/openfire/client.rb', line 11

def get_service(service)
  klass_name = "Openfire::Service::#{service.to_s.classify}"
  klass = klass_name.constantize rescue nil
  @services.each { |s| return s if s.is_a?(klass) }
  raise "unknown service: #{service}"
end