Class: Vkontakte::API

Inherits:
Object
  • Object
show all
Defined in:
lib/vkontakte/api.rb,
lib/vkontakte/api_error.rb

Overview

Make Vkontakte API requests

vk.com/dev/api_requests

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token = nil, proxy: nil, api_version: Vkontakte::API_VERSION, lang: 'ru', timeout: 60) ⇒ API

Returns a new instance of API.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/vkontakte/api.rb', line 12

def initialize(
  access_token = nil,
  proxy: nil,
  api_version: Vkontakte::API_VERSION,
  lang: 'ru',
  timeout: 60
)
  @access_token = access_token
  @proxy = proxy
  @api_version = api_version
  @lang = lang
  @timeout = timeout
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *params) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vkontakte/api.rb', line 26

def method_missing(method, *params)
  method_name = method.to_s.split('_').join('.')
  response = execute(method_name, *params)
  if response['error']
    error_code = response['error']['error_code']
    error_msg  = response['error']['error_msg']
    raise Vkontakte::API::Error.new(method_name, error_code, error_msg, params)
  end

  response['response']
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



9
10
11
# File 'lib/vkontakte/api.rb', line 9

def access_token
  @access_token
end

#api_versionObject (readonly)

Returns the value of attribute api_version.



9
10
11
# File 'lib/vkontakte/api.rb', line 9

def api_version
  @api_version
end

#langObject

Returns the value of attribute lang.



10
11
12
# File 'lib/vkontakte/api.rb', line 10

def lang
  @lang
end

#proxyObject (readonly)

Returns the value of attribute proxy.



9
10
11
# File 'lib/vkontakte/api.rb', line 9

def proxy
  @proxy
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



9
10
11
# File 'lib/vkontakte/api.rb', line 9

def timeout
  @timeout
end