storyblok 1.0.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/storyblok.rb +1 -1
- data/lib/storyblok/cache/redis.rb +51 -0
- data/lib/storyblok/client.rb +11 -7
- data/lib/storyblok/version.rb +1 -1
- data/storyblok-1.0.4.gem +0 -0
- metadata +5 -6
- data/lib/storyblok/cache.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9876a3898f429335e6252d7d52962dbf2ff6af96
|
4
|
+
data.tar.gz: 1795aeb2880895aa2f05d244513af07ad41f16bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2191647a2248d3e851dbc9157a521b2223a9ba5d40123e4682f5d90b7b93c9e1a7057b81ebf8d28afc16534f6faa10f1221005fb7db6b818817d919f577d70b4
|
7
|
+
data.tar.gz: e4a111074b5ae3019c1ff9df0a7de5f97cc2ec3d27ea105b1a7cef9a4fce8bc3b36518439511035e79e9f38904f13738bfcd7639542728e4da5618459fb82c29
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ gem 'storyblok'
|
|
12
12
|
### Load a Story
|
13
13
|
|
14
14
|
```ruby
|
15
|
-
client =
|
15
|
+
client = Storyblok::Client.new(token: 'YOUR_TOKEN')
|
16
16
|
|
17
17
|
# Optionally set a cache client
|
18
18
|
Storyblok::Cache.client = Redis.new(:url => 'redis://localhost:6379')
|
data/lib/storyblok.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Storyblok
|
2
|
+
module Cache
|
3
|
+
class Redis
|
4
|
+
DEFAULT_CONFIGURATION = {
|
5
|
+
ttl: 60 * 60 * 24
|
6
|
+
}
|
7
|
+
|
8
|
+
def initialize(*args)
|
9
|
+
options = args.extract_options!
|
10
|
+
|
11
|
+
@redis = options.delete(:redis) || begin
|
12
|
+
if defined?(::Redis)
|
13
|
+
::Redis.current
|
14
|
+
else
|
15
|
+
raise "Redis.current could not be found. Supply :redis option or make sure Redis.current is available."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
@options = DEFAULT_CONFIGURATION.merge(options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def cache(key, expire = nil)
|
23
|
+
if expire == 0
|
24
|
+
return yield(self)
|
25
|
+
end
|
26
|
+
|
27
|
+
expire ||= @options[:ttl]
|
28
|
+
|
29
|
+
if (value = get(key)).nil?
|
30
|
+
value = yield(self)
|
31
|
+
set(key, value, expire)
|
32
|
+
end
|
33
|
+
|
34
|
+
value
|
35
|
+
end
|
36
|
+
|
37
|
+
def get(key)
|
38
|
+
@redis.get(key)
|
39
|
+
end
|
40
|
+
|
41
|
+
def set(key, value, expire = false)
|
42
|
+
if expire
|
43
|
+
@redis.setex(key, expire, value)
|
44
|
+
else
|
45
|
+
@redis.set(key, value)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/storyblok/client.rb
CHANGED
@@ -15,7 +15,8 @@ module Storyblok
|
|
15
15
|
logger: false,
|
16
16
|
log_level: Logger::INFO,
|
17
17
|
version: 'draft',
|
18
|
-
cache_version: Time.now.to_i
|
18
|
+
cache_version: Time.now.to_i,
|
19
|
+
cache: nil,
|
19
20
|
}
|
20
21
|
|
21
22
|
attr_reader :configuration, :logger
|
@@ -92,14 +93,13 @@ module Storyblok
|
|
92
93
|
query = request_query(request.query)
|
93
94
|
query_string = build_nested_query(query)
|
94
95
|
|
95
|
-
if
|
96
|
+
if cache.nil?
|
96
97
|
result = run_request(endpoint, query_string)
|
97
98
|
else
|
98
|
-
version =
|
99
|
+
version = cache.get('storyblok:' + configuration[:token] + ':version') || '0'
|
99
100
|
cache_key = 'storyblok:' + configuration[:token] + ':v:' + version + ':' + request.url + ':' + Base64.encode64(query_string)
|
100
|
-
cache_time = 60 * 60 * 2
|
101
101
|
|
102
|
-
result =
|
102
|
+
result = cache.cache(cache_key) do
|
103
103
|
run_request(endpoint, query_string)
|
104
104
|
end
|
105
105
|
end
|
@@ -108,8 +108,8 @@ module Storyblok
|
|
108
108
|
end
|
109
109
|
|
110
110
|
def flush
|
111
|
-
|
112
|
-
|
111
|
+
unless cache.nil?
|
112
|
+
cache.set('storyblok:' + configuration[:token] + ':version', Time.now.to_i.to_s)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
@@ -139,6 +139,10 @@ module Storyblok
|
|
139
139
|
DEFAULT_CONFIGURATION.dup
|
140
140
|
end
|
141
141
|
|
142
|
+
def cache
|
143
|
+
configuration[:cache]
|
144
|
+
end
|
145
|
+
|
142
146
|
def setup_logger
|
143
147
|
@logger = configuration[:logger]
|
144
148
|
logger.level = configuration[:log_level] if logger
|
data/lib/storyblok/version.rb
CHANGED
data/storyblok-1.0.4.gem
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: storyblok
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Storyblok (Alexander Feiglstorfer)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -66,19 +66,18 @@ extra_rdoc_files: []
|
|
66
66
|
files:
|
67
67
|
- ".editorconfig"
|
68
68
|
- ".gitignore"
|
69
|
-
- ".ruby-version"
|
70
69
|
- Gemfile
|
71
|
-
- Gemfile.lock
|
72
70
|
- README.md
|
73
71
|
- examples/cache.rb
|
74
72
|
- examples/example_queries.rb
|
75
73
|
- examples/tree.rb
|
76
74
|
- lib/storyblok.rb
|
77
|
-
- lib/storyblok/cache.rb
|
75
|
+
- lib/storyblok/cache/redis.rb
|
78
76
|
- lib/storyblok/client.rb
|
79
77
|
- lib/storyblok/links.rb
|
80
78
|
- lib/storyblok/request.rb
|
81
79
|
- lib/storyblok/version.rb
|
80
|
+
- storyblok-1.0.4.gem
|
82
81
|
- storyblok.gemspec
|
83
82
|
homepage: https://github.com/storyblok/storyblok-ruby
|
84
83
|
licenses:
|
@@ -100,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
99
|
version: '0'
|
101
100
|
requirements: []
|
102
101
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.5.
|
102
|
+
rubygems_version: 2.5.2.3
|
104
103
|
signing_key:
|
105
104
|
specification_version: 4
|
106
105
|
summary: storyblok
|
data/lib/storyblok/cache.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module Storyblok
|
2
|
-
class Cache
|
3
|
-
def self.client=(client)
|
4
|
-
@client = client
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.client
|
8
|
-
@client
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.cache(key, expire = nil)
|
12
|
-
if expire == 0
|
13
|
-
return yield(self)
|
14
|
-
end
|
15
|
-
|
16
|
-
if (value = @client.get(key)).nil?
|
17
|
-
value = yield(self)
|
18
|
-
@client.set(key, value)
|
19
|
-
@client.expire(key, expire) if expire
|
20
|
-
value
|
21
|
-
else
|
22
|
-
value
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|