Class: Vkontakte::Client
- Inherits:
-
Object
- Object
- Vkontakte::Client
- Defined in:
- lib/vkontakte/client.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#api_version ⇒ Object
readonly
Returns the value of attribute api_version.
-
#expires_in ⇒ Object
readonly
Returns the value of attribute expires_in.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Instance Method Summary collapse
- #authorized? ⇒ Boolean
-
#initialize(client_id = nil, api_version: Vkontakte::API_VERSION, proxy: nil, timeout: 60) ⇒ Client
constructor
A new instance of Client.
- #login!(email, pass, open_captcha: false, permissions: '') ⇒ Object
Constructor Details
#initialize(client_id = nil, api_version: Vkontakte::API_VERSION, proxy: nil, timeout: 60) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/vkontakte/client.rb', line 8 def initialize( client_id = nil, api_version: Vkontakte::API_VERSION, proxy: nil, timeout: 60 ) @client_id = client_id @api_version = api_version @proxy = proxy @timeout = timeout = false @api = Vkontakte::API.new end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
6 7 8 |
# File 'lib/vkontakte/client.rb', line 6 def access_token @access_token end |
#api ⇒ Object (readonly)
Returns the value of attribute api.
6 7 8 |
# File 'lib/vkontakte/client.rb', line 6 def api @api end |
#api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
6 7 8 |
# File 'lib/vkontakte/client.rb', line 6 def api_version @api_version end |
#expires_in ⇒ Object (readonly)
Returns the value of attribute expires_in.
6 7 8 |
# File 'lib/vkontakte/client.rb', line 6 def expires_in @expires_in end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
6 7 8 |
# File 'lib/vkontakte/client.rb', line 6 def user_id @user_id end |
Instance Method Details
#authorized? ⇒ Boolean
69 70 71 |
# File 'lib/vkontakte/client.rb', line 69 def ? true : false end |
#login!(email, pass, open_captcha: false, permissions: '') ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/vkontakte/client.rb', line 23 def login!(email, pass, open_captcha: false, permissions: '') @email = email @pass = pass redirect_uri = 'https://oauth.vk.com/blank.html' display = 'mobile' response_type = 'token' query = { client_id: @client_id, redirect_uri: redirect_uri, display: display, scope: , response_type: response_type, v: api_version } agent = Mechanize.new do |a| a.user_agent_alias = 'Linux Firefox' a. a.agent.set_socks(@proxy.addr, @proxy.port) if @proxy&.socks? a.agent.set_proxy(@proxy.addr, @proxy.port) if @proxy&.http? end # https://vk.com/dev/implicit_flow_user # # Открытие диалога авторизации OAuth # query_string = query.map { |k, v| "#{k}=#{v}" }.join('&') url = "https://oauth.vk.com/authorize?#{query_string}" page = agent.get(url) login_form = page.forms.first login_form.email = @email login_form.pass = @pass page = login_form.submit raise('Invalid login or password.') unless page.search('.service_msg_warning').empty? page = submit_gain_access_form(page, open_captcha) if page.uri.path == '/authorize' get_token(page) end |