vkontakte_api 1.0.rc2 → 1.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +1 -1
- data/README.md +18 -2
- data/lib/generators/vkontakte_api/install/templates/initializer.rb +3 -0
- data/lib/vkontakte_api.rb +12 -3
- data/lib/vkontakte_api/api.rb +2 -2
- data/lib/vkontakte_api/configuration.rb +7 -6
- data/lib/vkontakte_api/version.rb +1 -1
- data/spec/integration_spec.rb +13 -11
- data/spec/vkontakte_api/api_spec.rb +4 -2
- data/spec/vkontakte_api/configuration_spec.rb +1 -0
- data/spec/vkontakte_api_spec.rb +33 -0
- metadata +2 -2
data/.yardopts
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
``` ruby
|
8
8
|
# Gemfile
|
9
|
-
gem 'vkontakte_api', '~> 1.0.
|
9
|
+
gem 'vkontakte_api', '~> 1.0.rc3'
|
10
10
|
```
|
11
11
|
|
12
12
|
или просто
|
@@ -165,6 +165,17 @@ VkontakteApi.configure do |config|
|
|
165
165
|
|
166
166
|
# faraday-адаптер для сетевых запросов
|
167
167
|
config.adapter = :net_http
|
168
|
+
# параметры для faraday-соединения
|
169
|
+
config.faraday_options = {
|
170
|
+
ssl: {
|
171
|
+
ca_path: '/usr/lib/ssl/certs'
|
172
|
+
},
|
173
|
+
proxy: {
|
174
|
+
uri: 'http://proxy.example.com',
|
175
|
+
user: 'foo',
|
176
|
+
password: 'bar'
|
177
|
+
}
|
178
|
+
}
|
168
179
|
|
169
180
|
# логгер
|
170
181
|
config.logger = Rails.logger
|
@@ -172,10 +183,15 @@ VkontakteApi.configure do |config|
|
|
172
183
|
config.log_errors = true # ошибки
|
173
184
|
config.log_responses = false # удачные ответы
|
174
185
|
end
|
186
|
+
|
187
|
+
# создание короткого алиаса VK для модуля VkontakteApi
|
188
|
+
VkontakteApi.register_alias
|
175
189
|
```
|
176
190
|
|
177
191
|
По умолчанию для HTTP-запросов используется `Net::HTTP`; можно выбрать [любой другой адаптер](https://github.com/technoweenie/faraday/blob/master/lib/faraday/adapter.rb), поддерживаемый `faraday`.
|
178
192
|
|
193
|
+
При необходимости можно указать параметры для faraday-соединения - например, параметры прокси-сервера или путь к SSL-сертификатам.
|
194
|
+
|
179
195
|
Чтобы сгенерировать файл с настройками по умолчанию в rails-приложении, можно воспользоваться генератором `vkontakte_api:install`:
|
180
196
|
|
181
197
|
``` sh
|
@@ -191,6 +207,6 @@ $ rails generate vkontakte_api:install
|
|
191
207
|
|
192
208
|
## Участие в разработке
|
193
209
|
|
194
|
-
Если вы хотите поучаствовать в разработке проекта, форкните репозиторий, положите свои изменения в отдельную
|
210
|
+
Если вы хотите поучаствовать в разработке проекта, форкните репозиторий, положите свои изменения в отдельную ветку, покройте их спеками и отправьте мне pull request.
|
195
211
|
|
196
212
|
`vkontakte_api` тестируется под MRI `1.8.7`, `1.9.2` и `1.9.3`. Если в одной из этих сред что-то работает неправильно, либо вообще не работает, то это следует считать багом, и написать об этом в [issues на Github](https://github.com/7even/vkontakte_api/issues).
|
data/lib/vkontakte_api.rb
CHANGED
@@ -25,7 +25,16 @@ module VkontakteApi
|
|
25
25
|
extend VkontakteApi::Configuration
|
26
26
|
extend VkontakteApi::Authorization
|
27
27
|
extend VkontakteApi::Uploading
|
28
|
+
|
29
|
+
class << self
|
30
|
+
# Creates a short alias `VK` for `VkontakteApi` module.
|
31
|
+
def register_alias
|
32
|
+
Object.const_set(:VK, VkontakteApi)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Removes the `VK` alias.
|
36
|
+
def unregister_alias
|
37
|
+
Object.send(:remove_const, :VK) if defined?(VK)
|
38
|
+
end
|
39
|
+
end
|
28
40
|
end
|
29
|
-
|
30
|
-
# short alias
|
31
|
-
VK = VkontakteApi unless defined?(VK)
|
data/lib/vkontakte_api/api.rb
CHANGED
@@ -4,7 +4,7 @@ module VkontakteApi
|
|
4
4
|
# It uses Faraday with middleware underneath the hood.
|
5
5
|
module API
|
6
6
|
# URL prefix for calling API methods.
|
7
|
-
URL_PREFIX = 'https://api.
|
7
|
+
URL_PREFIX = 'https://api.vk.com/method'
|
8
8
|
|
9
9
|
class << self
|
10
10
|
# API method call.
|
@@ -26,7 +26,7 @@ module VkontakteApi
|
|
26
26
|
url = options.delete(:url)
|
27
27
|
token = options.delete(:token)
|
28
28
|
|
29
|
-
Faraday.new(url) do |builder|
|
29
|
+
Faraday.new(url, VkontakteApi.faraday_options) do |builder|
|
30
30
|
builder.request :oauth2, token unless token.nil?
|
31
31
|
builder.request :multipart
|
32
32
|
builder.response :vk_logger
|
@@ -6,7 +6,7 @@ module VkontakteApi
|
|
6
6
|
# @note `VkontakteApi::Configuration` extends `VkontakteApi` so these methods should be called from the latter.
|
7
7
|
module Configuration
|
8
8
|
# Available options.
|
9
|
-
OPTION_NAMES = [:app_id, :app_secret, :redirect_uri, :adapter, :logger, :log_requests, :log_errors, :log_responses]
|
9
|
+
OPTION_NAMES = [:app_id, :app_secret, :redirect_uri, :adapter, :faraday_options, :logger, :log_requests, :log_errors, :log_responses]
|
10
10
|
|
11
11
|
attr_accessor *OPTION_NAMES
|
12
12
|
|
@@ -37,11 +37,12 @@ module VkontakteApi
|
|
37
37
|
|
38
38
|
# Reset all configuration options to defaults.
|
39
39
|
def reset
|
40
|
-
@adapter
|
41
|
-
@
|
42
|
-
@
|
43
|
-
@
|
44
|
-
@
|
40
|
+
@adapter = DEFAULT_ADAPTER
|
41
|
+
@faraday_options = {}
|
42
|
+
@logger = ::Logger.new(STDOUT)
|
43
|
+
@log_requests = DEFAULT_LOGGER_OPTIONS[:requests]
|
44
|
+
@log_errors = DEFAULT_LOGGER_OPTIONS[:errors]
|
45
|
+
@log_responses = DEFAULT_LOGGER_OPTIONS[:responses]
|
45
46
|
end
|
46
47
|
|
47
48
|
# When this module is extended, set all configuration options to their default values.
|
data/spec/integration_spec.rb
CHANGED
@@ -3,8 +3,9 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe "Integration" do
|
5
5
|
before(:all) do
|
6
|
+
VkontakteApi.register_alias
|
6
7
|
# turn off all the logging
|
7
|
-
|
8
|
+
VK.configure do |config|
|
8
9
|
config.log_requests = false
|
9
10
|
config.log_errors = false
|
10
11
|
config.log_responses = false
|
@@ -13,20 +14,20 @@ describe "Integration" do
|
|
13
14
|
|
14
15
|
describe "unauthorized requests" do
|
15
16
|
before(:each) do
|
16
|
-
@vk =
|
17
|
+
@vk = VK::Client.new
|
17
18
|
end
|
18
19
|
|
19
20
|
it "get users" do
|
20
21
|
user = @vk.users.get(:uid => 1).first
|
21
22
|
user.uid.should == 1
|
22
|
-
user.last_name.
|
23
|
-
user.first_name.
|
23
|
+
user.last_name.should_not be_empty
|
24
|
+
user.first_name.should_not be_empty
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
28
|
describe "authorized requests" do
|
28
29
|
before(:each) do
|
29
|
-
@vk =
|
30
|
+
@vk = VK::Client.new(ENV['TOKEN'])
|
30
31
|
end
|
31
32
|
|
32
33
|
it "get groups" do
|
@@ -37,7 +38,7 @@ describe "Integration" do
|
|
37
38
|
|
38
39
|
describe "requests with camelCase and predicate methods" do
|
39
40
|
before(:each) do
|
40
|
-
@vk =
|
41
|
+
@vk = VK::Client.new(ENV['TOKEN'])
|
41
42
|
end
|
42
43
|
|
43
44
|
it "convert method names to vk.com format" do
|
@@ -47,12 +48,12 @@ describe "Integration" do
|
|
47
48
|
|
48
49
|
describe "requests with array arguments" do
|
49
50
|
before(:each) do
|
50
|
-
@vk =
|
51
|
+
@vk = VK::Client.new
|
51
52
|
end
|
52
53
|
|
53
54
|
it "join arrays with a comma" do
|
54
55
|
users = @vk.users.get(:uids => [1, 2, 3], :fields => %w[first_name last_name screen_name])
|
55
|
-
users.first.screen_name.
|
56
|
+
users.first.screen_name.should_not be_empty
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
@@ -66,19 +67,20 @@ describe "Integration" do
|
|
66
67
|
"#{user.last_name} #{user.first_name}"
|
67
68
|
end
|
68
69
|
|
69
|
-
users.first.
|
70
|
+
users.first.should_not be_empty
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
73
74
|
describe "authorization" do
|
74
75
|
context "with a scope" do
|
75
76
|
it "returns a correct url" do
|
76
|
-
|
77
|
+
VK.authorization_url(:scope => %w[friends groups]).should include('scope=friends%2Cgroups')
|
77
78
|
end
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
81
82
|
after(:all) do
|
82
|
-
|
83
|
+
VK.reset
|
84
|
+
VK.unregister_alias
|
83
85
|
end
|
84
86
|
end
|
@@ -34,9 +34,11 @@ describe VkontakteApi::API do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
describe ".connection" do
|
37
|
-
it "uses the :url parameter" do
|
37
|
+
it "uses the :url parameter and VkontakteApi.faraday_options" do
|
38
|
+
faraday_options = stub("Faraday options")
|
39
|
+
VkontakteApi.stub(:faraday_options).and_return(faraday_options)
|
38
40
|
url = stub("URL")
|
39
|
-
Faraday.should_receive(:new).with(url)
|
41
|
+
Faraday.should_receive(:new).with(url, faraday_options)
|
40
42
|
connection = subject.connection(:url => url)
|
41
43
|
end
|
42
44
|
|
@@ -24,6 +24,7 @@ describe VkontakteApi::Configuration do
|
|
24
24
|
Configurable.app_id.should be_nil
|
25
25
|
Configurable.app_secret.should be_nil
|
26
26
|
Configurable.adapter.should == VkontakteApi::Configuration::DEFAULT_ADAPTER
|
27
|
+
Configurable.faraday_options.should == {}
|
27
28
|
|
28
29
|
Configurable.logger.should be_a(Logger)
|
29
30
|
Configurable.should log_requests
|
data/spec/vkontakte_api_spec.rb
CHANGED
@@ -15,4 +15,37 @@ describe VkontakteApi do
|
|
15
15
|
VkontakteApi.reset
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
describe ".register_alias" do
|
20
|
+
it "creates a VK alias" do
|
21
|
+
VkontakteApi.register_alias
|
22
|
+
VK.should == VkontakteApi
|
23
|
+
end
|
24
|
+
|
25
|
+
after(:each) do
|
26
|
+
VkontakteApi.unregister_alias
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe ".unregister_alias" do
|
31
|
+
context "after calling .register_alias" do
|
32
|
+
before(:each) do
|
33
|
+
VkontakteApi.register_alias
|
34
|
+
end
|
35
|
+
|
36
|
+
it "removes the alias" do
|
37
|
+
VkontakteApi.unregister_alias
|
38
|
+
expect {
|
39
|
+
VK
|
40
|
+
}.to raise_error(NameError)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "without creating an alias" do
|
45
|
+
it "does nothing" do
|
46
|
+
Object.should_not_receive(:remove_const)
|
47
|
+
VkontakteApi.unregister_alias
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
18
51
|
end
|
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.
|
4
|
+
version: 1.0.rc3
|
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-
|
12
|
+
date: 2012-07-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|