Module: Vkontakte::Status

Included in:
User
Defined in:
lib/rvk/status.rb

Instance Method Summary collapse

Instance Method Details

#fetch_activityhashObject



22
23
24
25
26
27
28
# File 'lib/rvk/status.rb', line 22

def fetch_activityhash
  if match = @profile.match(/<input type='hidden' id='activityhash' value='([^']+)'>/)
    match[1]
  else
    raise VkontakteError, "Could not find status hash"
  end
end

#fetch_microblog_dataObject



43
44
45
46
47
48
49
50
51
# File 'lib/rvk/status.rb', line 43

def fetch_microblog_data
  if match = @profile.match(/postStatus\((\d+), '([^']+)'\)/)
    hash = match[2]
    decoded_hash = (hash[-5..-1] + hash[4..hash.length-9]).reverse
    { 'to_id' => match[1], 'hash' => decoded_hash }
  else
    raise VkontakteError, "Could not find status hash"
  end
end

#set_microblog_status(text) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rvk/status.rb', line 30

def set_microblog_status(text)
  url = URI.parse('http://vk.com/wall.php')
  request = Net::HTTP::Post.new(url.path)
  request.set_form_data({
    'act'      => 'a_post_wall',
    'message'  => text,
    'reply_to' => -1
  }.merge(fetch_microblog_data))
  request['cookie'] = "remixsid=#{self.session}"

  Net::HTTP.new(url.host, url.port).start { |http| http.request(request) }
end

#set_old_status(text) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/rvk/status.rb', line 13

def set_old_status(text)
  url = URI.parse('http://vk.com/profile.php')
  request = Net::HTTP::Post.new(url.path)
  request.set_form_data({'setactivity' => text, 'activityhash' => self.fetch_activityhash})
  request['cookie'] = "remixsid=#{self.session}"

  Net::HTTP.new(url.host, url.port).start { |http| http.request(request) }
end

#set_status(text) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/rvk/status.rb', line 3

def set_status(text)
  request = open('http://vk.com/profile.php', 'Cookie' => "remixsid=#{self.session}")
  @profile = request.read.to_s
  if @profile =~ /<input type='hidden' id='activityhash'/
    set_old_status(text)
  else
    set_microblog_status(text)
  end
end