vkontakte 0.0.1 → 0.0.2

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.
@@ -7,6 +7,8 @@ More info about API:
7
7
 
8
8
  2. http://vkontakte.ru/developers.php?oid=-1&p=%D0%92%D1%8B%D0%BF%D0%BE%D0%BB%D0%BD%D0%B5%D0%BD%D0%B8%D0%B5_%D0%B7%D0%B0%D0%BF%D1%80%D0%BE%D1%81%D0%BE%D0%B2_%D0%BA_API
9
9
 
10
+ 3. http://vk.com/developers.php?oid=-1&p=%D0%9F%D1%80%D0%B0%D0%B2%D0%B0_%D0%B4%D0%BE%D1%81%D1%82%D1%83%D0%BF%D0%B0_%D0%BF%D1%80%D0%B8%D0%BB%D0%BE%D0%B6%D0%B5%D0%BD%D0%B8%D0%B9
11
+
10
12
  == Install
11
13
 
12
14
  gem 'vkontakte'
@@ -23,6 +25,34 @@ More info about API:
23
25
 
24
26
  == Usage
25
27
 
28
+ === User API by access_token
29
+
30
+ user = Vkontakte::App::User.new(uid, :access_token => ACCESS_TOKEN)
31
+ user.fetch # {"response"=>[{"uid"=>2592709, ...
32
+
33
+ Profile
34
+
35
+ user.profile.isAppUser() # {"response"=>"1"}
36
+ user.profile.getUserBalance()
37
+ user.profile.getUserSettings()
38
+ user.profile.likesGetList(:type => 'post')
39
+
40
+ Photos
41
+
42
+ user.photos.getAlbums()
43
+ user.photos.getAlbumsCount()
44
+ user.photos.get(:aid => 'album_id')
45
+
46
+ Groups
47
+
48
+ user.groups.get()
49
+ user.groups.isMember(:gid => 'group_id')
50
+
51
+ Friends
52
+
53
+ user.friends.get()
54
+ user.friends.getOnline()
55
+
26
56
  === Secure API
27
57
 
28
58
  @app = Vkontakte::App::Secure.new
@@ -10,6 +10,7 @@ module Vkontakte
10
10
  autoload :Base, 'vkontakte/app/base'
11
11
  autoload :Iframe, 'vkontakte/app/iframe'
12
12
  autoload :Secure, 'vkontakte/app/secure'
13
+ autoload :User, 'vkontakte/app/user'
13
14
  end
14
15
 
15
16
  module Api
@@ -18,6 +19,7 @@ module Vkontakte
18
19
  autoload :Friends, 'vkontakte/api/friends'
19
20
  autoload :Groups, 'vkontakte/api/groups'
20
21
  autoload :Secure, 'vkontakte/api/secure'
22
+ autoload :Profile, 'vkontakte/api/profile'
21
23
  end
22
24
 
23
25
  mattr_accessor :config
@@ -1,13 +1,22 @@
1
1
  module Vkontakte
2
2
  module Api
3
3
  class Base
4
- attr_accessor :app
4
+ attr_accessor :app, :default_params
5
5
 
6
6
  delegate :call, :to => :app
7
7
 
8
8
  def initialize(base)
9
9
  @app = base
10
10
  end
11
+
12
+ def default_params
13
+ @default_params ||= {}
14
+ end
15
+
16
+ def call(method_name, params = {})
17
+ params = default_params.merge(params)
18
+ @app.call(method_name, params)
19
+ end
11
20
  end
12
21
  end
13
22
  end
@@ -0,0 +1,52 @@
1
+ module Vkontakte
2
+ module Api
3
+ module Profile
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+ define_method :profile do
8
+ @profile ||= Standart.new(self)
9
+ end
10
+ end
11
+ end
12
+
13
+ class Standart < Api::Base
14
+ # Данный метод возвращает информацию о том, установил ли текущий пользователь приложение или нет.
15
+ # http://vk.com/developers.php?oid=-1&p=isAppUser
16
+ #
17
+ def isAppUser(options = {})
18
+ call('isAppUser', options)
19
+ end
20
+
21
+ # Возвращает расширенную информацию о пользователях.
22
+ # http://vk.com/developers.php?oid=-1&p=users.get
23
+ #
24
+ def get(options = {})
25
+ call('users.get', options)
26
+ end
27
+
28
+ # Возвращает баланс текущего пользователя на счету приложения в сотых долях голоса.
29
+ # Отличается от метода secure.getBalance тем, что не требует безопасного соединения с сервером API.
30
+ # http://vk.com/developers.php?oid=-1&p=getUserBalance
31
+ #
32
+ def getUserBalance(options = {})
33
+ call('getUserBalance', options)
34
+ end
35
+
36
+ # Получает настройки текущего пользователя в данном приложении.
37
+ # http://vk.com/developers.php?oid=-1&p=getUserSettings
38
+ #
39
+ def getUserSettings(options = {})
40
+ call('getUserSettings', options)
41
+ end
42
+
43
+ # Получает список идентификаторов пользователей, которые добавили заданный объект в свой список Мне нравится.
44
+ # http://vk.com/developers.php?oid=-1&p=likes.getList
45
+ #
46
+ def likesGetList(options = {})
47
+ call('likes.getList', options)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,37 @@
1
+ module Vkontakte
2
+ module App
3
+ # Vkontakte user
4
+ #
5
+ # user = Vkontakte::App::User.fetch(uid, :access_token => ACCESS_TOKEN)
6
+ #
7
+ # or
8
+ #
9
+ # user = Vkontakte::App::User.new(uid, :access_token => ACCESS_TOKEN)
10
+ # user.fetch
11
+ #
12
+ class User < Base
13
+ include Api::Photos
14
+ include Api::Friends
15
+ include Api::Groups
16
+ include Api::Profile
17
+
18
+ attr_reader :identifier
19
+
20
+ def initialize(identifier, options = {})
21
+ super(options[:app_id], options[:app_secret])
22
+ @identifier = identifier
23
+ @auth = { 'access_token' => options[:access_token] } if options.has_key?(:access_token)
24
+ photos.default_params = { :uid => @identifier }
25
+ end
26
+
27
+ def fetch(options = {})
28
+ options = { :uids => @identifier }.merge(options)
29
+ profile.get( options )
30
+ end
31
+
32
+ def self.fetch(identifier, options = {})
33
+ new(identifier, options).fetch
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module Vkontakte
2
- VERSION = "0.0.1".freeze
2
+ VERSION = "0.0.2".freeze
3
3
  end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+
3
+ describe Vkontakte::Api::Profile do
4
+ it "should be valid" do
5
+ Vkontakte::Api::Profile.should be_a(Module)
6
+ end
7
+
8
+ context "params" do
9
+ before(:each) do
10
+ @token = '7a1cfdd37a3b72167a3b7216ac7a1347bde7a3b7a3a7216c95a735a210be6d4'
11
+ @user = Vkontakte::App::User.new('2592709', :access_token => @token)
12
+ end
13
+
14
+ it "should be call users.get method" do
15
+ response = '{"response":[{"uid":2592709, "last_name":"Галета", "first_name":"Павел"}]}'
16
+
17
+ FakeWeb.register_uri(:get,
18
+ "https://api.vkontakte.ru/method/users.get?uids=2592709&access_token=#{@token}",
19
+ :body => response)
20
+
21
+ @user.fetch.should_not be_blank
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe Vkontakte::App::User do
4
+ it "should be valid" do
5
+ Vkontakte::App::User.should be_a(Module)
6
+ end
7
+
8
+ context "fetch" do
9
+ before(:each) do
10
+ @user = Vkontakte::App::User.new('uid', :access_token => 'ACCESS_TOKEN')
11
+ end
12
+
13
+ it "should load user profile" do
14
+ FakeWeb.register_uri(:get,
15
+ "https://api.vkontakte.ru/method/users.get?access_token=ACCESS_TOKEN&uids=uid",
16
+ :body => '{"response":[{"uid":2592709, "last_name":"Галета", "first_name":"Павел"}]}')
17
+
18
+ @user.fetch.should_not be_blank
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vkontakte
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Igor Galeta
@@ -16,8 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-11-11 00:00:00 +02:00
20
- default_executable:
19
+ date: 2012-02-26 00:00:00 Z
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
22
  name: activesupport
@@ -56,31 +55,34 @@ extensions: []
56
55
  extra_rdoc_files:
57
56
  - README.rdoc
58
57
  files:
59
- - lib/vkontakte/app/secure.rb
60
- - lib/vkontakte/app/iframe.rb
61
- - lib/vkontakte/app/base.rb
62
- - lib/vkontakte/utils.rb
58
+ - lib/vkontakte.rb
59
+ - lib/vkontakte/config.rb
60
+ - lib/vkontakte/api/photos.rb
61
+ - lib/vkontakte/api/base.rb
63
62
  - lib/vkontakte/api/secure.rb
64
- - lib/vkontakte/api/friends.rb
63
+ - lib/vkontakte/api/profile.rb
65
64
  - lib/vkontakte/api/groups.rb
66
- - lib/vkontakte/api/base.rb
67
- - lib/vkontakte/api/photos.rb
68
- - lib/vkontakte/config.rb
65
+ - lib/vkontakte/api/friends.rb
69
66
  - lib/vkontakte/version.rb
70
- - lib/vkontakte.rb
67
+ - lib/vkontakte/app/base.rb
68
+ - lib/vkontakte/app/secure.rb
69
+ - lib/vkontakte/app/user.rb
70
+ - lib/vkontakte/app/iframe.rb
71
+ - lib/vkontakte/utils.rb
71
72
  - MIT-LICENSE
72
73
  - Rakefile
73
74
  - Gemfile
74
75
  - README.rdoc
75
- - spec/api/secure_spec.rb
76
- - spec/api/friends_spec.rb
77
- - spec/api/photos_spec.rb
78
- - spec/api/groups_spec.rb
79
76
  - spec/vkontakte_spec.rb
77
+ - spec/spec_helper.rb
80
78
  - spec/apps/base_spec.rb
81
79
  - spec/apps/iframe_spec.rb
82
- - spec/spec_helper.rb
83
- has_rdoc: true
80
+ - spec/apps/user_spec.rb
81
+ - spec/api/profile_spec.rb
82
+ - spec/api/friends_spec.rb
83
+ - spec/api/secure_spec.rb
84
+ - spec/api/groups_spec.rb
85
+ - spec/api/photos_spec.rb
84
86
  homepage: https://github.com/galetahub/vkontakte
85
87
  licenses: []
86
88
 
@@ -110,16 +112,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
112
  requirements: []
111
113
 
112
114
  rubyforge_project:
113
- rubygems_version: 1.6.2
115
+ rubygems_version: 1.8.10
114
116
  signing_key:
115
117
  specification_version: 3
116
118
  summary: Vkontakte API
117
119
  test_files:
118
- - spec/api/secure_spec.rb
119
- - spec/api/friends_spec.rb
120
- - spec/api/photos_spec.rb
121
- - spec/api/groups_spec.rb
122
120
  - spec/vkontakte_spec.rb
121
+ - spec/spec_helper.rb
123
122
  - spec/apps/base_spec.rb
124
123
  - spec/apps/iframe_spec.rb
125
- - spec/spec_helper.rb
124
+ - spec/apps/user_spec.rb
125
+ - spec/api/profile_spec.rb
126
+ - spec/api/friends_spec.rb
127
+ - spec/api/secure_spec.rb
128
+ - spec/api/groups_spec.rb
129
+ - spec/api/photos_spec.rb