Class: CloudKit::Response

Inherits:
Object show all
Includes:
Util
Defined in:
lib/cloudkit/store/response.rb

Overview

A response wrapper for CloudKit::Store

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#erb, #r, #unquote

Constructor Details

#initialize(status, meta, content = '') ⇒ Response

Create an instance of a Response.



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

def initialize(status, meta, content='')
  @status = status; @meta = meta; @content = content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'lib/cloudkit/store/response.rb', line 7

def content
  @content
end

#metaObject (readonly)

Returns the value of attribute meta.



7
8
9
# File 'lib/cloudkit/store/response.rb', line 7

def meta
  @meta
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/cloudkit/store/response.rb', line 7

def status
  @status
end

Instance Method Details

#[](key) ⇒ Object

Return the header value specified by key.



15
16
17
# File 'lib/cloudkit/store/response.rb', line 15

def [](key)
  meta[key]
end

#[]=(key, value) ⇒ Object

Set the header specified by key to value.



20
21
22
# File 'lib/cloudkit/store/response.rb', line 20

def []=(key, value)
  meta[key] = value
end

#clear_contentObject

Clear only the content of the response. Useful for HEAD requests.



36
37
38
# File 'lib/cloudkit/store/response.rb', line 36

def clear_content
  @content = ''
end

#etagObject

Return the ETag for this response without the surrounding quotes.



48
49
50
# File 'lib/cloudkit/store/response.rb', line 48

def etag
  unquote(meta['ETag'])
end

#headObject

Return a response suitable for HEAD requests.



41
42
43
44
45
# File 'lib/cloudkit/store/response.rb', line 41

def head
  response = self.dup
  response.clear_content
  response
end

#parsed_contentObject

Parse and return the JSON content



31
32
33
# File 'lib/cloudkit/store/response.rb', line 31

def parsed_content
  JSON.parse(content)
end

#to_rackObject

Translate to the standard Rack representation: [status, headers, content]



25
26
27
28
# File 'lib/cloudkit/store/response.rb', line 25

def to_rack
  meta['Content-Length'] = content.length.to_s
  [status, meta, [content.to_s]]
end