Class: MTProto::UpdatesPoller

Inherits:
Object
  • Object
show all
Defined in:
lib/mtproto/updates_poller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, poll_interval: 1.0) ⇒ UpdatesPoller

Returns a new instance of UpdatesPoller.



10
11
12
13
14
15
16
17
18
# File 'lib/mtproto/updates_poller.rb', line 10

def initialize(client, poll_interval: 1.0)
  @client = client
  @poll_interval = poll_interval
  @state = nil
  @running = false
  @on_message_callbacks = []
  @on_update_callbacks = []
  @users_cache = {} # Cache user_id => access_hash
end

Instance Attribute Details

#runningObject (readonly)

Returns the value of attribute running.



8
9
10
# File 'lib/mtproto/updates_poller.rb', line 8

def running
  @running
end

#stateObject (readonly)

Returns the value of attribute state.



8
9
10
# File 'lib/mtproto/updates_poller.rb', line 8

def state
  @state
end

Instance Method Details

#on_message(&block) ⇒ Object



20
21
22
# File 'lib/mtproto/updates_poller.rb', line 20

def on_message(&block)
  @on_message_callbacks << block
end

#on_update(&block) ⇒ Object



24
25
26
# File 'lib/mtproto/updates_poller.rb', line 24

def on_update(&block)
  @on_update_callbacks << block
end

#startObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/mtproto/updates_poller.rb', line 28

def start
  raise 'Already running' if @running
  raise 'Auth key not generated' unless @client.auth_key

  @running = true

  @state = RPC::GetUpdatesState.new(@client).call_sync

  poll_loop
end

#stopObject



39
40
41
# File 'lib/mtproto/updates_poller.rb', line 39

def stop
  @running = false
end