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, log: false) ⇒ Client
constructor
Implicit Flow for User Access Token.
- #login!(email, pass, open_captcha: false, permissions: '') ⇒ Object
Constructor Details
#initialize(client_id = nil, api_version: Vkontakte::API_VERSION, proxy: nil, timeout: 60, log: false) ⇒ Client
Implicit Flow for User Access Token
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vkontakte/client.rb', line 11 def initialize( client_id = nil, api_version: Vkontakte::API_VERSION, proxy: nil, timeout: 60, log: false ) @client_id = client_id @api_version = api_version @proxy = proxy @timeout = timeout @authorize = false @log = log @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
73 74 75 |
# File 'lib/vkontakte/client.rb', line 73 def @authorize ? true : false end |
#login!(email, pass, open_captcha: false, permissions: '') ⇒ Object
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 68 69 70 71 |
# File 'lib/vkontakte/client.rb', line 28 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.log = Logger.new($stdout) if @log a.agent.set_socks(@proxy.addr, @proxy.port) if @proxy&.socks? a.agent.set_proxy(@proxy.addr, @proxy.port) if @proxy&.http? end # Opening Authorization Dialog # 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 |