rvk 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/lib/rvk.rb +4 -5
  2. data/lib/rvk/status.rb +6 -14
  3. data/lib/rvk/user.rb +5 -4
  4. metadata +3 -4
data/lib/rvk.rb CHANGED
@@ -3,11 +3,10 @@ require 'net/http'
3
3
 
4
4
  $KCODE = 'u'
5
5
 
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')
6
+ require 'rvk/status'
7
+ require 'rvk/note'
8
+ require 'rvk/user'
10
9
 
11
10
  module Vkontakte
12
11
  class VkontakteError < Exception; end;
13
- end
12
+ end
@@ -2,31 +2,23 @@ module Vkontakte
2
2
  module Status
3
3
 
4
4
  def set_status text
5
- url = URI.parse('http://vk.com/wall.php')
5
+ url = URI.parse('http://vk.com/profile.php')
6
6
  request = Net::HTTP::Post.new(url.path)
7
- request.set_form_data({
8
- 'act' => 'a_post_wall',
9
- 'message' => text,
10
- 'reply_to' => -1
11
- }.merge(fetch_hash))
7
+ request.set_form_data({'setactivity' => text, 'activityhash' => self.fetch_activityhash})
12
8
  request['cookie'] = "remixsid=#{self.session}"
13
9
 
14
10
  Net::HTTP.new(url.host, url.port).start { |http| http.request(request) }
15
11
  end
16
12
 
17
- def fetch_hash
13
+ def fetch_activityhash
18
14
  request = open('http://vk.com/profile.php', 'Cookie' => "remixsid=#{self.session}")
19
15
  profile = request.read.to_s
20
- if match = profile.match(/postStatus\((\d+), '([^']+)'\)/)
21
- { 'to_id' => match[1], 'hash' => decode_hash(match[2]) }
16
+ if match = profile.match(/<input type='hidden' id='activityhash' value='([^']+)'>/)
17
+ match[1]
22
18
  else
23
19
  raise VkontakteError, "Could not find status hash"
24
20
  end
25
21
  end
26
22
 
27
- def decode_hash hash
28
- (hash[-5..-1] + hash[4..hash.length-9]).reverse
29
- end
30
-
31
23
  end
32
- end
24
+ end
@@ -9,21 +9,22 @@ 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 email, password
16
+ def fetch_session args
17
+ (email, password) = args
17
18
  resource = Net::HTTP.post_form(URI.parse('http://login.vk.com/'),
18
19
  { 'email' => email, 'pass' => password, 'vk' => '', 'act' => 'login' })
19
20
  if resource.body.empty?
20
21
  raise VkontakteError, "Could not fetch session"
21
22
  end
22
- if match = resource.body.match(/name='s' value='([a-z0-9]+)'/)
23
+ if match = resource.body.match(/id='s' value='([a-z0-9]+)'/)
23
24
  match[1]
24
25
  else
25
26
  raise VkontakteError, "Could not find session"
26
27
  end
27
28
  end
28
29
  end
29
- end
30
+ end
metadata CHANGED
@@ -1,17 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rvk
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alexandr Zykov
14
- - Andrey Sitnik
15
14
  autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []