Module: Vkontakte::Note

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

Instance Method Summary collapse

Instance Method Details

#add_note(title, text) ⇒ Object



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

def add_note title, text
  url = URI.parse('http://vk.com/notes.php')
  request = Net::HTTP::Post.new(url.path)
  request.set_form_data({ 'act' => 'add', 'preview' => '0', 'hash' => self.fetch_notehash,
                          'title' => title, 'post' => text })
  request['cookie'] = "remixsid=#{self.session}"

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

#fetch_notehashObject



14
15
16
17
18
19
20
21
22
# File 'lib/rvk/note.rb', line 14

def fetch_notehash
  request = open('http://vk.com/notes.php?act=new', 'Cookie' => "remixsid=#{self.session}")
  profile = request.read.to_s
  if match = profile.match(/<input type="hidden" name="hash" id="hash" value="([^"]+)">/)
    match[1]
  else
    raise VkontakteError, "Could not find note hash"
  end
end