Class: Takagi::CoAP::Registries::Response
- Defined in:
- lib/takagi/coap/registries/response.rb
Overview
CoAP Response Code Registry (RFC 7252 ยง12.1.2)
Extensible registry for CoAP response codes. Plugins can register custom response codes without modifying core code.
Class Method Summary collapse
-
.class_for(code) ⇒ Integer
Get the response class (2, 4, 5, etc.).
-
.client_error?(code) ⇒ Boolean
Check if code is a client error (4.xx).
-
.error?(code) ⇒ Boolean
Check if code is any error (4.xx or 5.xx).
-
.server_error?(code) ⇒ Boolean
Check if code is a server error (5.xx).
-
.success?(code) ⇒ Boolean
Check if code is a success (2.xx).
-
.valid?(code) ⇒ Boolean
Check if code is a valid response code.
Methods inherited from Base
all, clear!, each_value, inherited, metadata_for, name_for, register, registered?, rfc_for, value_for, values
Class Method Details
.class_for(code) ⇒ Integer
Get the response class (2, 4, 5, etc.)
52 53 54 |
# File 'lib/takagi/coap/registries/response.rb', line 52 def self.class_for(code) code / 32 end |
.client_error?(code) ⇒ Boolean
Check if code is a client error (4.xx)
66 67 68 |
# File 'lib/takagi/coap/registries/response.rb', line 66 def self.client_error?(code) class_for(code) == 4 end |
.error?(code) ⇒ Boolean
Check if code is any error (4.xx or 5.xx)
80 81 82 |
# File 'lib/takagi/coap/registries/response.rb', line 80 def self.error?(code) client_error?(code) || server_error?(code) end |
.server_error?(code) ⇒ Boolean
Check if code is a server error (5.xx)
73 74 75 |
# File 'lib/takagi/coap/registries/response.rb', line 73 def self.server_error?(code) class_for(code) == 5 end |
.success?(code) ⇒ Boolean
Check if code is a success (2.xx)
59 60 61 |
# File 'lib/takagi/coap/registries/response.rb', line 59 def self.success?(code) class_for(code) == 2 end |
.valid?(code) ⇒ Boolean
Check if code is a valid response code
87 88 89 |
# File 'lib/takagi/coap/registries/response.rb', line 87 def self.valid?(code) code.between?(64, 191) && registered?(code) end |