Class: Telegram::ClientAdapter
- Inherits:
-
Object
- Object
- Telegram::ClientAdapter
- Defined in:
- lib/telegram/client_adapter.rb
Defined Under Namespace
Classes: ApiProxy
Instance Attribute Summary collapse
-
#bot_name ⇒ Object
Returns the value of attribute bot_name.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#options ⇒ Object
Returns the value of attribute options.
-
#queue_namespace ⇒ Object
Returns the value of attribute queue_namespace.
Instance Method Summary collapse
- #api ⇒ Object
- #configure {|_self| ... } ⇒ Object
- #on_message_received(&block) ⇒ Object
- #send_command(command, payload) ⇒ Object
- #send_message(payload) ⇒ Object
- #start ⇒ Object
Instance Attribute Details
#bot_name ⇒ Object
Returns the value of attribute bot_name.
23 24 25 |
# File 'lib/telegram/client_adapter.rb', line 23 def bot_name @bot_name end |
#connection ⇒ Object
Returns the value of attribute connection.
20 21 22 |
# File 'lib/telegram/client_adapter.rb', line 20 def connection @connection end |
#options ⇒ Object
Returns the value of attribute options.
22 23 24 |
# File 'lib/telegram/client_adapter.rb', line 22 def @options end |
#queue_namespace ⇒ Object
Returns the value of attribute queue_namespace.
21 22 23 |
# File 'lib/telegram/client_adapter.rb', line 21 def queue_namespace @queue_namespace end |
Instance Method Details
#api ⇒ Object
57 58 59 |
# File 'lib/telegram/client_adapter.rb', line 57 def api @api_proxy end |
#configure {|_self| ... } ⇒ Object
26 27 28 29 |
# File 'lib/telegram/client_adapter.rb', line 26 def configure yield self self end |
#on_message_received(&block) ⇒ Object
51 52 53 54 |
# File 'lib/telegram/client_adapter.rb', line 51 def &block @receive_callbacks ||= [] @receive_callbacks << block end |
#send_command(command, payload) ⇒ Object
67 68 69 70 |
# File 'lib/telegram/client_adapter.rb', line 67 def send_command command, payload raw_data = Marshal.dump(serialize_command(command,payload)) @channel.default_exchange.publish raw_data, routing_key: @send_queue.name end |
#send_message(payload) ⇒ Object
62 63 64 |
# File 'lib/telegram/client_adapter.rb', line 62 def payload api. payload end |
#start ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/telegram/client_adapter.rb', line 32 def start send_queue_name = "#{queue_prefix}.commands" receive_queue_name = "#{queue_prefix}.messages" @channel = connection.create_channel @send_queue = @channel.queue send_queue_name @receive_queue = @channel.queue receive_queue_name @receive_queue.subscribe do |info,,raw_data| data = Marshal.load(raw_data) @receive_callbacks.each do |callback| callback.call(data) end end @api_proxy = ApiProxy.new(self) end |