Class: VkApi::Client
- Inherits:
-
Object
- Object
- VkApi::Client
- Defined in:
- lib/vk-api/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#expires_in ⇒ Object
readonly
Returns the value of attribute expires_in.
Instance Method Summary collapse
- #api(method, params = {}) ⇒ Object
- #client_auth(login, pass, params) ⇒ Object
-
#initialize(params) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(params) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/vk-api/client.rb', line 5 def initialize(params) @params = { redirect_url: 'https://oauth.vk.com/blank.html', version: '5.28', settings: 'notify,friends,offline', display: 'page', host: 'https://api.vk.com' } @params.merge! params end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
2 3 4 |
# File 'lib/vk-api/client.rb', line 2 def access_token @access_token end |
#expires_in ⇒ Object (readonly)
Returns the value of attribute expires_in.
3 4 5 |
# File 'lib/vk-api/client.rb', line 3 def expires_in @expires_in end |
Instance Method Details
#api(method, params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vk-api/client.rb', line 17 def api(method, params = {}) params[:version] ||= @params[:version] params[:access_token] ||= @access_token url = URI.encode_www_form(params) url = "#{@params[:host]}/method/#{method}?#{url}" res = browser.request url if res['error'] raise VkApi::ApiError.new({ name: 'API', description: 'error', more: res['error'] }) else res end end |
#client_auth(login, pass, params) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vk-api/client.rb', line 32 def client_auth(login, pass, params) @params.merge! params browser.sign_in login, pass browser.security_hack login @expires_in = browser.response['expires_in'] @access_token = browser.response['access_token'] raise VkApi::AuthError.new({name: 'Auth', description: 'login or password is incorrect'}) unless @access_token return @access_token, @expires_in end |