Class: CloudKit::Response
- Includes:
- Util
- Defined in:
- lib/cloudkit/store/response.rb
Overview
A response wrapper for CloudKit::Store
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Return the header value specified by key.
-
#[]=(key, value) ⇒ Object
Set the header specified by key to value.
-
#clear_content ⇒ Object
Clear only the content of the response.
-
#etag ⇒ Object
Return the ETag for this response without the surrounding quotes.
-
#head ⇒ Object
Return a response suitable for HEAD requests.
-
#initialize(status, meta, content = '') ⇒ Response
constructor
Create an instance of a Response.
-
#parsed_content ⇒ Object
Parse and return the JSON content.
-
#to_rack ⇒ Object
Translate to the standard Rack representation: [status, headers, content].
Methods included from Util
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, , content='') @status = status; @meta = ; @content = content end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
7 8 9 |
# File 'lib/cloudkit/store/response.rb', line 7 def content @content end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
7 8 9 |
# File 'lib/cloudkit/store/response.rb', line 7 def @meta end |
#status ⇒ Object (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) [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) [key] = value end |
#clear_content ⇒ Object
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 |
#etag ⇒ Object
Return the ETag for this response without the surrounding quotes.
48 49 50 |
# File 'lib/cloudkit/store/response.rb', line 48 def etag unquote(['ETag']) end |
#head ⇒ Object
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_content ⇒ Object
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_rack ⇒ Object
Translate to the standard Rack representation: [status, headers, content]
25 26 27 28 |
# File 'lib/cloudkit/store/response.rb', line 25 def to_rack ['Content-Length'] = content.length.to_s [status, , [content.to_s]] end |