fragment_client 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fragment_client.rb +18 -3
- data/lib/memory_cache.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1c1d458d625afad36e7931d2bda171aa6064d3d
|
4
|
+
data.tar.gz: 81c9be211e144ddb2a07d520de834a9bac7964d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64835b4471eeaf7c32871b8ee4ab40801114f7215fd2c707cc18fe54754c3a2e2c0e16da0f6b68627f884c5dab01264ee99df7d97f8cd4f14d2c6aa6f17a596c
|
7
|
+
data.tar.gz: 8cdb8051c830a46a872c19fef5ade1d72b22d00acfe1b63ec458cf2f5ee49c3c65331b9c5de253f4da0d09ccab90c52cc6228e5db3e29e977dbe597651e7d799
|
data/lib/fragment_client.rb
CHANGED
@@ -1,21 +1,36 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'memory_cache'
|
3
|
+
require 'net/http'
|
3
4
|
|
4
5
|
class FragmentClient
|
5
|
-
attr_accessor :fragment_server_url, :option_params, :cache
|
6
|
+
attr_accessor :fragment_server_url, :option_params, :cache, :logger
|
6
7
|
DEFAULT_URL = 'http://test-eva-fragment-server.herokuapp.com/fragments/full.json?'
|
7
8
|
|
8
|
-
def initialize(fragment_server_url=DEFAULT_URL, cache=MemoryCache.new)
|
9
|
+
def initialize(fragment_server_url=DEFAULT_URL, cache=MemoryCache.new, logger=default_logger)
|
9
10
|
self.fragment_server_url = fragment_server_url
|
10
11
|
self.cache = cache
|
12
|
+
self.logger = logger
|
11
13
|
end
|
12
14
|
|
13
15
|
def fetch(section, options={})
|
14
16
|
set_params(options)
|
15
|
-
|
17
|
+
log(section)
|
18
|
+
|
19
|
+
cache.fetch(section.to_s + option_params, expires_in: ENV["FRAGMENT_CLIENT_CACHE_TIME"].to_i || 1.hour) do
|
20
|
+
request[section]
|
21
|
+
end
|
16
22
|
end
|
17
23
|
|
18
24
|
private
|
25
|
+
def default_logger
|
26
|
+
Rails.try(:logger) || Logger.new(STDOUT)
|
27
|
+
end
|
28
|
+
|
29
|
+
def log(section)
|
30
|
+
cache_hit = cache.read(section).present? ? 'CacheHit' : 'CacheMiss'
|
31
|
+
logger.info "FragmentClient:{Cache:#{cache.class}, Section:#{section}, #{cache_hit}}"
|
32
|
+
logger.info "FragmentClient:{requesting:#{uri}}" if cache_hit == 'CacheMiss'
|
33
|
+
end
|
19
34
|
|
20
35
|
def set_params(options={})
|
21
36
|
self.option_params = URI.encode_www_form(default_options.merge(options).sort)
|
data/lib/memory_cache.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fragment_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Atkinson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-01-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails-timeago
|