Class: Vkontakte::User

Inherits:
Object
  • Object
show all
Includes:
Note, Status
Defined in:
lib/rvk/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Note

#add_note, #fetch_notehash

Methods included from Status

#find_in_profile, #set_microblog_status, #set_status

Constructor Details

#initialize(*args) ⇒ User

Returns a new instance of User.



8
9
10
11
12
13
14
# File 'lib/rvk/user.rb', line 8

def initialize(*args)
  if (args.size == 1)
    self.session = args.first
  else
    self.session = self.fetch_session *args
  end      
end

Instance Attribute Details

#sessionObject

Returns the value of attribute session.



3
4
5
# File 'lib/rvk/user.rb', line 3

def session
  @session
end

Instance Method Details

#fetch_session(email, password) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rvk/user.rb', line 16

def fetch_session(email, password)
  resource = Net::HTTP.post_form(URI.parse('http://login.vk.com/'), 
      { 'email' => email, 'pass' => password, 'vk' => '', 'act' => 'login' })
  if resource.body.empty?
    raise VkontakteError, "Could not fetch session"
  end
  if match = resource.body.match(/name='s' value='([a-z0-9]+)'/)
    match[1]
  else
    raise VkontakteError, "Could not find session"
  end
end