Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ end

### Загрузка файлов

Загрузка файлов на сервера ВКонтакте осуществляется в несколько этапов: сначала вызывается метод API, возвращающий URL для загрузки, затем происходит сама загрузка файлов, и после этого в некоторых случаях нужно вызвать другой метод API, передав в параметрах данные, возвращенные сервером после предыдущего запроса. Вызываемые методы API зависят от типа загружаемых файлов и описаны в [соответствующем разделе документации](https://vk.com/dev/upload_files).
Загрузка файлов на сервера ВКонтакте осуществляется в несколько этапов: сначала вызывается метод API, возвращающий URL для загрузки, затем происходит сама загрузка файлов, и после этого в некоторых случаях нужно вызвать другой метод API, передав в параметрах данные, возвращенные сервером после предыдущего запроса. Вызываемые методы API зависят от типа загружаемых файлов и описаны в [соответствующем разделе документации](https://vk.ru/dev/upload_files).

Файлы передаются в формате хэша, где ключом является название параметра в запросе (указано в документации, например для загрузки фото на стену это будет `photo`), а значением — массив из 2 строк: полный путь к файлу и его MIME-тип:

Expand All @@ -80,13 +80,13 @@ VkontakteApi.upload(url: url, photo: [file_io, 'image/jpeg', '/path/to/file.jpg'

Для вызова большинства методов требуется токен доступа (access token). Чтобы получить его, можно использовать авторизацию, встроенную в `vkontakte_api`, либо положиться на какой-то другой механизм (например, [OmniAuth](https://github.com/intridea/omniauth)). В последнем случае в результате авторизации будет получен токен, который нужно будет передать в `VkontakteApi::Client.new`.

Для работы с ВКонтакте API предусмотрено 3 типа авторизации: для сайтов, для клиентских приложений (мобильных либо десктопных, имеющих доступ к управлению браузером) и специальный тип авторизации серверов приложений для вызова административных методов без авторизации самого пользователя. Более подробно они описаны [тут](https://vk.com/dev/authentication); рассмотрим, как работать с ними средствами `vkontakte_api`.
Для работы с ВКонтакте API предусмотрено 3 типа авторизации: для сайтов, для клиентских приложений (мобильных либо десктопных, имеющих доступ к управлению браузером) и специальный тип авторизации серверов приложений для вызова административных методов без авторизации самого пользователя. Более подробно они описаны [тут](https://vk.ru/dev/authentication); рассмотрим, как работать с ними средствами `vkontakte_api`.

Для авторизации необходимо задать параметры `app_id` (ID приложения), `app_secret` (защищенный ключ) и `redirect_uri` (адрес, куда пользователь будет направлен после предоставления прав приложению) в настройках `VkontakteApi.configure`. Более подробно о конфигурировании `vkontakte_api` см. далее в соответствующем разделе.

##### Сайт

Авторизация сайтов проходит в 2 шага. Сначала пользователь перенаправляется на страницу ВКонтакте для подтверждения запрошенных у него прав сайта на доступ к его данным. Со списком возможных прав можно ознакомиться [здесь](https://vk.com/dev/permissions). Допустим, нужно получить доступ к друзьям (`friends`) и фотографиям (`photos`) пользователя.
Авторизация сайтов проходит в 2 шага. Сначала пользователь перенаправляется на страницу ВКонтакте для подтверждения запрошенных у него прав сайта на доступ к его данным. Со списком возможных прав можно ознакомиться [здесь](https://vk.ru/dev/permissions). Допустим, нужно получить доступ к друзьям (`friends`) и фотографиям (`photos`) пользователя.

В соответствии с [рекомендациями](http://tools.ietf.org/html/draft-ietf-oauth-v2-30#section-10.12) в протоколе OAuth2 для защиты от [CSRF](http://ru.wikipedia.org/wiki/%D0%9F%D0%BE%D0%B4%D0%B4%D0%B5%D0%BB%D0%BA%D0%B0_%D0%BC%D0%B5%D0%B6%D1%81%D0%B0%D0%B9%D1%82%D0%BE%D0%B2%D1%8B%D1%85_%D0%B7%D0%B0%D0%BF%D1%80%D0%BE%D1%81%D0%BE%D0%B2), нужно передать параметр `state`, содержащий случайное значение.

Expand Down Expand Up @@ -269,7 +269,7 @@ end
[любой другой адаптер](https://github.com/lostisland/faraday/blob/master/lib/faraday/adapter.rb),
поддерживаемый `faraday`.

ВКонтакте [позволяет](https://vk.com/dev/api_requests)
ВКонтакте [позволяет](https://vk.ru/dev/api_requests)
использовать как `GET`-, так и `POST`-запросы при вызове методов API.
По умолчанию `vkontakte_api` использует `POST`, но в настройке `http_verb`
можно указать `:get`, чтобы совершать `GET`-запросы.
Expand Down
8 changes: 4 additions & 4 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ end

### File upload

Files can be uploaded to VKontakte in several steps: first you need to call an API method that returns a URL to upload to; then upload the file(s) and in some cases call another finalization API method with uploaded file params. The API methods to call depend on the uploaded file type and are described in the [documentation](https://vk.com/dev/upload_files).
Files can be uploaded to VKontakte in several steps: first you need to call an API method that returns a URL to upload to; then upload the file(s) and in some cases call another finalization API method with uploaded file params. The API methods to call depend on the uploaded file type and are described in the [documentation](https://vk.ru/dev/upload_files).

Files are transferred in a Hash format, where key is the name of the request parameter (described in documentation, for example `photo` when uploading photos), and the value is an array composed of 2 strings: full path to the file and it's MIME-type:

Expand All @@ -78,13 +78,13 @@ The `upload` method returns VKontakte server response converted to `Hashie::Mash

Most of methods require an access token to be called. To get this token, you can use authorization built in `vkontakte_api` or any other solution (for example [OmniAuth](https://github.com/intridea/omniauth)). In the latter case the result of authorization process is a token, which needs to be passed into `VkontakteApi::Client.new`.

VKontakte API provides 3 types of authorization: for webpages, for client applications (mobile or desktop, having access to authorized browsers) and special authorization type for servers to invoke administration methods without user authorization. More details are available [here](https://vk.com/dev/authentication); let's see how to use them with `vkontakte_api`.
VKontakte API provides 3 types of authorization: for webpages, for client applications (mobile or desktop, having access to authorized browsers) and special authorization type for servers to invoke administration methods without user authorization. More details are available [here](https://vk.ru/dev/authentication); let's see how to use them with `vkontakte_api`.

For the purposes of authorization you have to specify `app_id` (application ID), `app_secret` (secret key) and `redirect_uri` (a URL where the user will be redirected after successful authorization) in the `VkontakteApi.configure` settings. For more information about configuring `vkontakte_api` see below.

##### Website

Website authorization goes in 2 steps. First user is redirected to VKontakte website to confirm the rights of a website to access his data. The list of available permissions is avaliable [here](https://vk.com/dev/permissions). Let's suppose one wants to access friends (`friends`) and photos (`photos`) of the user.
Website authorization goes in 2 steps. First user is redirected to VKontakte website to confirm the rights of a website to access his data. The list of available permissions is avaliable [here](https://vk.ru/dev/permissions). Let's suppose one wants to access friends (`friends`) and photos (`photos`) of the user.

According to the [guidelines](http://tools.ietf.org/html/draft-ietf-oauth-v2-30#section-10.12) in OAuth2 protocol the `state` parameter should be passed with a random number in order to prevent [CSRF](http://ru.wikipedia.org/wiki/%D0%9F%D0%BE%D0%B4%D0%B4%D0%B5%D0%BB%D0%BA%D0%B0_%D0%BC%D0%B5%D0%B6%D1%81%D0%B0%D0%B9%D1%82%D0%BE%D0%B2%D1%8B%D1%85_%D0%B7%D0%B0%D0%BF%D1%80%D0%BE%D1%81%D0%BE%D0%B2).

Expand Down Expand Up @@ -268,7 +268,7 @@ By default the `Net::HTTP` Faraday adapter is used but you can choose
[any other adapter](https://github.com/lostisland/faraday/blob/master/lib/faraday/adapter.rb)
supported by `faraday`.

VKontakte [allows](https://vk.com/dev/api_requests)
VKontakte [allows](https://vk.ru/dev/api_requests)
using either `GET` or `POST` requests when calling API methods.
`vkontakte_api` uses `POST` by default but you can change that by
setting `http_verb` to `:get`.
Expand Down
2 changes: 1 addition & 1 deletion lib/vkontakte_api/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module VkontakteApi
# It uses Faraday with middleware underneath the hood.
module API
# URL prefix for calling API methods.
URL_PREFIX = 'https://api.vk.com/method'
URL_PREFIX = 'https://api.vk.ru/method'

class << self
# API method call.
Expand Down
2 changes: 1 addition & 1 deletion lib/vkontakte_api/authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Authorization
# Authorization options.
OPTIONS = {
client: {
site: 'https://oauth.vk.com',
site: 'https://oauth.vk.ru',
authorize_url: '/authorize',
token_url: '/access_token'
},
Expand Down
2 changes: 1 addition & 1 deletion spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
end

describe "requests with camelCase and predicate methods" do
it "convert method names to vk.com format" do
it "convert method names to vk.ru format" do
expect(vk.is_app_user?).to be_truthy
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/support/mechanized_authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def client(scope: [:friends, :groups])
configure
agent.get VkontakteApi.authorization_url(scope: scope, type: :client)

agent.page.form_with(action: /login.vk.com/) do |form|
agent.page.form_with(action: /login.vk.ru/) do |form|
form.email = settings.email
form.pass = settings.password
end.submit
Expand Down