Class: Telegram::Rabbit::ClientAdapter
- Inherits:
-
Object
- Object
- Telegram::Rabbit::ClientAdapter
- Defined in:
- lib/telegram/rabbit/client_adapter.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ ClientAdapter
constructor
A new instance of ClientAdapter.
- #start ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ ClientAdapter
Returns a new instance of ClientAdapter.
13 14 15 16 17 |
# File 'lib/telegram/rabbit/client_adapter.rb', line 13 def initialize opts={} @options = .merge(opts) @logger = get_option :logger_instance @logger.level = get_option :log_level end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
10 11 12 |
# File 'lib/telegram/rabbit/client_adapter.rb', line 10 def client @client end |
Instance Method Details
#start ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/telegram/rabbit/client_adapter.rb', line 20 def start logger.debug "Starting ClientAdapter" @connection = Bunny.new(get_option :bunny).start at_exit { @connection.close } #queues send_queue_name = "#{queue_prefix}.messages" receive_queue_name = "#{queue_prefix}.commands" @channel = @connection.create_channel @send_queue = @channel.queue send_queue_name @receive_queue = @channel.queue receive_queue_name logger.debug "Created queues:" logger.debug " send: #{send_queue_name}" logger.debug " receive: #{receive_queue_name}" @receive_queue.subscribe do |info,,raw_data| data = Marshal.load(raw_data) command, payload = extract_command(data) logger.debug "Received command: #{command}" logger.debug payload.inspect exec_api_command command, payload end logger.debug "Starting bot client" @client = client || Telegram::Bot::Client.new(get_option :bot, :token) @client.run do |bot| logger.debug "Bot client started" bot.listen do || logger.debug "Received message:" logger.debug .inspect send_to_app end end end |