rvk 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rvk/status.rb +14 -34
- metadata +3 -3
data/lib/rvk/status.rb
CHANGED
@@ -3,52 +3,32 @@ module Vkontakte
|
|
3
3
|
def set_status(text)
|
4
4
|
request = open('http://vk.com/profile.php', 'Cookie' => "remixsid=#{self.session}")
|
5
5
|
@profile = request.read.to_s
|
6
|
-
|
7
|
-
set_old_status(text)
|
8
|
-
else
|
9
|
-
set_microblog_status(text)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def set_old_status(text)
|
14
|
-
url = URI.parse('http://vk.com/profile.php')
|
15
|
-
request = Net::HTTP::Post.new(url.path)
|
16
|
-
request.set_form_data({'setactivity' => text, 'activityhash' => self.fetch_activityhash})
|
17
|
-
request['cookie'] = "remixsid=#{self.session}"
|
18
|
-
|
19
|
-
Net::HTTP.new(url.host, url.port).start { |http| http.request(request) }
|
20
|
-
end
|
21
|
-
|
22
|
-
def fetch_activityhash
|
23
|
-
if match = @profile.match(/<input type='hidden' id='activityhash' value='([^']+)'>/)
|
24
|
-
match[1]
|
25
|
-
else
|
26
|
-
raise VkontakteError, "Could not find status hash"
|
27
|
-
end
|
6
|
+
set_microblog_status(text)
|
28
7
|
end
|
29
8
|
|
30
9
|
def set_microblog_status(text)
|
31
|
-
url = URI.parse('http://vk.com/
|
10
|
+
url = URI.parse('http://vk.com/al_wall.php')
|
32
11
|
request = Net::HTTP::Post.new(url.path)
|
33
12
|
request.set_form_data({
|
34
|
-
'
|
35
|
-
'
|
36
|
-
'
|
37
|
-
|
13
|
+
'al' => 1,
|
14
|
+
'act' => 'post',
|
15
|
+
'to_id' => find_in_profile(/"user_id":(\d+)/),
|
16
|
+
'hash' => find_in_profile(/"post_hash":"([^"]+)"/),
|
17
|
+
'message' => text,
|
18
|
+
'note_title' => '',
|
19
|
+
'status_export' => ''
|
20
|
+
})
|
38
21
|
request['cookie'] = "remixsid=#{self.session}"
|
39
22
|
|
40
23
|
Net::HTTP.new(url.host, url.port).start { |http| http.request(request) }
|
41
24
|
end
|
42
25
|
|
43
|
-
def
|
44
|
-
if match = @profile.match(
|
45
|
-
|
46
|
-
decoded_hash = (hash[-5..-1] + hash[4..hash.length-9]).reverse
|
47
|
-
{ 'to_id' => match[1], 'hash' => decoded_hash }
|
26
|
+
def find_in_profile(regexp)
|
27
|
+
if match = @profile.match(regexp)
|
28
|
+
match[1]
|
48
29
|
else
|
49
|
-
raise VkontakteError, "Could not find
|
30
|
+
raise VkontakteError, "Could not find #{regexp}"
|
50
31
|
end
|
51
32
|
end
|
52
|
-
|
53
33
|
end
|
54
34
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rvk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 8
|
10
|
+
version: 0.1.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alexandr Zykov
|