vkontakte_api 1.0.rc → 1.0.rc2

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.
data/.travis.yml CHANGED
@@ -2,4 +2,4 @@ rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
4
  - 1.9.3
5
- - ruby-head
5
+ # - ruby-head
data/README.md CHANGED
@@ -6,13 +6,13 @@
6
6
 
7
7
  ``` ruby
8
8
  # Gemfile
9
- gem 'vkontakte_api', '~> 1.0.rc'
9
+ gem 'vkontakte_api', '~> 1.0.rc2'
10
10
  ```
11
11
 
12
12
  или просто
13
13
 
14
14
  ``` sh
15
- $ gem install vkontakte_api
15
+ $ gem install vkontakte_api --pre
16
16
  ```
17
17
 
18
18
  ## Использование
@@ -42,7 +42,6 @@ users = @vk.users.get(uids: [1, 2, 3])
42
42
  users.first.uid # => 1
43
43
  users.first.first_name # => "Павел"
44
44
  users.first.last_name # => "Дуров"
45
- users.first.online? # => true
46
45
 
47
46
  # если метод, возвращающий массив, вызывается с блоком,
48
47
  # то блок будет выполнен для каждого элемента,
@@ -91,10 +90,17 @@ redirect_to VkontakteApi.authorization_url(scope: [:friends, :photos])
91
90
  @vk.is_app_user?
92
91
  ```
93
92
 
94
- Также в этот момент полезно сохранить полученный токен в БД либо в сессии, чтобы использовать его повторно:
93
+ Клиент будет содержать id пользователя, авторизовавшего приложение; его можно получить с помощью метода `VkontakteApi::Client#user_id`:
94
+
95
+ ``` ruby
96
+ @vk.user_id # => 123456
97
+ ```
98
+
99
+ Также в этот момент полезно сохранить полученный токен (и, при необходимости, id пользователя) в БД либо в сессии, чтобы использовать их повторно:
95
100
 
96
101
  ``` ruby
97
102
  current_user.token = @vk.token
103
+ current_user.vk_id = @vk.user_id
98
104
  current_user.save
99
105
  # позже
100
106
  @vk = VkontakteApi::Client.new(current_user.token)
@@ -187,4 +193,4 @@ $ rails generate vkontakte_api:install
187
193
 
188
194
  Если вы хотите поучаствовать в разработке проекта, форкните репозиторий, положите свои изменения в отдельную ветку и отправьте мне pull request.
189
195
 
190
- `vkontakte_api` тестируется под MRI `1.8.7`, `1.9.2`, `1.9.3` и `2.0.0-dev`. Если в одной из этих сред что-то работает неправильно, либо вообще не работает, то это следует считать багом, и написать об этом в [issues на Github](https://github.com/7even/vkontakte_api/issues).
196
+ `vkontakte_api` тестируется под MRI `1.8.7`, `1.9.2` и `1.9.3`. Если в одной из этих сред что-то работает неправильно, либо вообще не работает, то это следует считать багом, и написать об этом в [issues на Github](https://github.com/7even/vkontakte_api/issues).
@@ -4,14 +4,21 @@ module VkontakteApi
4
4
  include Resolver
5
5
 
6
6
  # An access token needed by authorized requests.
7
+ # @return [String]
7
8
  attr_reader :token
9
+ # Current user id.
10
+ # @return [Integer]
11
+ attr_reader :user_id
8
12
 
9
13
  # A new API client.
14
+ # If given an `OAuth2::AccessToken` instance, it extracts and keeps
15
+ # the token string and the user id; otherwise it just stores the given token.
10
16
  # @param [String, OAuth2::AccessToken] token An access token.
11
17
  def initialize(token = nil)
12
- if token.respond_to?(:token)
18
+ if token.respond_to?(:token) && token.respond_to?(:params)
13
19
  # token is an OAuth2::AccessToken
14
- @token = token.token
20
+ @token = token.token
21
+ @user_id = token.params['user_id']
15
22
  else
16
23
  # token is a String or nil
17
24
  @token = token
@@ -1,4 +1,4 @@
1
1
  module VkontakteApi
2
2
  # Library version.
3
- VERSION = '1.0.rc'
3
+ VERSION = '1.0.rc2'
4
4
  end
@@ -2,8 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe VkontakteApi::Client do
4
4
  before(:each) do
5
+ @user_id = stub("User id")
5
6
  @string_token = stub("Access token as a String")
6
- @oauth2_token = stub("Access token as an OAuth2::AccessToken", :token => @string_token)
7
+ @oauth2_token = stub("Access token as an OAuth2::AccessToken", :token => @string_token, :params => {'user_id' => @user_id})
7
8
  end
8
9
 
9
10
  describe "#initialize" do
@@ -26,6 +27,7 @@ describe VkontakteApi::Client do
26
27
  it "extracts the string token and uses it" do
27
28
  client = VkontakteApi::Client.new(@oauth2_token)
28
29
  client.token.should == @string_token
30
+ client.user_id.should == @user_id
29
31
  end
30
32
  end
31
33
  end
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
8
8
  s.authors = ['Vsevolod Romashov']
9
9
  s.email = ['7@7vn.ru']
10
10
  s.homepage = 'http://7even.github.com/vkontakte_api'
11
- s.summary = %q{Ruby-way wrapper for VKontakte API}
12
- s.description = %q{A transparent wrapper for API of vk.com social network called VKontakte. Supports ruby-way method naming (without any method lists inside), result typecasting and any faraday-supported http adapter of your choice (no hardcoded Net::HTTP).}
11
+ s.summary = %q{Ruby wrapper for VKontakte API}
12
+ s.description = %q{A transparent wrapper for VKontakte API. Supports ruby-way naming of API methods (without method lists inside), optional authorization, files uploading, logging and any faraday-supported http adapter of your choice.}
13
13
 
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vkontakte_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.rc
4
+ version: 1.0.rc2
5
5
  prerelease: 4
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-08 00:00:00.000000000 Z
12
+ date: 2012-07-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -155,9 +155,9 @@ dependencies:
155
155
  - - ! '>='
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
- description: A transparent wrapper for API of vk.com social network called VKontakte.
159
- Supports ruby-way method naming (without any method lists inside), result typecasting
160
- and any faraday-supported http adapter of your choice (no hardcoded Net::HTTP).
158
+ description: A transparent wrapper for VKontakte API. Supports ruby-way naming of
159
+ API methods (without method lists inside), optional authorization, files uploading,
160
+ logging and any faraday-supported http adapter of your choice.
161
161
  email:
162
162
  - 7@7vn.ru
163
163
  executables: []
@@ -232,7 +232,7 @@ rubyforge_project:
232
232
  rubygems_version: 1.8.23
233
233
  signing_key:
234
234
  specification_version: 3
235
- summary: Ruby-way wrapper for VKontakte API
235
+ summary: Ruby wrapper for VKontakte API
236
236
  test_files:
237
237
  - spec/integration_spec.rb
238
238
  - spec/spec_helper.rb