Class: Web::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/web/response.rb

Overview

A class which represents data from a response

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, body, headers) ⇒ Response

Returns a new instance of Response.



19
20
21
22
23
# File 'lib/web/response.rb', line 19

def initialize(code, body, headers)
  @code = code
  @body = body
  @headers = headers || {}
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



8
9
10
# File 'lib/web/response.rb', line 8

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



8
9
10
# File 'lib/web/response.rb', line 8

def code
  @code
end

#headersObject (readonly)

Returns the value of attribute headers.



8
9
10
# File 'lib/web/response.rb', line 8

def headers
  @headers
end

Class Method Details

.load(data) ⇒ Object



14
15
16
17
# File 'lib/web/response.rb', line 14

def self.load(data)
  data = JSON::parse(data)
  self.new(data['code'], data['body'], data['headers'])
end

Instance Method Details

#dumpObject



10
11
12
# File 'lib/web/response.rb', line 10

def dump
  { :code => @code, :headers => @headers, :body => @body }.to_json
end