Class: UDPRest::UHTTPResponse
- Inherits:
-
Object
- Object
- UDPRest::UHTTPResponse
- Defined in:
- lib/udp_rest/uhttp.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#text ⇒ Object
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(code, options = {}) ⇒ UHTTPResponse
constructor
A new instance of UHTTPResponse.
- #ok? ⇒ Boolean
- #status_line ⇒ Object
- #status_text ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(code, options = {}) ⇒ UHTTPResponse
Returns a new instance of UHTTPResponse.
67 68 69 70 71 |
# File 'lib/udp_rest/uhttp.rb', line 67 def initialize(code, = {}) self.code = code.to_i self.protocol = [:protocol] || 'UHTTP/1.0' self.text = [:text] || '' end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
63 64 65 |
# File 'lib/udp_rest/uhttp.rb', line 63 def code @code end |
#protocol ⇒ Object
Returns the value of attribute protocol.
64 65 66 |
# File 'lib/udp_rest/uhttp.rb', line 64 def protocol @protocol end |
#text ⇒ Object
Returns the value of attribute text.
65 66 67 |
# File 'lib/udp_rest/uhttp.rb', line 65 def text @text end |
Class Method Details
.parse(s) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/udp_rest/uhttp.rb', line 73 def self.parse(s) data = s.split("\n\n") status = data[0].split(' ') text = data[1] if data.length > 1 self.new(status[1], :text => text || '') end |
Instance Method Details
#ok? ⇒ Boolean
80 81 82 |
# File 'lib/udp_rest/uhttp.rb', line 80 def ok? code == 200 end |
#status_line ⇒ Object
89 90 91 |
# File 'lib/udp_rest/uhttp.rb', line 89 def status_line "#{protocol} #{code} #{status_text}" end |
#status_text ⇒ Object
84 85 86 87 |
# File 'lib/udp_rest/uhttp.rb', line 84 def status_text return 'OK' if ok? return 'FAILED' end |
#to_s ⇒ Object
93 94 95 |
# File 'lib/udp_rest/uhttp.rb', line 93 def to_s "#{status_line}\n\n#{text}" end |