Module: VkontakteApi::API
- Defined in:
- lib/vkontakte_api/api.rb
Overview
A low-level module which handles the requests to VKontakte API and returns their results as mashes.
It uses Faraday with middleware underneath the hood.
Constant Summary collapse
- URL_PREFIX =
URL prefix for calling API methods.
'https://api.vk.com/method'
Class Method Summary collapse
-
.call(method_name, args = {}, token = nil) ⇒ Hashie::Mash
API method call.
-
.connection(options = {}) ⇒ Faraday::Connection
Faraday connection.
Class Method Details
.call(method_name, args = {}, token = nil) ⇒ Hashie::Mash
API method call.
15 16 17 18 19 |
# File 'lib/vkontakte_api/api.rb', line 15 def call(method_name, args = {}, token = nil) flat_arguments = Utils.flatten_arguments(args) flat_arguments[:v] ||= VkontakteApi.api_version unless VkontakteApi.api_version.nil? connection(url: URL_PREFIX, token: token).send(VkontakteApi.http_verb, method_name, flat_arguments).body end |
.connection(options = {}) ⇒ Faraday::Connection
Faraday connection.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vkontakte_api/api.rb', line 26 def connection( = {}) url = .delete(:url) token = .delete(:token) Faraday.new(url, VkontakteApi.) do |builder| builder.request :oauth2, token, token_type: 'param' unless token.nil? builder.request :multipart builder.request :url_encoded builder.request :retry, VkontakteApi.max_retries builder.response :vk_logger builder.response :mashify builder.response :multi_json, preserve_raw: true builder.adapter VkontakteApi.adapter end end |