storyblok 2.0.0 → 2.0.1
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 +5 -5
- data/.ruby-version +1 -0
- data/Gemfile.lock +51 -0
- data/README.md +61 -3
- data/examples/management_api.rb +33 -0
- data/lib/storyblok/client.rb +71 -5
- data/lib/storyblok/request.rb +1 -1
- data/lib/storyblok/version.rb +1 -1
- data/storyblok.gemspec +1 -1
- metadata +8 -5
- data/storyblok-1.0.4.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ba3b3cbf9eb1bf234d0d093ad0d8e608b60408a1c62d650ab26d292114a45588
|
4
|
+
data.tar.gz: fd55258a2032f6aa3befad526afb5bd3191f6eb9a2c8bbe5220098f484224a12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 489b55d03fa510f6aecbd1da080e173f707e34bc45168a0d14644efc77ba798090e5667a820b85999a65f97c94f46828c43f9dcb9cc1984ed0054aaf573555f5
|
7
|
+
data.tar.gz: d96a28a42e2e0cf7517fbfa44d37db9138c1e9939aa37539d04932dd562545ebdf5e00bdbb3d1c964a0517e57bcfe21dfd173b6be22799ef19b9be8ac52e99f2
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.1
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
storyblok (2.0.1)
|
5
|
+
rest-client (>= 1.8.0, < 3)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.3)
|
11
|
+
domain_name (0.5.20180417)
|
12
|
+
unf (>= 0.0.5, < 1.0.0)
|
13
|
+
http-cookie (1.0.3)
|
14
|
+
domain_name (~> 0.5)
|
15
|
+
mime-types (3.2.2)
|
16
|
+
mime-types-data (~> 3.2015)
|
17
|
+
mime-types-data (3.2018.0812)
|
18
|
+
netrc (0.11.0)
|
19
|
+
redis (4.1.0)
|
20
|
+
rest-client (2.0.2)
|
21
|
+
http-cookie (>= 1.0.2, < 2.0)
|
22
|
+
mime-types (>= 1.16, < 4.0)
|
23
|
+
netrc (~> 0.8)
|
24
|
+
rspec (3.8.0)
|
25
|
+
rspec-core (~> 3.8.0)
|
26
|
+
rspec-expectations (~> 3.8.0)
|
27
|
+
rspec-mocks (~> 3.8.0)
|
28
|
+
rspec-core (3.8.0)
|
29
|
+
rspec-support (~> 3.8.0)
|
30
|
+
rspec-expectations (3.8.2)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.8.0)
|
33
|
+
rspec-mocks (3.8.0)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.8.0)
|
36
|
+
rspec-support (3.8.0)
|
37
|
+
unf (0.1.4)
|
38
|
+
unf_ext
|
39
|
+
unf_ext (0.0.7.5)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
bundler (~> 1.5)
|
46
|
+
redis
|
47
|
+
rspec (~> 3)
|
48
|
+
storyblok!
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
1.16.6
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# About
|
2
|
-
This is the Storyblok ruby client for easy access of the content delivery api.
|
2
|
+
This is the Storyblok ruby client for easy access of the management and content delivery api.
|
3
3
|
|
4
4
|
## Install
|
5
5
|
|
@@ -7,15 +7,28 @@ This is the Storyblok ruby client for easy access of the content delivery api.
|
|
7
7
|
gem 'storyblok'
|
8
8
|
```
|
9
9
|
|
10
|
-
## Usage
|
10
|
+
## Usage for the content delivery api
|
11
|
+
|
12
|
+
By default the client loads the "draft" version of the Story. Be sure to set the version to "published" to get the published content only.
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
# The draft mode is required for the preview
|
16
|
+
Storyblok::Client.new(version: 'draft')
|
17
|
+
|
18
|
+
# Requests only published stories
|
19
|
+
Storyblok::Client.new(version: 'published')
|
20
|
+
```
|
11
21
|
|
12
22
|
### Load a Story
|
13
23
|
|
14
24
|
```ruby
|
25
|
+
# Without cache
|
15
26
|
client = Storyblok::Client.new(token: 'YOUR_TOKEN')
|
16
27
|
|
17
28
|
# Optionally set a cache client
|
18
|
-
|
29
|
+
redis = Redis.new(url: 'redis://localhost:6379')
|
30
|
+
cache = Storyblok::Cache::Redis.new(redis: Redis.current)
|
31
|
+
client = Storyblok::Client.new(cache: cache, token: 'YOUR_TOKEN')
|
19
32
|
|
20
33
|
# Get a story
|
21
34
|
client.story('home')
|
@@ -72,6 +85,51 @@ end
|
|
72
85
|
puts '</ul>'
|
73
86
|
```
|
74
87
|
|
88
|
+
## How to flush the cache
|
89
|
+
|
90
|
+
Following an example of how to flush the client cache:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
cache = Storyblok::Cache::Redis.new(redis: Redis.current)
|
94
|
+
client = Storyblok::Client.new(cache: cache, token: 'YOUR_TOKEN')
|
95
|
+
|
96
|
+
# Get a story and cache it
|
97
|
+
client.story('home')
|
98
|
+
|
99
|
+
# Flush the cache
|
100
|
+
client.flush
|
101
|
+
```
|
102
|
+
|
103
|
+
## Usage for the management api
|
104
|
+
|
105
|
+
### Initialize the client and load spaces
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
client = Storyblok::Client.new(oauth_token: 'YOUR_OAUTH_TOKEN')
|
109
|
+
|
110
|
+
# Get your spaces
|
111
|
+
client.get('spaces')
|
112
|
+
```
|
113
|
+
|
114
|
+
### Create a story
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
client.post("spaces/{space_id}/stories", {story: {name: 'new', slug: "new"}})
|
118
|
+
```
|
119
|
+
|
120
|
+
### Update a story
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
client.put("spaces/{space_id}/stories/{story_id}", {story: {name: 'new', slug: "new"}})
|
124
|
+
```
|
125
|
+
|
126
|
+
### Delete a story
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
client.delete("spaces/{space_id}/stories/{story_id}")
|
130
|
+
```
|
131
|
+
|
132
|
+
|
75
133
|
### License
|
76
134
|
|
77
135
|
This project is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# bundle exec ruby examples/management_api.rb
|
2
|
+
|
3
|
+
require 'storyblok'
|
4
|
+
|
5
|
+
logger = Logger.new(STDOUT)
|
6
|
+
|
7
|
+
client = Storyblok::Client.new(
|
8
|
+
token: 'A5uTnm0GXLBLhwaGrhHdQwtt',
|
9
|
+
oauth_token: 'OAUTH_TOKEN',
|
10
|
+
logger: logger
|
11
|
+
)
|
12
|
+
|
13
|
+
spaces = client.get('spaces')['data']['spaces']
|
14
|
+
space = spaces.first
|
15
|
+
|
16
|
+
p client.get("spaces/#{space['id']}")['data']['space']
|
17
|
+
story_res = client.post("spaces/#{space['id']}/stories", {story: {name: 'new', slug: "new"}})['data']
|
18
|
+
|
19
|
+
10.times do |index|
|
20
|
+
client.get("spaces/#{space['id']}/stories/#{story_res['story']['id']}")
|
21
|
+
puts index
|
22
|
+
end
|
23
|
+
|
24
|
+
p client.put("spaces/#{space['id']}/stories/#{story_res['story']['id']}", {story: {name: 'new123'}})['data']
|
25
|
+
|
26
|
+
10.times do |index|
|
27
|
+
client.story('new')
|
28
|
+
puts index
|
29
|
+
end
|
30
|
+
|
31
|
+
p client.delete("spaces/#{space['id']}/stories/#{story_res['story']['id']}")
|
32
|
+
|
33
|
+
|
data/lib/storyblok/client.rb
CHANGED
@@ -22,7 +22,8 @@ module Storyblok
|
|
22
22
|
attr_reader :configuration, :logger
|
23
23
|
|
24
24
|
# @param [Hash] given_configuration
|
25
|
-
# @option given_configuration [String] :token Required
|
25
|
+
# @option given_configuration [String] :token Required if oauth_token is not set
|
26
|
+
# @option given_configuration [String] :oauth_token Required if token is not set
|
26
27
|
# @option given_configuration [String] :api_url
|
27
28
|
# @option given_configuration [Number] :api_version
|
28
29
|
# @option given_configuration [false, ::Logger] :logger
|
@@ -30,6 +31,13 @@ module Storyblok
|
|
30
31
|
def initialize(given_configuration = {})
|
31
32
|
@configuration = default_configuration.merge(given_configuration)
|
32
33
|
validate_configuration!
|
34
|
+
|
35
|
+
if configuration[:oauth_token]
|
36
|
+
@rest_client = RestClient::Resource.new(base_url, :headers => {
|
37
|
+
:authorization => configuration[:oauth_token]
|
38
|
+
})
|
39
|
+
end
|
40
|
+
|
33
41
|
setup_logger
|
34
42
|
end
|
35
43
|
|
@@ -88,7 +96,47 @@ module Storyblok
|
|
88
96
|
Links.new(Request.new(self, '/cdn/links', query).get).as_tree
|
89
97
|
end
|
90
98
|
|
91
|
-
def
|
99
|
+
def post(path, payload, additional_headers = {})
|
100
|
+
run_management_request(:post, path, payload, additional_headers)
|
101
|
+
end
|
102
|
+
|
103
|
+
def put(path, payload, additional_headers = {})
|
104
|
+
run_management_request(:put, path, payload, additional_headers)
|
105
|
+
end
|
106
|
+
|
107
|
+
def delete(path, additional_headers = {})
|
108
|
+
run_management_request(:delete, path, nil, additional_headers)
|
109
|
+
end
|
110
|
+
|
111
|
+
def get(path, additional_headers = {})
|
112
|
+
run_management_request(:get, path, nil, additional_headers)
|
113
|
+
end
|
114
|
+
|
115
|
+
def run_management_request(action, path, payload = {}, additional_headers = {})
|
116
|
+
logger.info(request: { path: path, action: action }) if logger
|
117
|
+
retries_left = 3
|
118
|
+
|
119
|
+
begin
|
120
|
+
if [:post, :put].include?(action)
|
121
|
+
res = @rest_client[path].send(action, payload, additional_headers)
|
122
|
+
else
|
123
|
+
res = @rest_client[path].send(action, additional_headers)
|
124
|
+
end
|
125
|
+
rescue RestClient::TooManyRequests
|
126
|
+
if retries_left != 0
|
127
|
+
retries_left -= 1
|
128
|
+
logger.info("Too many requests. Retry nr. #{(3 - retries_left).to_s} of max. 3 times.") if logger
|
129
|
+
sleep(0.5)
|
130
|
+
retry
|
131
|
+
end
|
132
|
+
|
133
|
+
raise
|
134
|
+
end
|
135
|
+
|
136
|
+
parse_result(res)
|
137
|
+
end
|
138
|
+
|
139
|
+
def cached_get(request)
|
92
140
|
endpoint = base_url + request.url
|
93
141
|
query = request_query(request.query)
|
94
142
|
query_string = build_nested_query(query)
|
@@ -115,11 +163,29 @@ module Storyblok
|
|
115
163
|
|
116
164
|
private
|
117
165
|
|
166
|
+
def parse_result(res)
|
167
|
+
{'headers' => res.headers, 'data' => JSON.parse(res.body)}
|
168
|
+
end
|
169
|
+
|
118
170
|
def run_request(endpoint, query_string)
|
119
171
|
logger.info(request: { endpoint: endpoint, query: query_string }) if logger
|
120
|
-
res = RestClient.get "#{endpoint}?#{query_string}"
|
121
172
|
|
122
|
-
|
173
|
+
retries_left = 3
|
174
|
+
|
175
|
+
begin
|
176
|
+
res = RestClient.get "#{endpoint}?#{query_string}"
|
177
|
+
rescue RestClient::TooManyRequests
|
178
|
+
if retries_left != 0
|
179
|
+
retries_left -= 1
|
180
|
+
logger.info("Too many requests. Retry nr. #{(3 - retries_left).to_s} of max. 3 times.") if logger
|
181
|
+
sleep(0.5)
|
182
|
+
retry
|
183
|
+
end
|
184
|
+
|
185
|
+
raise
|
186
|
+
end
|
187
|
+
|
188
|
+
{'headers' => res.headers, 'data' => JSON.parse(res.body)}.to_json
|
123
189
|
end
|
124
190
|
|
125
191
|
# Patches a query hash with the client configurations for queries
|
@@ -149,7 +215,7 @@ module Storyblok
|
|
149
215
|
end
|
150
216
|
|
151
217
|
def validate_configuration!
|
152
|
-
fail ArgumentError, 'You will need to initialize a client with an :token' if configuration[:token]
|
218
|
+
fail ArgumentError, 'You will need to initialize a client with an :token or :oauth_token' if !configuration[:token] and !configuration[:oauth_token]
|
153
219
|
fail ArgumentError, 'The client configuration needs to contain an :api_url' if configuration[:api_url].empty?
|
154
220
|
fail ArgumentError, 'The :api_version must be a positive number' unless configuration[:api_version].to_i >= 0
|
155
221
|
end
|
data/lib/storyblok/request.rb
CHANGED
data/lib/storyblok/version.rb
CHANGED
data/storyblok.gemspec
CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |gem|
|
|
4
4
|
gem.name = 'storyblok'
|
5
5
|
gem.version = Storyblok::VERSION
|
6
6
|
gem.summary = 'storyblok'
|
7
|
-
gem.description = 'Ruby client for the https://www.storyblok.com
|
7
|
+
gem.description = 'Ruby client for the https://www.storyblok.com management and content delivery API'
|
8
8
|
gem.license = 'MIT'
|
9
9
|
gem.authors = ['Storyblok (Alexander Feiglstorfer)']
|
10
10
|
gem.email = 'it@storyblok.com'
|
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: 2.0.
|
4
|
+
version: 2.0.1
|
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:
|
11
|
+
date: 2019-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -58,7 +58,8 @@ dependencies:
|
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '3'
|
61
|
-
description: Ruby client for the https://www.storyblok.com
|
61
|
+
description: Ruby client for the https://www.storyblok.com management and content
|
62
|
+
delivery API
|
62
63
|
email: it@storyblok.com
|
63
64
|
executables: []
|
64
65
|
extensions: []
|
@@ -66,10 +67,13 @@ extra_rdoc_files: []
|
|
66
67
|
files:
|
67
68
|
- ".editorconfig"
|
68
69
|
- ".gitignore"
|
70
|
+
- ".ruby-version"
|
69
71
|
- Gemfile
|
72
|
+
- Gemfile.lock
|
70
73
|
- README.md
|
71
74
|
- examples/cache.rb
|
72
75
|
- examples/example_queries.rb
|
76
|
+
- examples/management_api.rb
|
73
77
|
- examples/tree.rb
|
74
78
|
- lib/storyblok.rb
|
75
79
|
- lib/storyblok/cache/redis.rb
|
@@ -77,7 +81,6 @@ files:
|
|
77
81
|
- lib/storyblok/links.rb
|
78
82
|
- lib/storyblok/request.rb
|
79
83
|
- lib/storyblok/version.rb
|
80
|
-
- storyblok-1.0.4.gem
|
81
84
|
- storyblok.gemspec
|
82
85
|
homepage: https://github.com/storyblok/storyblok-ruby
|
83
86
|
licenses:
|
@@ -99,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
102
|
version: '0'
|
100
103
|
requirements: []
|
101
104
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.
|
105
|
+
rubygems_version: 2.7.6
|
103
106
|
signing_key:
|
104
107
|
specification_version: 4
|
105
108
|
summary: storyblok
|
data/storyblok-1.0.4.gem
DELETED
Binary file
|