storyblok 1.0.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddf62135995f7382d7859652b2d02b1b0a147a41
4
- data.tar.gz: 7e3f2229f06904fe05410352ddfa9fbeb74671a1
3
+ metadata.gz: 9876a3898f429335e6252d7d52962dbf2ff6af96
4
+ data.tar.gz: 1795aeb2880895aa2f05d244513af07ad41f16bf
5
5
  SHA512:
6
- metadata.gz: db9fabb6d63a3dfea95e7ddc1a468b9f05a57d233b6ea1d19360005934df038c0803b4e41ec372de68632b249a89f73a24397a972cf6c96f7a2d5cf787711e17
7
- data.tar.gz: 1416e31040d1a7549a12ec212e282eadd8c8f15e018b8c0add2ae1e92509ae9fc2100f1ef0e38398d2614032d54463b759d54b66a3c613b1974ae0789b8ee333
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 = new Storyblok::Client(token: 'YOUR_TOKEN')
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
@@ -1,3 +1,3 @@
1
1
  require 'storyblok/version'
2
- require 'storyblok/cache'
2
+ require 'storyblok/cache/redis'
3
3
  require 'storyblok/client'
@@ -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
@@ -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 Cache.client.nil?
96
+ if cache.nil?
96
97
  result = run_request(endpoint, query_string)
97
98
  else
98
- version = Cache.client.get('storyblok:' + configuration[:token] + ':version') || '0'
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 = Cache.cache(cache_key, cache_time) do
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
- if !Cache.client.nil?
112
- Cache.client.set('storyblok:' + configuration[:token] + ':version', Time.now.to_i.to_s)
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
@@ -1,4 +1,4 @@
1
1
  module Storyblok
2
2
  # Gem Version
3
- VERSION = '1.0.4'
3
+ VERSION = '2.0.0'
4
4
  end
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: 1.0.4
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-02-07 00:00:00.000000000 Z
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.1
102
+ rubygems_version: 2.5.2.3
104
103
  signing_key:
105
104
  specification_version: 4
106
105
  summary: storyblok
@@ -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