Sha256: 57de9e3c5d16b53a78d6a289c949c80a8a4eaae2f6dcf1db9f0794f3fd9ce74c

Contents?: true

Size: 1.97 KB

Versions: 10

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true

module MyApiClient
  # Provides HTTP request method.
  module Request
    include Basic
    include Pagination

    private

    # Executes HTTP request with relative URI.
    #
    # @param http_method [Symbol]
    #   HTTP method. e.g. `:get`, `:post`, `:put`, `:patch` and `:delete`.
    # @param pathname [String]
    #   Pathname of the request target URL.
    #   It's joined with the defined by `endpoint`.
    # @param headers [Hash, nil]
    #   Request headers.
    # @param query [Hash, nil]
    #   Query string.
    # @param body [Hash, nil]
    #   Request body.
    # @return [Sawyer::Response]
    #   Response instance.
    def _request_with_relative_uri(http_method, pathname, headers, query, body)
      query_strings = query.present? ? "?#{query.to_query}" : ''
      uri = URI.join(File.join(endpoint, pathname), query_strings)
      _request_with_absolute_uri(http_method, uri, headers, body)
    end

    # Executes HTTP request with absolute URI.
    #
    # @param http_method [Symbol]
    #   HTTP method. e.g. `:get`, `:post`, `:put`, `:patch` and `:delete`.
    # @param uri [URI]
    #   Request target URI including query strings.
    # @param headers [Hash, nil]
    #   Request headers.
    # @param body [Hash, nil]
    #   Request body.
    # @return [Sawyer::Response]
    #   Response instance.
    def _request_with_absolute_uri(http_method, uri, headers, body)
      Executor.call(
        instance: self,
        request_params: Params::Request.new(http_method, uri, headers, body),
        request_logger: Logger.new(logger, http_method, uri),
        faraday_options: faraday_options
      )
    end

    # Generates options for the faraday instance.
    #
    # @return [Hash] Generated options.
    def faraday_options
      {
        request: {
          timeout: (http_read_timeout if respond_to?(:http_read_timeout)),
          open_timeout: (http_open_timeout if respond_to?(:http_open_timeout)),
        }.compact,
      }
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
my_api_client-1.1.0 lib/my_api_client/request.rb
my_api_client-1.0.0 lib/my_api_client/request.rb
my_api_client-0.27.0 lib/my_api_client/request.rb
my_api_client-0.26.0 lib/my_api_client/request.rb
my_api_client-0.25.0 lib/my_api_client/request.rb
my_api_client-0.24.0 lib/my_api_client/request.rb
my_api_client-0.23.0 lib/my_api_client/request.rb
my_api_client-0.22.0 lib/my_api_client/request.rb
my_api_client-0.21.0 lib/my_api_client/request.rb
my_api_client-0.20.0 lib/my_api_client/request.rb