Class: TelegramOnSteroids::Updates

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram_on_steroids/updates.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Updates

Returns a new instance of Updates.



4
5
6
# File 'lib/telegram_on_steroids/updates.rb', line 4

def initialize(params)
  @params = params
end

Instance Attribute Details

#stop=(value) ⇒ Object (writeonly)

Sets the attribute stop

Parameters:

  • value

    the value to set the attribute stop to.



2
3
4
# File 'lib/telegram_on_steroids/updates.rb', line 2

def stop=(value)
  @stop = value
end

Instance Method Details

#enumObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/telegram_on_steroids/updates.rb', line 8

def enum
  Enumerator.new do |y|
    loop do
      break if @stop

      updates = TelegramOnSteroids::Client.new.get_updates(@params)["result"]
      updates.each do |update|
        y << update
      end

      if updates.any?
        @params.merge! offset: updates.last["update_id"] + 1
      end
    end
  end
end