class TLAW::APIPath
Base class for all API
pathes: entire API
, namespaces and endpoints. Allows to define params and post-processors on any level.
Constants
- CLASS_NAMES
@private
Attributes
base_url[RW]
@private
docs_link[RW]
@private
path[RW]
@private
xml[RW]
@private
Public Class Methods
class_name()
click to toggle source
@private
# File lib/tlaw/api_path.rb, line 25 def class_name # TODO: # * validate if it is classifiable # * provide additional option for non-default class name CLASS_NAMES[symbol] || Util.camelize(symbol.to_s) end
define_method_on(host)
click to toggle source
@private
# File lib/tlaw/api_path.rb, line 112 def define_method_on(host) file, line = method(:to_code).source_location # line + 1 is where real definition, theoretically, starts host.module_eval(to_code, file, line + 1) end
describe(definition = nil)
click to toggle source
Redefined on descendants, it just allows you to do `api.namespace.describe` or `api.namespace1.namespace2.endpoints.describe` and have reasonable useful description printed.
@return [Util::Description] It is just description string but with
redefined `#inspect` to be pretty-printed in console.
# File lib/tlaw/api_path.rb, line 95 def describe(definition = nil) Util::Description.new( ".#{definition || to_method_definition}" + (description ? "\n" + description.indent(' ') + "\n" : '') + (param_set.empty? ? '' : "\n" + param_set.describe.indent(' ')) ) end
describe_short()
click to toggle source
@private
# File lib/tlaw/api_path.rb, line 104 def describe_short Util::Description.new( ".#{to_method_definition}" + (description ? "\n" + description_first_para.indent(' ') : '') ) end
description()
click to toggle source
@private
# File lib/tlaw/api_path.rb, line 38 def description return unless @description || @docs_link Util::Description.new( [@description, ("Docs: #{@docs_link}" if @docs_link)] .compact.join("\n\n") ) end
description=(descr)
click to toggle source
@private
# File lib/tlaw/api_path.rb, line 33 def description=(descr) @description = Util::Description.new(descr) end
inherit(namespace, **attrs)
click to toggle source
@private
# File lib/tlaw/api_path.rb, line 48 def inherit(namespace, **attrs) Class.new(self).tap do |subclass| attrs.each { |a, v| subclass.send("#{a}=", v) } namespace.const_set(subclass.class_name, subclass) end end
new(**parent_params)
click to toggle source
# File lib/tlaw/api_path.rb, line 127 def initialize(**parent_params) @parent_params = parent_params end
param_set()
click to toggle source
@return [ParamSet]
# File lib/tlaw/api_path.rb, line 75 def param_set @param_set ||= ParamSet.new end
params_from_path!()
click to toggle source
@private
# File lib/tlaw/api_path.rb, line 56 def params_from_path! Addressable::Template.new(path).keys.each do |key| param_set.add key.to_sym, keyword: false end end
response_processor()
click to toggle source
@private
# File lib/tlaw/api_path.rb, line 80 def response_processor @response_processor ||= ResponseProcessor.new end
setup_parents(parent)
click to toggle source
@private
# File lib/tlaw/api_path.rb, line 63 def setup_parents(parent) param_set.parent = parent.param_set response_processor.parent = parent.response_processor end
symbol()
click to toggle source
@private
# File lib/tlaw/api_path.rb, line 13 def symbol # FIXME: the second part is necessary only for describes, # and probably should not be here. @symbol || (name && "#{name}.new") end
symbol=(sym)
click to toggle source
@private
# File lib/tlaw/api_path.rb, line 69 def symbol=(sym) @symbol = sym @path ||= "/#{sym}" end
to_method_definition()
click to toggle source
@private
# File lib/tlaw/api_path.rb, line 85 def to_method_definition "#{symbol}(#{param_set.to_code})" end
Private Class Methods
description_first_para()
click to toggle source
# File lib/tlaw/api_path.rb, line 120 def description_first_para description.split("\n\n").first end
Private Instance Methods
object_class()
click to toggle source
# File lib/tlaw/api_path.rb, line 133 def object_class self.class end