Class: ActionChannels::Client
- Inherits:
-
Object
- Object
- ActionChannels::Client
- Defined in:
- lib/action_channels/client.rb
Instance Attribute Summary collapse
-
#message_sender ⇒ Object
readonly
Returns the value of attribute message_sender.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #connected? ⇒ Boolean
-
#initialize(url, options = {}) ⇒ Client
constructor
A new instance of Client.
- #send_message(message) ⇒ Object
- #start(waits_at = 20) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(url, options = {}) ⇒ Client
Returns a new instance of Client.
18 19 20 21 22 |
# File 'lib/action_channels/client.rb', line 18 def initialize(url, = {}) @url = url self.is_connected = false @message_sender = .fetch :message_sender, MessageSenders::WebSocket.new end |
Instance Attribute Details
#message_sender ⇒ Object (readonly)
Returns the value of attribute message_sender.
16 17 18 |
# File 'lib/action_channels/client.rb', line 16 def @message_sender end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
16 17 18 |
# File 'lib/action_channels/client.rb', line 16 def url @url end |
Class Method Details
.send_message(url, message, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/action_channels/client.rb', line 6 def (url, , = {}) client = new(url, ) client.start client.() client.stop true end |
Instance Method Details
#connected? ⇒ Boolean
55 56 57 |
# File 'lib/action_channels/client.rb', line 55 def connected? is_connected end |
#send_message(message) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/action_channels/client.rb', line 47 def () return false unless connected? .do_send(connect, ) true end |
#start(waits_at = 20) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/action_channels/client.rb', line 24 def start(waits_at = 20) return true if connected? do_connect Timeout::timeout(waits_at, Errors::NotConnected) do until connected? do sleep 1 end end true end |
#stop ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/action_channels/client.rb', line 38 def stop if connected? connect.close connect = nil end true end |