Class: Punchblock::Client

Inherits:
Object show all
Extended by:
ActiveSupport::Autoload
Includes:
HasGuardedHandlers
Defined in:
lib/punchblock/client.rb,
lib/punchblock/client/component_registry.rb

Defined Under Namespace

Classes: ComponentRegistry

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Client) initialize(options = {})

Returns a new instance of Client

Options Hash (options):

  • :connection (Connection::XMPP)

    The Punchblock connection to use for this session



18
19
20
21
22
# File 'lib/punchblock/client.rb', line 18

def initialize(options = {})
  @connection = options[:connection]
  @connection.event_handler = lambda { |event| self.handle_event event } if @connection
  @component_registry = ComponentRegistry.new
end

Instance Attribute Details

- (Object) component_registry (readonly)

Returns the value of attribute component_registry



11
12
13
# File 'lib/punchblock/client.rb', line 11

def component_registry
  @component_registry
end

- (Object) connection (readonly)

Returns the value of attribute connection



11
12
13
# File 'lib/punchblock/client.rb', line 11

def connection
  @connection
end

Instance Method Details

- (Object) delete_component_registration(component)



45
46
47
# File 'lib/punchblock/client.rb', line 45

def delete_component_registration(component)
  component_registry.delete component
end

- (Object) execute_command(command, options = {})



49
50
51
52
53
54
55
56
57
# File 'lib/punchblock/client.rb', line 49

def execute_command(command, options = {})
  command.client = self
  if command.respond_to?(:register_handler)
    command.register_handler :internal do |event|
      trigger_handler :event, event
    end
  end
  connection.write command, options
end

- (Object) find_component_by_uri(uri)



41
42
43
# File 'lib/punchblock/client.rb', line 41

def find_component_by_uri(uri)
  component_registry.find_by_uri uri
end

- (Object) handle_event(event)



24
25
26
27
28
29
30
31
# File 'lib/punchblock/client.rb', line 24

def handle_event(event)
  event.client = self
  if event.source
    event.source.add_event event
  else
    trigger_handler :event, event
  end
end

- (Object) register_component(component)



37
38
39
# File 'lib/punchblock/client.rb', line 37

def register_component(component)
  component_registry << component
end

- (Object) register_event_handler(*guards, &block)



33
34
35
# File 'lib/punchblock/client.rb', line 33

def register_event_handler(*guards, &block)
  register_handler :event, *guards, &block
end