Sha256: ca305bd4a943ffb1d87a63cdb5bdf97b390eb12aa927fa5d33d958795c22a49b

Contents?: true

Size: 1.07 KB

Versions: 11

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module MyApiClient
  module Request
    # Provides basic HTTP request method.
    module Basic
      HTTP_METHODS = %i[get post put patch delete].freeze

      HTTP_METHODS.each do |http_method|
        class_eval <<~METHOD, __FILE__, __LINE__ + 1
          # Executes HTTP request with #{http_method.upcase} method
          #
          # @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. You should not specify it when use GET method.
          # @return [Sawyer::Resource]
          #   Response body instance.
          def #{http_method}(pathname, headers: nil, query: nil, body: nil)
            response = call(:_request_with_relative_uri, :#{http_method}, pathname, headers, query, body)
            response.data
          end
        METHOD
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
my_api_client-0.26.0 lib/my_api_client/request/basic.rb
my_api_client-0.25.0 lib/my_api_client/request/basic.rb
my_api_client-0.24.0 lib/my_api_client/request/basic.rb
my_api_client-0.23.0 lib/my_api_client/request/basic.rb
my_api_client-0.22.0 lib/my_api_client/request/basic.rb
my_api_client-0.21.0 lib/my_api_client/request/basic.rb
my_api_client-0.20.0 lib/my_api_client/request/basic.rb
my_api_client-0.19.0 lib/my_api_client/request/basic.rb
my_api_client-0.18.0 lib/my_api_client/request/basic.rb
my_api_client-0.17.0 lib/my_api_client/request/basic.rb
my_api_client-0.16.1 lib/my_api_client/request/basic.rb