Class: Wrappi::CachedResponse
- Inherits:
-
Object
- Object
- Wrappi::CachedResponse
- Defined in:
- lib/wrappi/cached_response.rb
Instance Method Summary collapse
- #body ⇒ Object
- #call ⇒ Object
- #called? ⇒ Boolean
- #error? ⇒ Boolean
-
#initialize(cached_data) ⇒ CachedResponse
constructor
input is a <Response>.to_h Example input { raw_body: ‘“bar”’, code: 200, uri: “hello.com”, success: true }.
- #raw_body ⇒ Object
- #status ⇒ Object (also: #status_code)
- #success? ⇒ Boolean
- #uri ⇒ Object
Constructor Details
#initialize(cached_data) ⇒ CachedResponse
input is a <Response>.to_h Example input
raw_body: '{"foo": "bar"',
code: 200,
uri: "http://hello.com",
success: true
}
11 12 13 |
# File 'lib/wrappi/cached_response.rb', line 11 def initialize(cached_data) @cached_data = Fusu::HashWithIndifferentAccess.new(cached_data) end |
Instance Method Details
#body ⇒ Object
23 24 25 |
# File 'lib/wrappi/cached_response.rb', line 23 def body @body ||= JSON.parse(cached_data[:raw_body]) end |
#call ⇒ Object
15 16 17 |
# File 'lib/wrappi/cached_response.rb', line 15 def call self end |
#called? ⇒ Boolean
19 20 21 |
# File 'lib/wrappi/cached_response.rb', line 19 def called? false end |
#error? ⇒ Boolean
31 32 33 |
# File 'lib/wrappi/cached_response.rb', line 31 def error? !success? end |
#raw_body ⇒ Object
35 36 37 |
# File 'lib/wrappi/cached_response.rb', line 35 def raw_body cached_data[:raw_body] end |
#status ⇒ Object Also known as: status_code
43 44 45 |
# File 'lib/wrappi/cached_response.rb', line 43 def status cached_data[:code] end |
#success? ⇒ Boolean
27 28 29 |
# File 'lib/wrappi/cached_response.rb', line 27 def success? cached_data[:success] end |
#uri ⇒ Object
39 40 41 |
# File 'lib/wrappi/cached_response.rb', line 39 def uri cached_data[:uri] end |