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(app_name, fragment_server_url = DEFAULT_URL, cache = MemoryCache.new, logger = default_logger) ⇒ FragmentClient

Returns a new instance of FragmentClient.



10
11
12
13
14
15
# File 'lib/fragment_client.rb', line 10

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

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



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

def app_name
  @app_name
end

#cacheObject

Returns the value of attribute cache.



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

def cache
  @cache
end

#fragment_server_urlObject

Returns the value of attribute fragment_server_url.



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

def fragment_server_url
  @fragment_server_url
end

#loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

#option_paramsObject

Returns the value of attribute option_params.



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

def option_params
  @option_params
end

Instance Method Details

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



17
18
19
20
21
22
23
24
# File 'lib/fragment_client.rb', line 17

def fetch(section, options={})
  set_params(options)
  log(section)

  cache.fetch(section.to_s + option_params, expires_in: ENV["FRAGMENT_CLIENT_CACHE_TIME"].to_i || 1.hour) do
    request[section]
  end
end