class ClientApiBuilder::NestedRouter

Attributes

root_router[R]

Public Class Methods

get_instance_method(var) click to toggle source
# File lib/client_api_builder/nested_router.rb, line 17
def self.get_instance_method(var)
  "\#{root_router.#{var}\}"
end
new(root_router) click to toggle source
# File lib/client_api_builder/nested_router.rb, line 13
def initialize(root_router)
  @root_router = root_router
end

Public Instance Methods

base_url(options) click to toggle source
# File lib/client_api_builder/nested_router.rb, line 37
def base_url(options)
  self.class.base_url || root_router.base_url(options)
end
build_body(body, options) click to toggle source
# File lib/client_api_builder/nested_router.rb, line 88
def build_body(body, options)
  root_router.build_body(body, options)
end
build_connection_options(options) click to toggle source
# File lib/client_api_builder/nested_router.rb, line 60
def build_connection_options(options)
  root_router.build_connection_options(options)
end
build_headers(options) click to toggle source
# File lib/client_api_builder/nested_router.rb, line 41
def build_headers(options)
  headers = root_router.build_headers(options)

  add_header_proc = proc do |name, value|
    headers[name] =
      if value.is_a?(Proc)
        root_router.instance_eval(&value)
      elsif value.is_a?(Symbol)
        root_router.send(value)
      else
        value
      end
  end

  self.class.headers.each(&add_header_proc)

  headers
end
build_query(query, options) click to toggle source
# File lib/client_api_builder/nested_router.rb, line 64
def build_query(query, options)
  return nil if query.nil? && root_router.class.query_params.empty? && self.class.query_params.empty?

  query_params = {}

  add_query_param_proc = proc do |name, value|
    query_params[name] =
      if value.is_a?(Proc)
        root_router.instance_eval(&value)
      elsif value.is_a?(Symbol)
        root_router.send(value)
      else
        value
      end
  end

  root_router.class.query_params.each(&add_query_param_proc)
  self.class.query_params.each(&add_query_param_proc)
  query && query.each(&add_query_param_proc)
  options[:query] && options[:query].each(&add_query_param_proc)

  self.class.build_query(query_params)
end
expected_response_code!(response, expected_response_codes, options) click to toggle source
# File lib/client_api_builder/nested_router.rb, line 92
def expected_response_code!(response, expected_response_codes, options)
  root_router.expected_response_code!(response, expected_response_codes, options)
end
handle_response(response, options, &block) click to toggle source
# File lib/client_api_builder/nested_router.rb, line 96
def handle_response(response, options, &block)
  root_router.handle_response(response, options, &block)
end
request(**options, &block) click to toggle source
# File lib/client_api_builder/nested_router.rb, line 21
def request(**options, &block)
  root_router.request(**options, &block)
end
stream(**options, &block) click to toggle source
# File lib/client_api_builder/nested_router.rb, line 25
def stream(**options, &block)
  root_router.stream(**options, &block)
end
stream_to_file(**options, &block) click to toggle source
# File lib/client_api_builder/nested_router.rb, line 33
def stream_to_file(**options, &block)
  root_router.stream_to_file(**options, &block)
end
stream_to_io(**options, &block) click to toggle source
# File lib/client_api_builder/nested_router.rb, line 29
def stream_to_io(**options, &block)
  root_router.stream_to_io(**options, &block)
end