Class: FaradayCage::Status
- Inherits:
-
Object
- Object
- FaradayCage::Status
- Defined in:
- lib/faraday_cage/status.rb
Overview
Wraps status codes to provide various helper methods for testing a response.
Constant Summary collapse
- MAPPINGS =
{ 100 => :continue, 101 => :switching_protocols, 102 => :processing, 200 => :ok, 201 => :created, 202 => :accepted, 203 => :non_authoritative_information, 204 => :no_content, 205 => :reset_content, 206 => :partial_content, 207 => :multi_status, 226 => :im_used, 300 => :multiple_choices, 301 => :moved_permanently, 302 => :found, 303 => :see_other, 304 => :not_modified, 305 => :use_proxy, 307 => :temporary_redirect, 400 => :bad_request, 401 => :unauthorized, 402 => :payment_required, 403 => :forbidden, 404 => :not_found, 405 => :method_not_allowed, 406 => :not_acceptable, 407 => :proxy_authentication_required, 408 => :request_timeout, 409 => :conflict, 410 => :gone, 411 => :length_required, 412 => :precondition_failed, 413 => :request_entity_too_large, 414 => :request_uri_too_long, 415 => :unsupported_media_type, 416 => :requested_range_not_satisfiable, 417 => :expectation_failed, 422 => :unprocessable_entity, 423 => :locked, 424 => :failed_dependency, 426 => :upgrade_required, 500 => :internal_server_error, 501 => :not_implemented, 502 => :bad_gateway, 503 => :service_unavailable, 504 => :gateway_timeout, 505 => :http_version_not_supported, 507 => :insufficient_storage, 510 => :not_extended }
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
Instance Method Summary collapse
- #==(object) ⇒ Object
- #client_error? ⇒ Boolean
- #error? ⇒ Boolean
- #informational? ⇒ Boolean
-
#initialize(code) ⇒ Status
constructor
A new instance of Status.
- #inspect ⇒ Object
- #name ⇒ Object
- #redirect? ⇒ Boolean
- #server_error? ⇒ Boolean
- #success? ⇒ Boolean
- #to_i ⇒ Object
- #to_s ⇒ Object
- #to_sym ⇒ Object
- #type ⇒ Object
- #unknown? ⇒ Boolean
Constructor Details
#initialize(code) ⇒ Status
Returns a new instance of Status.
93 94 95 |
# File 'lib/faraday_cage/status.rb', line 93 def initialize(code) @code = code.to_i end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
91 92 93 |
# File 'lib/faraday_cage/status.rb', line 91 def code @code end |
Instance Method Details
#==(object) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/faraday_cage/status.rb', line 97 def ==(object) if object.respond_to?(:code) object.code == code else object == code || object == name end end |
#client_error? ⇒ Boolean
148 149 150 |
# File 'lib/faraday_cage/status.rb', line 148 def client_error? type == :client_error end |
#error? ⇒ Boolean
156 157 158 |
# File 'lib/faraday_cage/status.rb', line 156 def error? client_error? || server_error? end |
#informational? ⇒ Boolean
136 137 138 |
# File 'lib/faraday_cage/status.rb', line 136 def informational? type == :informational end |
#inspect ⇒ Object
121 122 123 |
# File 'lib/faraday_cage/status.rb', line 121 def inspect "#<#{self.class} code: #{code.inspect} name: #{name.inspect}>" end |
#name ⇒ Object
105 106 107 |
# File 'lib/faraday_cage/status.rb', line 105 def name @name ||= MAPPINGS[code] end |
#redirect? ⇒ Boolean
144 145 146 |
# File 'lib/faraday_cage/status.rb', line 144 def redirect? type == :redirect end |
#server_error? ⇒ Boolean
152 153 154 |
# File 'lib/faraday_cage/status.rb', line 152 def server_error? type == :server_error end |
#success? ⇒ Boolean
140 141 142 |
# File 'lib/faraday_cage/status.rb', line 140 def success? type == :success end |
#to_i ⇒ Object
109 110 111 |
# File 'lib/faraday_cage/status.rb', line 109 def to_i code end |
#to_s ⇒ Object
113 114 115 |
# File 'lib/faraday_cage/status.rb', line 113 def to_s name.to_s end |
#to_sym ⇒ Object
117 118 119 |
# File 'lib/faraday_cage/status.rb', line 117 def to_sym name end |
#type ⇒ Object
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/faraday_cage/status.rb', line 125 def type @type ||= case code when 100..199 then :informational when 200..299 then :success when 300..399 then :redirect when 400..499 then :client_error when 500..599 then :server_error else :unknown end end |
#unknown? ⇒ Boolean
160 161 162 |
# File 'lib/faraday_cage/status.rb', line 160 def unknown? type == :unknown end |