Sha256: dc78da578621152ac6427d3c76b71ed72c6b7ca69790fd487451157bd7a6672e

Contents?: true

Size: 1.37 KB

Versions: 21

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module MyApiClient
  # Description of Base
  class Base
    include MyApiClient::Config
    include MyApiClient::ErrorHandling
    include MyApiClient::Exceptions
    include MyApiClient::Request

    if ActiveSupport::VERSION::STRING >= '5.2.0'
      class_attribute :logger, instance_writer: false, default: ::Logger.new(STDOUT)
      class_attribute :error_handlers, instance_writer: false, default: []
    else
      class_attribute :logger
      class_attribute :error_handlers
      self.logger = ::Logger.new(STDOUT)
      self.error_handlers = []
    end

    # NOTE: This class **MUST NOT** implement #initialize method. Because it
    #       will become constraint that need call #super in the #initialize at
    #       definition of the child classes.

    HTTP_METHODS = %i[get post patch delete].freeze

    HTTP_METHODS.each do |http_method|
      class_eval <<~METHOD, __FILE__, __LINE__ + 1
        # Description of #undefined
        #
        # @param pathname [String]
        # @param headers [Hash, nil]
        # @param query [Hash, nil]
        # @param body [Hash, nil]
        # @return [Sawyer::Resouce] description_of_returned_object
        def #{http_method}(pathname, headers: nil, query: nil, body: nil)
          _request :#{http_method}, pathname, headers, query, body, logger
        end
      METHOD
    end
    alias put patch
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
my_api_client-0.11.0 lib/my_api_client/base.rb
my_api_client-0.10.3 lib/my_api_client/base.rb
my_api_client-0.10.2 lib/my_api_client/base.rb
my_api_client-0.10.1 lib/my_api_client/base.rb
my_api_client-0.10.0 lib/my_api_client/base.rb
my_api_client-0.9.2 lib/my_api_client/base.rb
my_api_client-0.9.1 lib/my_api_client/base.rb
my_api_client-0.9.0 lib/my_api_client/base.rb
my_api_client-0.8.0 lib/my_api_client/base.rb
my_api_client-0.7.0 lib/my_api_client/base.rb
my_api_client-0.6.2 lib/my_api_client/base.rb
my_api_client-0.6.1 lib/my_api_client/base.rb
my_api_client-0.6.0 lib/my_api_client/base.rb
my_api_client-0.5.3 lib/my_api_client/base.rb
my_api_client-0.5.2 lib/my_api_client/base.rb
my_api_client-0.5.1 lib/my_api_client/base.rb
my_api_client-0.5.0 lib/my_api_client/base.rb
my_api_client-0.4.0 lib/my_api_client/base.rb
my_api_client-0.3.0 lib/my_api_client/base.rb
my_api_client-0.2.0 lib/my_api_client/base.rb