lib/vkontakte_api/api.rb in vkontakte_api-1.3.1 vs lib/vkontakte_api/api.rb in vkontakte_api-1.4

- old
+ new

@@ -1,8 +1,8 @@ module VkontakteApi # 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. module API # URL prefix for calling API methods. URL_PREFIX = 'https://api.vk.com/method' @@ -12,10 +12,11 @@ # @param [Hash] args Method arguments. # @param [String] token The access token. # @return [Hashie::Mash] Mashed server response. 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 # Faraday connection. # @param [Hash] options Connection options. @@ -25,17 +26,19 @@ def connection(options = {}) url = options.delete(:url) token = options.delete(:token) Faraday.new(url, VkontakteApi.faraday_options) do |builder| - builder.request :oauth2, token unless token.nil? - builder.request :multipart - builder.request :url_encoded - builder.request :retry, VkontakteApi.max_retries + builder.request :oauth2, token 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 :oj, preserve_raw: true - builder.adapter VkontakteApi.adapter + + builder.adapter VkontakteApi.adapter end end end end end