rvk 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
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
data/lib/rvk/note.rb CHANGED
@@ -14,7 +14,11 @@ module Vkontakte
14
14
  def fetch_notehash
15
15
  request = open('http://vk.com/notes.php?act=new', 'Cookie' => "remixsid=#{self.session}")
16
16
  profile = request.read.to_s
17
- profile.match(/<input type="hidden" name="hash" id="hash" value="([^"]+)">/)[1]
17
+ if match = profile.match(/<input type="hidden" name="hash" id="hash" value="([^"]+)">/)
18
+ match[1]
19
+ else
20
+ raise VkontakteError, "Could not find note hash"
21
+ end
18
22
  end
19
23
 
20
24
  end
data/lib/rvk/status.rb CHANGED
@@ -2,19 +2,31 @@ module Vkontakte
2
2
  module Status
3
3
 
4
4
  def set_status text
5
- url = URI.parse('http://vk.com/profile.php')
5
+ url = URI.parse('http://vk.com/wall.php')
6
6
  request = Net::HTTP::Post.new(url.path)
7
- request.set_form_data({'setactivity' => text, 'activityhash' => self.fetch_activityhash})
7
+ request.set_form_data({
8
+ 'act' => 'a_post_wall',
9
+ 'message' => text,
10
+ 'reply_to' => -1
11
+ }.merge(fetch_hash))
8
12
  request['cookie'] = "remixsid=#{self.session}"
9
13
 
10
14
  Net::HTTP.new(url.host, url.port).start { |http| http.request(request) }
11
15
  end
12
16
 
13
- def fetch_activityhash
17
+ def fetch_hash
14
18
  request = open('http://vk.com/profile.php', 'Cookie' => "remixsid=#{self.session}")
15
19
  profile = request.read.to_s
16
- profile.match(/<input type='hidden' id='activityhash' value='([^']+)'>/)[1]
20
+ if match = profile.match(/postStatus\((\d+), '([^']+)'\)/)
21
+ { 'to_id' => match[1], 'hash' => decode_hash(match[2]) }
22
+ else
23
+ raise VkontakteError, "Could not find status hash"
24
+ end
25
+ end
26
+
27
+ def decode_hash hash
28
+ (hash[-5..-1] + hash[4..hash.length-9]).reverse
17
29
  end
18
30
 
19
31
  end
20
- end
32
+ end
data/lib/rvk/user.rb CHANGED
@@ -9,18 +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
- resource.body.match(/id='s' value='([a-z0-9]+)'/)[1]
22
+ if match = resource.body.match(/name='s' value='([a-z0-9]+)'/)
23
+ match[1]
24
+ else
25
+ raise VkontakteError, "Could not find session"
26
+ end
24
27
  end
25
28
  end
26
- end
29
+ end
metadata CHANGED
@@ -1,20 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rvk
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 29
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 1
8
- - 1
9
- version: 0.1.1
9
+ - 3
10
+ version: 0.1.3
10
11
  platform: ruby
11
12
  authors:
12
13
  - Alexandr Zykov
14
+ - Andrey Sitnik
13
15
  autorequire:
14
16
  bindir: bin
15
17
  cert_chain: []
16
18
 
17
- date: 2010-03-16 00:00:00 +03:00
19
+ date: 2010-03-16 00:00:00 +01:00
18
20
  default_executable:
19
21
  dependencies: []
20
22
 
@@ -43,23 +45,27 @@ rdoc_options: []
43
45
  require_paths:
44
46
  - lib
45
47
  required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
46
49
  requirements:
47
50
  - - ">="
48
51
  - !ruby/object:Gem::Version
52
+ hash: 3
49
53
  segments:
50
54
  - 0
51
55
  version: "0"
52
56
  required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
53
58
  requirements:
54
59
  - - ">="
55
60
  - !ruby/object:Gem::Version
61
+ hash: 3
56
62
  segments:
57
63
  - 0
58
64
  version: "0"
59
65
  requirements: []
60
66
 
61
67
  rubyforge_project:
62
- rubygems_version: 1.3.6
68
+ rubygems_version: 1.3.7
63
69
  signing_key:
64
70
  specification_version: 3
65
71
  summary: Ruby vkontakte poster