Class: FragmentClient

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

Constant Summary collapse

DEFAULT_URL =
'http://test-eva-fragment-server.herokuapp.com/fragments/full.json?'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fragment_server_url = DEFAULT_URL, cache = MemoryCache.new) ⇒ FragmentClient

Returns a new instance of FragmentClient.



8
9
10
11
# File 'lib/fragment_client.rb', line 8

def initialize(fragment_server_url=DEFAULT_URL, cache=MemoryCache.new)
  self.fragment_server_url = fragment_server_url
  self.cache               = cache
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



5
6
7
# File 'lib/fragment_client.rb', line 5

def cache
  @cache
end

#fragment_server_urlObject

Returns the value of attribute fragment_server_url.



5
6
7
# File 'lib/fragment_client.rb', line 5

def fragment_server_url
  @fragment_server_url
end

#option_paramsObject

Returns the value of attribute option_params.



5
6
7
# File 'lib/fragment_client.rb', line 5

def option_params
  @option_params
end

Instance Method Details

#fetch(section, options = {}) ⇒ Object



13
14
15
16
# File 'lib/fragment_client.rb', line 13

def fetch(section, options={})
  set_params(options)
  cache.fetch(section + option_params, expires_in: ENV["FRAGMENT_CLIENT_CACHE_TIME"] || 1.hour) { request[section] }
end