class Vox::HTTP::Route
Route
that contains information about a request path, intended for use with {HTTP::Client#request}.
Constants
- MAJOR_PARAMS
Major parameters that are significant when forming a rate limit key.
Attributes
@return [String] Unformatted API path, using Kernel.format
syntax referencing keys in {params}.
@return [Hash] Parameters that are passed to be used when formatting
the API path.
@return [String] String that defines an endpoint based on HTTP
verb,
API path, and major parameter if any.
@return [Symbol, String] HTTP
verb to be used when accessing the API
path.
Public Class Methods
Create a new route to be used with {Client#request} @param verb [#to_sym] The HTTP
verb to be used when accessing the API path. @param key [String] The unformatted route using Kernel.format syntax to
incorporate the data provided in `params`.
@param params [Hash<String, to_s>] Parameters passed when formatting `key`.
# File lib/vox/http/route.rb, line 32 def initialize(verb, key, **params) @verb = verb.downcase.to_sym @key = key @params = params @rl_key = "#{@verb}:#{@key}:#{major_param}" end
Public Instance Methods
Compare a {Route} or {Route} like object (responds to `#verb`, `#key`, and `#params`). @param other [Route] @return [true, false]
# File lib/vox/http/route.rb, line 55 def ==(other) @verb == other.verb && @key == other.key && @params == other.params end
Format the route with the given params @return [String] Formatted API path.
# File lib/vox/http/route.rb, line 41 def format return @key if @params.empty? Kernel.format(@key, @params) if @params.any? end
@return [String, Integer, nil] The major param value of the route key if any
# File lib/vox/http/route.rb, line 48 def major_param params.slice(*MAJOR_PARAMS).values.first end