rvk 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,4 +18,10 @@ Example
18
18
  u = Vkontakte::User.new email, password # or Vkontakte::User.new session
19
19
 
20
20
  u.add_note title, body
21
- u.set_status status
21
+ u.set_status status
22
+
23
+ Authors
24
+ -------
25
+
26
+ Alexander Zykov <alexandrz@gmail.com>
27
+ Andrey Sitnik <andrey@sitnik.ru>
data/lib/rvk.rb CHANGED
@@ -3,10 +3,11 @@ require 'net/http'
3
3
 
4
4
  $KCODE = 'u'
5
5
 
6
- require 'rvk/status'
7
- require 'rvk/note'
8
- require 'rvk/user'
6
+ dir = File.dirname(__FILE__)
7
+ require File.join(dir, 'rvk/status')
8
+ require File.join(dir, 'rvk/note')
9
+ require File.join(dir, 'rvk/user')
9
10
 
10
11
  module Vkontakte
11
12
  class VkontakteError < Exception; end;
12
- end
13
+ end
@@ -1,7 +1,16 @@
1
1
  module Vkontakte
2
2
  module Status
3
+ def set_status(text)
4
+ request = open('http://vk.com/profile.php', 'Cookie' => "remixsid=#{self.session}")
5
+ @profile = request.read.to_s
6
+ if @profile =~ /<input type='hidden' id='activityhash'/
7
+ set_old_status(text)
8
+ else
9
+ set_microblog_status(text)
10
+ end
11
+ end
3
12
 
4
- def set_status text
13
+ def set_old_status(text)
5
14
  url = URI.parse('http://vk.com/profile.php')
6
15
  request = Net::HTTP::Post.new(url.path)
7
16
  request.set_form_data({'setactivity' => text, 'activityhash' => self.fetch_activityhash})
@@ -11,14 +20,35 @@ module Vkontakte
11
20
  end
12
21
 
13
22
  def fetch_activityhash
14
- request = open('http://vk.com/profile.php', 'Cookie' => "remixsid=#{self.session}")
15
- profile = request.read.to_s
16
- if match = profile.match(/<input type='hidden' id='activityhash' value='([^']+)'>/)
23
+ if match = @profile.match(/<input type='hidden' id='activityhash' value='([^']+)'>/)
17
24
  match[1]
18
25
  else
19
26
  raise VkontakteError, "Could not find status hash"
20
27
  end
21
28
  end
22
29
 
30
+ def set_microblog_status(text)
31
+ url = URI.parse('http://vk.com/wall.php')
32
+ request = Net::HTTP::Post.new(url.path)
33
+ request.set_form_data({
34
+ 'act' => 'a_post_wall',
35
+ 'message' => text,
36
+ 'reply_to' => -1
37
+ }.merge(fetch_microblog_data))
38
+ request['cookie'] = "remixsid=#{self.session}"
39
+
40
+ Net::HTTP.new(url.host, url.port).start { |http| http.request(request) }
41
+ end
42
+
43
+ def fetch_microblog_data
44
+ if match = @profile.match(/postStatus\((\d+), '([^']+)'\)/)
45
+ hash = match[2]
46
+ decoded_hash = (hash[-5..-1] + hash[4..hash.length-9]).reverse
47
+ { 'to_id' => match[1], 'hash' => decoded_hash }
48
+ else
49
+ raise VkontakteError, "Could not find status hash"
50
+ end
51
+ end
52
+
23
53
  end
24
- end
54
+ end
@@ -9,22 +9,21 @@ module Vkontakte
9
9
  if (args.size == 1)
10
10
  self.session = args.first
11
11
  else
12
- self.session = self.fetch_session args
12
+ self.session = self.fetch_session *args
13
13
  end
14
14
  end
15
15
 
16
- def fetch_session args
17
- (email, password) = args
16
+ def fetch_session(email, password)
18
17
  resource = Net::HTTP.post_form(URI.parse('http://login.vk.com/'),
19
18
  { 'email' => email, 'pass' => password, 'vk' => '', 'act' => 'login' })
20
19
  if resource.body.empty?
21
20
  raise VkontakteError, "Could not fetch session"
22
21
  end
23
- if match = resource.body.match(/id='s' value='([a-z0-9]+)'/)
22
+ if match = resource.body.match(/name='s' value='([a-z0-9]+)'/)
24
23
  match[1]
25
24
  else
26
25
  raise VkontakteError, "Could not find session"
27
26
  end
28
27
  end
29
28
  end
30
- end
29
+ end
metadata CHANGED
@@ -1,21 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rvk
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 5
10
- version: 0.1.5
9
+ - 6
10
+ version: 0.1.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alexandr Zykov
14
+ - Andrey Sitnik
14
15
  autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-03-16 00:00:00 +01:00
19
+ date: 2010-08-15 00:00:00 +04:00
19
20
  default_executable:
20
21
  dependencies: []
21
22