module VkontakteApi::API
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.
Constants
- URL_PREFIX
URL prefix for calling
API
methods.
Public Class Methods
call(method_name, args = {}, token = nil)
click to toggle source
API
method call. @param [String] method_name A full name of the method. @param [Hash] args Method
arguments. @param [String] token The access token. @return [Hashie::Mash] Mashed server response.
# 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 = {})
click to toggle source
Faraday connection. @param [Hash] options Connection options. @option options [String] :url Connection URL (either full or just prefix). @option options [String] :token OAuth2 access token (not used if omitted). @return [Faraday::Connection] Created connection.
# File lib/vkontakte_api/api.rb, line 26 def connection(options = {}) url = options.delete(:url) token = options.delete(:token) Faraday.new(url, VkontakteApi.faraday_options) 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