Class: UDPRest::UHTTPResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/udp_rest/uhttp.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
    self.code = code.to_i
    self.protocol = options[:protocol] || 'UHTTP/1.0'
    self.text = options[:text] || ''
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



63
64
65
# File 'lib/udp_rest/uhttp.rb', line 63

def code
  @code
end

#protocolObject

Returns the value of attribute protocol.



64
65
66
# File 'lib/udp_rest/uhttp.rb', line 64

def protocol
  @protocol
end

#textObject

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

Returns:

  • (Boolean)


80
81
82
# File 'lib/udp_rest/uhttp.rb', line 80

def ok?
    code == 200
end

#status_lineObject



89
90
91
# File 'lib/udp_rest/uhttp.rb', line 89

def status_line
    "#{protocol} #{code} #{status_text}"
end

#status_textObject



84
85
86
87
# File 'lib/udp_rest/uhttp.rb', line 84

def status_text
    return 'OK' if ok?
    return 'FAILED'
end

#to_sObject



93
94
95
# File 'lib/udp_rest/uhttp.rb', line 93

def to_s
    "#{status_line}\n\n#{text}"
end