Class: Useless::Doc::Client::Standard

Inherits:
Object
  • Object
show all
Includes:
Useless::Doc::Client
Defined in:
lib/useless/doc/client.rb

Constant Summary collapse

NotModified =
304

Instance Method Summary collapse

Methods included from Useless::Doc::Client

standard, stub

Constructor Details

#initializeStandard

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.options 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