Class: Footrest::Client

Inherits:
Object
  • Object
show all
Includes:
Connection, Request
Defined in:
lib/footrest/client.rb

Constant Summary collapse

CONFIG_ACCESSORS =

Well-known options surfaced as reader/writer methods (e.g. client.token). Any other option remains reachable through #config (e.g. config).

%i[token prefix logging].freeze

Instance Method Summary collapse

Methods included from Request

#delete, #get, #patch, #post, #put, #request, #request_with_params_in_body, #request_with_params_in_url

Methods included from Connection

#set_connection

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:



14
15
16
17
18
# File 'lib/footrest/client.rb', line 14

def initialize(options={}, &block)
  config.merge!(options)
  yield self if block_given?
  set_connection(config)
end

Instance Method Details

#configObject

Per-instance options bag. ActiveSupport::OrderedOptions supports both hash-style (config) and method-style (config.token) access, the same surface ActiveSupport::Configurable’s config object provided. This replaces ‘include ActiveSupport::Configurable`, which activesupport deprecates in 8.1 and removes in 8.2.



25
26
27
# File 'lib/footrest/client.rb', line 25

def config
  @config ||= ActiveSupport::OrderedOptions.new
end

#connection(&block) ⇒ Object



34
35
36
37
38
# File 'lib/footrest/client.rb', line 34

def connection(&block)
  @connection.tap do |conn|
    yield conn if block_given?
  end
end

#fullpath(path) ⇒ Object



40
41
42
43
# File 'lib/footrest/client.rb', line 40

def fullpath(path)
  return path if path =~ /^https?:/i
  prefix ? join(prefix, path) : path
end