Class: Useless::Doc::Client::Standard
- Inherits:
-
Object
- Object
- Useless::Doc::Client::Standard
- Includes:
- Useless::Doc::Client
- Defined in:
- lib/useless/doc/client.rb
Constant Summary collapse
- NotModified =
304
Instance Method Summary collapse
- #get(url) ⇒ Object
-
#initialize ⇒ Standard
constructor
A new instance of Standard.
Methods included from Useless::Doc::Client
Constructor Details
#initialize ⇒ Standard
Returns a new instance of Standard.
27 28 29 |
# File 'lib/useless/doc/client.rb', line 27 def initialize @cache = {} end |
Instance Method Details
#get(url) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/useless/doc/client.rb', line 31 def get(url) headers = { 'Accept' => 'application/json' } if @cache[url] headers['If-Modified-Since'] = @cache[url][:timestamp].httpdate() end response = Typhoeus. url, headers: headers unless response.response_code == NotModified @cache[url] = { response_body: response.response_body, timestamp: Time.now } end Useless::Doc::Serialization::Load.load(@cache[url][:response_body]) end |