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

key[R]

@return [String] Unformatted API path, using Kernel.format

syntax referencing keys in {params}.
params[R]

@return [Hash] Parameters that are passed to be used when formatting

the API path.
rl_key[R]

@return [String] String that defines an endpoint based on HTTP verb,

API path, and major parameter if any.
verb[R]

@return [Symbol, String] HTTP verb to be used when accessing the API

path.

Public Class Methods

new(verb, key, **params) click to toggle source

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

==(other) click to toggle source

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() click to toggle source

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
major_param() click to toggle source

@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