Class: Resterl::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/resterl/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/resterl/response.rb', line 3

def body
  @body
end

#expires_atObject (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_responseObject (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

Returns:

  • (Boolean)


11
12
13
# File 'lib/resterl/response.rb', line 11

def expired?
  @expires_at < Time.now
end

#expires_inObject



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