Class: VkCozy::User

Inherits:
Object
  • Object
show all
Defined in:
lib/vk_cozy/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token, version = 5.92) ⇒ User

Returns a new instance of User.



10
11
12
13
14
15
16
# File 'lib/vk_cozy/user.rb', line 10

def initialize(access_token, version=5.92)
  @access_token = access_token
  @api = Api.new(access_token, version)
  
  @polling = VkCozy::UserPolling.new(@api)
  @labeler = VkCozy::UserLabeler.new(@api)
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



8
9
10
# File 'lib/vk_cozy/user.rb', line 8

def api
  @api
end

Instance Method Details

#onObject



18
19
20
# File 'lib/vk_cozy/user.rb', line 18

def on
  return @labeler
end

#on_startupObject



22
23
24
# File 'lib/vk_cozy/user.rb', line 22

def on_startup
  puts 'Run polling'
end

#run_polling(startup = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/vk_cozy/user.rb', line 26

def run_polling(startup=nil)
  if startup.nil?
    on_startup
  elsif startup.is_a?(Proc)
    startup.call
  else
    startup
  end

  @polling.listen do |event|
    for update in event['updates']
      begin
        if @labeler.filter(update)
          next
        end
      rescue Exception => e 
        raise e
      end
    end
  end
end