Class: Resterl::Response
- Inherits:
-
Object
- Object
- Resterl::Response
- Defined in:
- lib/resterl/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#net_http_response ⇒ Object
readonly
Returns the value of attribute net_http_response.
Instance Method Summary collapse
- #expired? ⇒ Boolean
- #expires_in ⇒ Object
-
#header(h) ⇒ Object
rubocop:enable Style/TrivialAccessors.
-
#initialize(r, minimum_cache_lifetime) ⇒ Response
constructor
A new instance of Response.
-
#update_expires_at(t) ⇒ Object
rubocop:disable Style/TrivialAccessors.
Constructor Details
#initialize(r, minimum_cache_lifetime) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 |
# File 'lib/resterl/response.rb', line 5 def initialize(r, minimum_cache_lifetime) @net_http_response = r @body = r.body @expires_at = Time.now + [extract_max_age, minimum_cache_lifetime].max end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/resterl/response.rb', line 3 def body @body end |
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at.
3 4 5 |
# File 'lib/resterl/response.rb', line 3 def expires_at @expires_at end |
#net_http_response ⇒ Object (readonly)
Returns the value of attribute net_http_response.
3 4 5 |
# File 'lib/resterl/response.rb', line 3 def net_http_response @net_http_response end |
Instance Method Details
#expired? ⇒ Boolean
11 12 13 |
# File 'lib/resterl/response.rb', line 11 def expired? @expires_at < Time.now end |
#expires_in ⇒ Object
25 26 27 |
# File 'lib/resterl/response.rb', line 25 def expires_in extract_max_age end |
#header(h) ⇒ Object
rubocop:enable Style/TrivialAccessors
21 22 23 |
# File 'lib/resterl/response.rb', line 21 def header h @net_http_response[h] end |
#update_expires_at(t) ⇒ Object
rubocop:disable Style/TrivialAccessors
16 17 18 |
# File 'lib/resterl/response.rb', line 16 def update_expires_at t @expires_at = t end |