Class: HttpResponseFormat

Inherits:
Format
  • Object
show all
Defined in:
lib/httpresponseformat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code = nil, reason = nil, headers = nil, body = nil) ⇒ HttpResponseFormat

Returns a new instance of HttpResponseFormat.



17
18
19
20
21
22
# File 'lib/httpresponseformat.rb', line 17

def initialize(code=nil, reason=nil, headers=nil, body=nil)
  @code = code
  @reason = reason
  @headers = headers
  @body = body
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



15
16
17
# File 'lib/httpresponseformat.rb', line 15

def body
  @body
end

#codeObject

Returns the value of attribute code.



12
13
14
# File 'lib/httpresponseformat.rb', line 12

def code
  @code
end

#headersObject

Returns the value of attribute headers.



14
15
16
# File 'lib/httpresponseformat.rb', line 14

def headers
  @headers
end

#reasonObject

Returns the value of attribute reason.



13
14
15
# File 'lib/httpresponseformat.rb', line 13

def reason
  @reason
end

Instance Method Details

#exportObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/httpresponseformat.rb', line 28

def export
  out = Hash.new
  if !@code.nil?
    out['code'] = @code
  end
  if !@reason.nil?
    out['reason'] = @reason
  end
  if !@headers.nil? and @headers.length > 0
    out['headers'] = @headers
  end
  if !@body.nil?
    if @body.encoding.name == 'ASCII-8BIT'
      out['body-bin'] = Base64.encode64(@body)
    else
      out['body'] = @body
    end
  end
  return out
end

#nameObject



24
25
26
# File 'lib/httpresponseformat.rb', line 24

def name
  return 'http-response'
end