Class: RubyAMI::Client
- Inherits:
-
Object
- Object
- RubyAMI::Client
- Includes:
- Celluloid
- Defined in:
- lib/ruby_ami/client.rb
Instance Attribute Summary collapse
-
#actions_stream ⇒ Object
readonly
Returns the value of attribute actions_stream.
-
#events_stream ⇒ Object
readonly
Returns the value of attribute events_stream.
Instance Method Summary collapse
- #handle_event(event) ⇒ Object
- #handle_message(message) ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #send_action(*args) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 |
# File 'lib/ruby_ami/client.rb', line 10 def initialize() @options = @event_handler = @options[:event_handler] @state = :stopped client = current_actor @events_stream = new_stream ->(event) { client.async.handle_event event } @actions_stream = new_stream ->() { client.async. } end |
Instance Attribute Details
#actions_stream ⇒ Object (readonly)
Returns the value of attribute actions_stream.
8 9 10 |
# File 'lib/ruby_ami/client.rb', line 8 def actions_stream @actions_stream end |
#events_stream ⇒ Object (readonly)
Returns the value of attribute events_stream.
8 9 10 |
# File 'lib/ruby_ami/client.rb', line 8 def events_stream @events_stream end |
Instance Method Details
#handle_event(event) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/ruby_ami/client.rb', line 44 def handle_event(event) logger.trace "[RECV-EVENTS]: #{event.inspect}" case event when Stream::Connected, Stream::Disconnected else pass_event event end end |
#handle_message(message) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ruby_ami/client.rb', line 33 def () logger.trace "[RECV-ACTIONS]: #{.inspect}" case when Stream::Connected send_action 'Events', 'EventMask' => 'Off' when Stream::Disconnected when Event pass_event end end |
#send_action(*args) ⇒ Object
29 30 31 |
# File 'lib/ruby_ami/client.rb', line 29 def send_action(*args) actions_stream.send_action *args end |
#start ⇒ Object
23 24 25 26 27 |
# File 'lib/ruby_ami/client.rb', line 23 def start @events_stream.async.run @actions_stream.async.run @state = :started end |