Class CloudKit::Response

  1. lib/cloudkit/store/response.rb
Parent: Object

A response wrapper for CloudKit::Store

Methods

public class

  1. new

public instance

  1. []
  2. []=
  3. clear_content
  4. etag
  5. head
  6. parsed_content
  7. to_rack

Included modules

  1. Util

Attributes

content [R]
meta [R]
status [R]

Public class methods

new (status, meta, content='')

Create an instance of a Response.

[show source]
    # File lib/cloudkit/store/response.rb, line 10
10:     def initialize(status, meta, content='')
11:       @status = status; @meta = meta; @content = content
12:     end

Public instance methods

[] (key)

Return the header value specified by key.

[show source]
    # File lib/cloudkit/store/response.rb, line 15
15:     def [](key)
16:       meta[key]
17:     end
[]= (key, value)

Set the header specified by key to value.

[show source]
    # File lib/cloudkit/store/response.rb, line 20
20:     def []=(key, value)
21:       meta[key] = value
22:     end
clear_content ()

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

[show source]
    # File lib/cloudkit/store/response.rb, line 36
36:     def clear_content
37:       @content = ''
38:     end
etag ()

Return the ETag for this response without the surrounding quotes.

[show source]
    # File lib/cloudkit/store/response.rb, line 48
48:     def etag
49:       unquote(meta['ETag'])
50:     end
head ()

Return a response suitable for HEAD requests.

[show source]
    # File lib/cloudkit/store/response.rb, line 41
41:     def head
42:       response = self.dup
43:       response.clear_content
44:       response
45:     end
parsed_content ()

Parse and return the JSON content

[show source]
    # File lib/cloudkit/store/response.rb, line 31
31:     def parsed_content
32:       JSON.parse(content)
33:     end
to_rack ()

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

[show source]
    # File lib/cloudkit/store/response.rb, line 25
25:     def to_rack
26:       meta['Content-Length'] = content.length.to_s
27:       [status, meta, [content.to_s]]
28:     end