Class: Vox::HTTP::Route
- Inherits:
-
Object
- Object
- Vox::HTTP::Route
- Defined in:
- lib/vox/http/route.rb
Overview
Route that contains information about a request path, intended for use with Client#request.
Constant Summary collapse
- MAJOR_PARAMS =
Major parameters that are significant when forming a rate limit key.
%i[guild_id channel_id webhook_id].freeze
Instance Attribute Summary collapse
-
#key ⇒ String
readonly
Unformatted API path, using Kernel.format syntax referencing keys in #params.
-
#params ⇒ Hash
readonly
Parameters that are passed to be used when formatting the API path.
-
#rl_key ⇒ String
readonly
String that defines an endpoint based on HTTP verb, API path, and major parameter if any.
-
#verb ⇒ Symbol, String
readonly
HTTP verb to be used when accessing the API path.
Instance Method Summary collapse
- #==(other) ⇒ true, false
-
#format ⇒ String
Format the route with the given params.
-
#initialize(verb, key, **params) ⇒ Route
constructor
Create a new route to be used with Client#request.
-
#major_param ⇒ String, ...
The major param value of the route key if any.
Constructor Details
#initialize(verb, key, **params) ⇒ Route
Create a new route to be used with Client#request
32 33 34 35 36 37 |
# 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 |
Instance Attribute Details
#key ⇒ String (readonly)
Returns Unformatted API path, using Kernel.format syntax referencing keys in #params.
17 18 19 |
# File 'lib/vox/http/route.rb', line 17 def key @key end |
#params ⇒ Hash (readonly)
Returns Parameters that are passed to be used when formatting the API path.
25 26 27 |
# File 'lib/vox/http/route.rb', line 25 def params @params end |
#rl_key ⇒ String (readonly)
Returns String that defines an endpoint based on HTTP verb, API path, and major parameter if any.
21 22 23 |
# File 'lib/vox/http/route.rb', line 21 def rl_key @rl_key end |
#verb ⇒ Symbol, String (readonly)
Returns HTTP verb to be used when accessing the API path.
13 14 15 |
# File 'lib/vox/http/route.rb', line 13 def verb @verb end |
Instance Method Details
#==(other) ⇒ true, false
Compare a Vox::HTTP::Route or Vox::HTTP::Route like object (responds to ‘#verb`, `#key`, and `#params`).
55 56 57 |
# File 'lib/vox/http/route.rb', line 55 def ==(other) @verb == other.verb && @key == other.key && @params == other.params end |
#format ⇒ String
Format the route with the given params
41 42 43 44 45 |
# 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 ⇒ String, ...
Returns The major param value of the route key if any.
48 49 50 |
# File 'lib/vox/http/route.rb', line 48 def major_param params.slice(*MAJOR_PARAMS).values.first end |