Class: Webclient::Response::Status
- Inherits:
-
Object
- Object
- Webclient::Response::Status
- Defined in:
- lib/webclient/webclient_response-status.rb
Overview
nested class Response::Status
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
fix-fix-fix maybe fold back into response.status | status_code response.status_message | status_msg keep it simple?.
Instance Method Summary collapse
-
#==(other) ⇒ Object
note - allow compare with integer e.g.
- #error? ⇒ Boolean
-
#initialize(code, message: nil) ⇒ Status
constructor
A new instance of Status.
- #message ⇒ Object (also: #msg)
- #nok? ⇒ Boolean
- #ok? ⇒ Boolean
- #redirect? ⇒ Boolean
- #success? ⇒ Boolean
-
#to_i ⇒ Object
use alias_method :to_id, :code - why? why not?.
- #to_int ⇒ Object
Constructor Details
#initialize(code, message: nil) ⇒ Status
Returns a new instance of Status.
18 19 20 21 22 23 |
# File 'lib/webclient/webclient_response-status.rb', line 18 def initialize( code, message: nil ) ## note - upstream Net::HTTP::Response::code is a string e.g. "200"!!! ## convert to integer number @code = code.to_i(10) = end |
Instance Attribute Details
#code ⇒ Object (readonly)
fix-fix-fix maybe fold back into response.status | status_code response.status_message | status_msg keep it simple?
keep status.ok? => response.ok?
keep status.nok? => response.nok?
16 17 18 |
# File 'lib/webclient/webclient_response-status.rb', line 16 def code @code end |
Instance Method Details
#==(other) ⇒ Object
note - allow compare with integer e.g. response.status == 200
31 32 33 |
# File 'lib/webclient/webclient_response-status.rb', line 31 def ==(other) other.is_a?(Status) ? code == other.code : code == other.to_i end |
#error? ⇒ Boolean
41 |
# File 'lib/webclient/webclient_response-status.rb', line 41 def error?() code >= 400; end |
#message ⇒ Object Also known as: msg
44 |
# File 'lib/webclient/webclient_response-status.rb', line 44 def () ; end |
#nok? ⇒ Boolean
37 |
# File 'lib/webclient/webclient_response-status.rb', line 37 def nok?() code != 200; end |
#ok? ⇒ Boolean
36 |
# File 'lib/webclient/webclient_response-status.rb', line 36 def ok?() code == 200; end |
#redirect? ⇒ Boolean
40 |
# File 'lib/webclient/webclient_response-status.rb', line 40 def redirect?() (300..399).include?(code); end |
#success? ⇒ Boolean
39 |
# File 'lib/webclient/webclient_response-status.rb', line 39 def success?() (200..299).include?(code); end |
#to_i ⇒ Object
use alias_method :to_id, :code - why? why not?
26 |
# File 'lib/webclient/webclient_response-status.rb', line 26 def to_i() @code; end |
#to_int ⇒ Object
27 |
# File 'lib/webclient/webclient_response-status.rb', line 27 def to_int() @code; end |