class Punchblock::Client

Attributes

component_registry[R]
connection[R]

Public Class Methods

new(options = {}) click to toggle source

@param [Hash] options @option options [Connection::XMPP] :connection The Punchblock connection to use for this session

# 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

Public Instance Methods

delete_component_registration(component) click to toggle source
# File lib/punchblock/client.rb, line 45
def delete_component_registration(component)
  component_registry.delete component
end
execute_command(command, options = {}) click to toggle source
# 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
find_component_by_uri(uri) click to toggle source
# File lib/punchblock/client.rb, line 41
def find_component_by_uri(uri)
  component_registry.find_by_uri uri
end
handle_event(event) click to toggle source
# 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
register_component(component) click to toggle source
# File lib/punchblock/client.rb, line 37
def register_component(component)
  component_registry << component
end
register_event_handler(*guards, &block) click to toggle source
# File lib/punchblock/client.rb, line 33
def register_event_handler(*guards, &block)
  register_handler :event, *guards, &block
end