Class: MTProto::UpdatesPoller
- Inherits:
-
Object
- Object
- MTProto::UpdatesPoller
- Defined in:
- lib/mtproto/updates_poller.rb
Instance Attribute Summary collapse
-
#running ⇒ Object
readonly
Returns the value of attribute running.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
-
#initialize(client, poll_interval: 1.0) ⇒ UpdatesPoller
constructor
A new instance of UpdatesPoller.
- #on_message(&block) ⇒ Object
- #on_update(&block) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
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
#running ⇒ Object (readonly)
Returns the value of attribute running.
8 9 10 |
# File 'lib/mtproto/updates_poller.rb', line 8 def running @running end |
#state ⇒ Object (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 (&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 |
#start ⇒ Object
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 |
#stop ⇒ Object
39 40 41 |
# File 'lib/mtproto/updates_poller.rb', line 39 def stop @running = false end |