Class: Telegram::Connection
- Inherits:
-
EM::Connection
- Object
- EM::Connection
- Telegram::Connection
- Defined in:
- lib/telegram/connection.rb
Instance Method Summary collapse
- #available? ⇒ Boolean
- #communicate(*messages, &callback) ⇒ Object
- #connected? ⇒ Boolean
- #connection_completed ⇒ Object private
-
#initialize ⇒ Connection
constructor
A new instance of Connection.
- #on_connect=(block) ⇒ Object
- #on_disconnect=(block) ⇒ Object
- #receive_data(data) ⇒ Object
- #unbind ⇒ Object
Constructor Details
#initialize ⇒ Connection
Returns a new instance of Connection.
3 4 5 6 7 8 9 10 |
# File 'lib/telegram/connection.rb', line 3 def initialize super @connected = false @on_connect = nil @on_disconnect = nil @callback = nil @available = true end |
Instance Method Details
#available? ⇒ Boolean
12 13 14 |
# File 'lib/telegram/connection.rb', line 12 def available? @available end |
#communicate(*messages, &callback) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/telegram/connection.rb', line 16 def communicate(*, &callback) @available = false @callback = callback = .each_with_index.map { |m, i| if i > 0 m = "\"#{m}\"" end m }.join(' ') << "\n" send_data() end |
#connected? ⇒ Boolean
47 48 49 |
# File 'lib/telegram/connection.rb', line 47 def connected? @connected end |
#connection_completed ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 40 |
# File 'lib/telegram/connection.rb', line 37 def connection_completed @connected = true @on_connect.call unless @on_connect.nil? end |
#on_connect=(block) ⇒ Object
28 29 30 |
# File 'lib/telegram/connection.rb', line 28 def on_connect=(block) @on_connect = block end |
#on_disconnect=(block) ⇒ Object
32 33 34 |
# File 'lib/telegram/connection.rb', line 32 def on_disconnect=(block) @on_disconnect = block end |
#receive_data(data) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/telegram/connection.rb', line 51 def receive_data(data) begin result = _receive_data(data) rescue result = nil end @callback.call(!result.nil?, result) unless @callback.nil? @callback = nil @available = true end |
#unbind ⇒ Object
42 43 44 45 |
# File 'lib/telegram/connection.rb', line 42 def unbind @connected = false @on_disconnect.call unless @on_disconnect.nil? end |