Class: Telegram::ClientAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram/client_adapter.rb

Defined Under Namespace

Classes: ApiProxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bot_nameObject

Returns the value of attribute bot_name.



23
24
25
# File 'lib/telegram/client_adapter.rb', line 23

def bot_name
  @bot_name
end

#connectionObject

Returns the value of attribute connection.



20
21
22
# File 'lib/telegram/client_adapter.rb', line 20

def connection
  @connection
end

#optionsObject

Returns the value of attribute options.



22
23
24
# File 'lib/telegram/client_adapter.rb', line 22

def options
  @options
end

#queue_namespaceObject

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

#apiObject



57
58
59
# File 'lib/telegram/client_adapter.rb', line 57

def api
  @api_proxy
end

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



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 on_message_received &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 send_message payload
  api.send_message payload
end

#startObject



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