lib/plaid/api_client.rb
def call_api(http_method, path, opts = {})
      connection = Faraday.new(:url => config.base_url) do |conn|
        if opts[:header_params]["Content-Type"] == "multipart/form-data"
          conn.request :multipart
          conn.request :url_encoded
        end
        conn.adapter(Faraday.default_adapter)
      end

      begin
        response = connection.public_send(http_method.to_sym.downcase) do |req|
          build_request(http_method, path, req, opts)
        end

        if @config.debugging
          @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
        end

        unless response.success?
          if response.status == 0
            # Errors from libcurl will be made visible here
            fail ApiError.new(:code => 0,
                              :message => response.return_message)
          else
            fail ApiError.new(:code => response.status,
                              :response_headers => response.headers,
                              :response_body => response.body,
                              :data => JSON.parse(response.body)),
                 response.reason_phrase
          end
        end
      rescue Faraday::TimeoutError
        fail ApiError.new('Connection timed out')
      end

      if opts[:return_type]
        prepare_file(response) if opts[:return_type] == 'File'
        data = deserialize(response, opts[:return_type])
      else
        data = nil
      end
      return data, response.status, response.headers
    end
# Call an API with given options.
#
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
#   the data deserialized from response body (could be nil), response status code and response headers.
Call an API with given options.
Call an API with given options .
def call_api(http_method, path, opts = {})
      connection = Faraday.new(:url => config.base_url) do |conn|
        if opts[:header_params]["Content-Type"] == "multipart/form-data"
          conn.request :multipart
          conn.request :url_encoded
        end
        conn.adapter(Faraday.default_adapter)
      end
      begin
        response = connection.public_send(http_method.to_sym.downcase) do |req|
          build_request(http_method, path, req, opts)
        end
        if @config.debugging
          @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
        end
        unless response.success?
          if response.status == 0
            fail ApiError.new(:code => 0,
                              :message => response.return_message)
          else
            fail ApiError.new(:code => response.status,
                              :response_headers => response.headers,
                              :response_body => response.body,
                              :data => JSON.parse(response.body)),
                 response.reason_phrase
          end
        end
      rescue Faraday::TimeoutError
        fail ApiError.new('Connection timed out')
      end
      if opts[:return_type]
        prepare_file(response) if opts[:return_type] == 'File'
        data = deserialize(response, opts[:return_type])
      else
        data = nil
      end
      return data, response.status, response.headers
    end
def call_api ( http_method , path , opts = { } ) connection = Faraday . new ( :url => config . base_url ) do | conn | if opts [ :header_params ] [ "Content-Type" ] == "multipart/form-data" conn . request :multipart conn . request :url_encoded end conn . adapter ( Faraday . default_adapter ) end begin response = connection . public_send ( http_method . to_sym . downcase ) do | req | build_request ( http_method , path , req , opts ) end if @config . debugging @config . logger . debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n" end unless response . success? if response . status == 0 fail ApiError . new ( :code => 0 , :message => response . return_message ) else fail ApiError . new ( :code => response . status , :response_headers => response . headers , :response_body => response . body , :data => JSON . parse ( response . body ) ) , response . reason_phrase end end rescue Faraday :: TimeoutError fail ApiError . new ( 'Connection timed out' ) end if opts [ :return_type ] prepare_file ( response ) if opts [ :return_type ] == 'File' data = deserialize ( response , opts [ :return_type ] ) else data = nil end return data , response . status , response . headers end
Call an API with given options.
Call an API with given options .
# Errors from libcurl will be made visible here
an array of 3 elements: the data deserialized from response body (could be nil), response status code and response headers.
an array of 3 elements : the data deserialized from response body ( could be nil ) response status code and response headers .
Array<(Object, Integer, Hash)>
http_method
path
opts