contentful_bootstrap 2.0.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -1
- data/examples/templates/catalogue.json +87 -62
- data/lib/contentful/bootstrap/commands/create_space.rb +1 -1
- data/lib/contentful/bootstrap/generator.rb +9 -9
- data/lib/contentful/bootstrap/templates/base.rb +42 -24
- data/lib/contentful/bootstrap/templates/blog.rb +2 -0
- data/lib/contentful/bootstrap/templates/json_template.rb +24 -11
- data/lib/contentful/bootstrap/templates/links/base.rb +5 -0
- data/lib/contentful/bootstrap/token.rb +3 -3
- data/lib/contentful/bootstrap/version.rb +5 -1
- data/spec/contentful/bootstrap/commands/create_space_spec.rb +56 -4
- data/spec/contentful/bootstrap/commands/generate_token_spec.rb +14 -0
- data/spec/contentful/bootstrap/templates/json_template_spec.rb +39 -1
- data/spec/contentful/bootstrap/templates/links/asset_spec.rb +14 -0
- data/spec/contentful/bootstrap/templates/links/base_spec.rb +15 -1
- data/spec/contentful/bootstrap/templates/links/entry_spec.rb +14 -0
- data/spec/fixtures/json_fixtures/high.json +6 -0
- data/spec/fixtures/json_fixtures/invalid.json +5 -0
- data/spec/fixtures/json_fixtures/issue_22.json +20 -15
- data/spec/fixtures/json_fixtures/links.json +18 -0
- data/spec/fixtures/json_fixtures/low.json +6 -0
- data/spec/fixtures/json_fixtures/no_ids.json +25 -0
- data/spec/fixtures/json_fixtures/ok_version.json +6 -0
- data/spec/fixtures/json_fixtures/simple.json +8 -3
- data/spec/fixtures/json_fixtures/wl1z0pal05vy.json +209 -172
- data/spec/fixtures/vcr_fixtures/create_space.yml +202 -0
- data/spec/fixtures/vcr_fixtures/create_space_with_blog_template.yml +4337 -0
- data/spec/fixtures/vcr_fixtures/create_space_with_catalogue_template.yml +9987 -0
- data/spec/fixtures/vcr_fixtures/create_space_with_gallery_template.yml +5609 -0
- data/spec/fixtures/vcr_fixtures/generate_json.yml +177 -177
- data/spec/fixtures/vcr_fixtures/generate_token.yml +394 -0
- data/spec/fixtures/vcr_fixtures/issue_22.yml +914 -307
- data/spec/fixtures/vcr_fixtures/no_ids.yml +1314 -0
- metadata +27 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c952447ab1885c58f1e64320aba4ebf2b1697cc4
|
4
|
+
data.tar.gz: 98ecff172ff775441525ba47fa0ecab3de8a4323
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7111f2b133ab7359ddec7246cb054f5c9bbbc4b708e18ec8d6d4327765fa3b0dde5812db2a083da0001467c015a84cf153e66c240354440d861e65a3bf071ec
|
7
|
+
data.tar.gz: df0a573b361e23c174b674584cfd64af0b7d7408347a8b6369777588aabcfa443cd0ac65a8e55092ff54e4201b75d219cfd0711e2c91ee4a617565da7131374a
|
data/.travis.yml
CHANGED
@@ -4,3 +4,6 @@ rvm:
|
|
4
4
|
- 2.1.7
|
5
5
|
- 2.2.3
|
6
6
|
- 2.0.0
|
7
|
+
notifications:
|
8
|
+
slack:
|
9
|
+
secure: Pw7UFAHD2fSAUtjf0P/W0Wg91TVTMAV8Gl04B/XhFrYpjVtifsGxWipOBDvJr9S7ep2UFbR3YbBABRWAJAigoDHvwEaf6eytEFT9LGsMwmPQOtb5NlJt0+Qhvys3sZUM0KskBORQ+Etz1M0O4e9baC5Tz1V8GzI/lNxIbpIM7dwQU18st+9sUTjBh6UFJDRXd0Qm28VAHk7fjlhpdKVH+5F4iEnFfRw414wVja8kPVmVDHCEqHPWS1JyHIj4eU8E50yBi3WjC60eE2TjAsCA9wc9gzvxb4tN5vXyuIVtqopPW4JPIBCaIv+j07biNAiLrTccQ5vv9RD9NTPmXANX9LyF/qD9I+itFl8xLatnwy1JXtPpi/S+OlQj6lluF17F+3c8g64vVgTYXyCDgCqpzSTj/KsTfwC9PkVGh8bmZMLtfUyd4IiMw8qiXt2opEmv90K1aodcixrpL2Db/OS2aSo4djRfMrjMlUN7tGM7hg9yQfAaZQKCPjof4C/XGG9me9FX+BvnNf9Xl6/t6uHFnkBfF969UX7gk7tzkwyyqpOp/FQ+6c+EiZF7wnVotbW49FBgEmZN62JsXSquDBlDfWrALeX4y9dZ+uYrWBd4q47N+kZUtogwf3f3gj0pE+K1XmKV549HkiHZ9MHcFtOwNu7KrCFMmUSPGIUKSotbg/c=
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## v3.0.0
|
6
|
+
### Changed
|
7
|
+
* Change JSON Template format to resemble the API more closely
|
8
|
+
* Create Entries on 2 Steps [#27](https://github.com/contentful-labs/contentful-bootstrap.rb/pull/27)
|
9
|
+
* Add JSON Template Version Check [#31](https://github.com/contentful-labs/contentful-bootstrap.rb/issues/31)
|
10
|
+
|
5
11
|
## v2.0.2
|
6
12
|
### Fixed
|
7
13
|
* Array and Link handling
|
data/Gemfile
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
{
|
2
|
+
"version": 3,
|
2
3
|
"content_types": [
|
3
4
|
{
|
4
5
|
"id": "brand",
|
5
6
|
"name": "Brand",
|
6
|
-
"
|
7
|
+
"displayField": "name",
|
7
8
|
"fields": [
|
8
9
|
{
|
9
10
|
"id": "name",
|
@@ -19,14 +20,14 @@
|
|
19
20
|
"id": "logo",
|
20
21
|
"name": "Logo",
|
21
22
|
"type": "Link",
|
22
|
-
"
|
23
|
+
"linkType": "Asset"
|
23
24
|
}
|
24
25
|
]
|
25
26
|
},
|
26
27
|
{
|
27
28
|
"id": "category",
|
28
29
|
"name": "Category",
|
29
|
-
"
|
30
|
+
"displayField": "title",
|
30
31
|
"fields": [
|
31
32
|
{
|
32
33
|
"id": "title",
|
@@ -42,14 +43,14 @@
|
|
42
43
|
"id": "icon",
|
43
44
|
"name": "Icon",
|
44
45
|
"type": "Link",
|
45
|
-
"
|
46
|
+
"linkType": "Asset"
|
46
47
|
}
|
47
48
|
]
|
48
49
|
},
|
49
50
|
{
|
50
51
|
"id": "product",
|
51
52
|
"name": "Product",
|
52
|
-
"
|
53
|
+
"displayField": "name",
|
53
54
|
"fields": [
|
54
55
|
{
|
55
56
|
"id": "name",
|
@@ -65,19 +66,19 @@
|
|
65
66
|
"id": "image",
|
66
67
|
"name": "Image",
|
67
68
|
"type": "Link",
|
68
|
-
"
|
69
|
+
"linkType": "Asset"
|
69
70
|
},
|
70
71
|
{
|
71
72
|
"id": "brand",
|
72
73
|
"name": "Brand",
|
73
74
|
"type": "Link",
|
74
|
-
"
|
75
|
+
"linkType": "Entry"
|
75
76
|
},
|
76
77
|
{
|
77
78
|
"id": "category",
|
78
79
|
"name": "Category",
|
79
80
|
"type": "Link",
|
80
|
-
"
|
81
|
+
"linkType": "Entry"
|
81
82
|
},
|
82
83
|
{
|
83
84
|
"id": "url",
|
@@ -140,80 +141,104 @@
|
|
140
141
|
"entries": {
|
141
142
|
"brand": [
|
142
143
|
{
|
143
|
-
"
|
144
|
-
|
145
|
-
|
146
|
-
"
|
147
|
-
"
|
148
|
-
"
|
144
|
+
"sys": {
|
145
|
+
"id": "playsam"
|
146
|
+
},
|
147
|
+
"fields": {
|
148
|
+
"name": "Playsam, Inc",
|
149
|
+
"website": "http://www.playsam.com",
|
150
|
+
"logo": {
|
151
|
+
"link_type": "Asset",
|
152
|
+
"id": "playsam_image"
|
153
|
+
}
|
149
154
|
}
|
150
155
|
},
|
151
156
|
{
|
152
|
-
"
|
153
|
-
|
154
|
-
|
155
|
-
"
|
156
|
-
"
|
157
|
-
"
|
157
|
+
"sys": {
|
158
|
+
"id": "normann"
|
159
|
+
},
|
160
|
+
"fields": {
|
161
|
+
"name": "Normann Copenhagen, Inc",
|
162
|
+
"website": "http://www.normann-copenhagen.com/",
|
163
|
+
"logo": {
|
164
|
+
"linkType": "Asset",
|
165
|
+
"id": "normann_image"
|
166
|
+
}
|
158
167
|
}
|
159
168
|
}
|
160
169
|
],
|
161
170
|
"category": [
|
162
171
|
{
|
163
|
-
"
|
164
|
-
|
165
|
-
|
166
|
-
"
|
167
|
-
"
|
168
|
-
"
|
172
|
+
"sys": {
|
173
|
+
"id": "toys"
|
174
|
+
},
|
175
|
+
"fields": {
|
176
|
+
"title": "Toys",
|
177
|
+
"description": "Toys for children",
|
178
|
+
"icon": {
|
179
|
+
"linkType": "Asset",
|
180
|
+
"id": "toy_image"
|
181
|
+
}
|
169
182
|
}
|
170
183
|
},
|
171
184
|
{
|
172
|
-
"
|
173
|
-
|
174
|
-
|
175
|
-
"
|
176
|
-
"
|
177
|
-
"
|
185
|
+
"sys": {
|
186
|
+
"id": "kitchen"
|
187
|
+
},
|
188
|
+
"fields": {
|
189
|
+
"title": "House and Kitchen",
|
190
|
+
"description": "House and Kitchen accessories",
|
191
|
+
"icon": {
|
192
|
+
"linkType": "Asset",
|
193
|
+
"id": "kitchen_image"
|
194
|
+
}
|
178
195
|
}
|
179
196
|
}
|
180
197
|
],
|
181
198
|
"product": [
|
182
199
|
{
|
183
|
-
"
|
184
|
-
|
185
|
-
"description": "A classic Playsam design, the Streamliner Classic Car has been selected as Swedish Design Classic by the Swedish National Museum for its inventive style and sleek surface. It's no wonder that this wooden car has also been a long-standing favorite for children both big and small!",
|
186
|
-
"image": {
|
187
|
-
"link_type": "Asset",
|
188
|
-
"id": "toy_car"
|
189
|
-
},
|
190
|
-
"brand": {
|
191
|
-
"link_type": "Entry",
|
192
|
-
"id": "playsam"
|
193
|
-
},
|
194
|
-
"category": {
|
195
|
-
"link_type": "Entry",
|
196
|
-
"id": "toys"
|
200
|
+
"sys": {
|
201
|
+
"id": "playsam_car"
|
197
202
|
},
|
198
|
-
"
|
203
|
+
"fields": {
|
204
|
+
"name": "Playsam Streamliner Classic Car, Espresso",
|
205
|
+
"description": "A classic Playsam design, the Streamliner Classic Car has been selected as Swedish Design Classic by the Swedish National Museum for its inventive style and sleek surface. It's no wonder that this wooden car has also been a long-standing favorite for children both big and small!",
|
206
|
+
"image": {
|
207
|
+
"linkType": "Asset",
|
208
|
+
"id": "toy_car"
|
209
|
+
},
|
210
|
+
"brand": {
|
211
|
+
"linkType": "Entry",
|
212
|
+
"id": "playsam"
|
213
|
+
},
|
214
|
+
"category": {
|
215
|
+
"linkType": "Entry",
|
216
|
+
"id": "toys"
|
217
|
+
},
|
218
|
+
"url": "http://www.amazon.com/dp/B001R6JUZ2/"
|
219
|
+
}
|
199
220
|
},
|
200
221
|
{
|
201
|
-
"
|
202
|
-
|
203
|
-
"description": "A creative little whisk that comes in 8 different colors. Handy and easy to clean after use. A great gift idea.",
|
204
|
-
"image": {
|
205
|
-
"link_type": "Asset",
|
206
|
-
"id": "whiskers"
|
222
|
+
"sys": {
|
223
|
+
"id": "whisk_beater"
|
207
224
|
},
|
208
|
-
"
|
209
|
-
"
|
210
|
-
"
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
225
|
+
"fields": {
|
226
|
+
"name": "Whisk Beater",
|
227
|
+
"description": "A creative little whisk that comes in 8 different colors. Handy and easy to clean after use. A great gift idea.",
|
228
|
+
"image": {
|
229
|
+
"linkType": "Asset",
|
230
|
+
"id": "whiskers"
|
231
|
+
},
|
232
|
+
"brand": {
|
233
|
+
"linkType": "Entry",
|
234
|
+
"id": "normann"
|
235
|
+
},
|
236
|
+
"category": {
|
237
|
+
"linkType": "Entry",
|
238
|
+
"id": "kitchen"
|
239
|
+
},
|
240
|
+
"url": "http://www.amazon.com/dp/B0081F2CCK/"
|
241
|
+
}
|
217
242
|
}
|
218
243
|
]
|
219
244
|
}
|
@@ -64,7 +64,7 @@ module Contentful
|
|
64
64
|
url = client.base_url.sub('spaces', 'token')
|
65
65
|
response = Contentful::Management::Client.get_http(url, nil, client.request_headers)
|
66
66
|
organization_ids = JSON.load(response.body.to_s)['includes']['Organization'].map do |org|
|
67
|
-
|
67
|
+
sprintf('%-20s %s', org['name'], org['sys']['id'])
|
68
68
|
end
|
69
69
|
organization_ids.sort
|
70
70
|
end
|
@@ -2,6 +2,7 @@ require 'contentful'
|
|
2
2
|
require 'inifile'
|
3
3
|
require 'json'
|
4
4
|
require 'zlib'
|
5
|
+
require 'contentful/bootstrap/version'
|
5
6
|
|
6
7
|
module Contentful
|
7
8
|
module Bootstrap
|
@@ -12,7 +13,8 @@ module Contentful
|
|
12
13
|
|
13
14
|
def generate_json
|
14
15
|
template = {}
|
15
|
-
template['
|
16
|
+
template['version'] = Contentful::Bootstrap.major_version
|
17
|
+
template['contentTypes'] = content_types
|
16
18
|
template['assets'] = assets
|
17
19
|
template['entries'] = entries
|
18
20
|
JSON.pretty_generate(template)
|
@@ -21,7 +23,7 @@ module Contentful
|
|
21
23
|
private
|
22
24
|
|
23
25
|
def assets
|
24
|
-
proccessed_assets = @client.assets.map do |asset|
|
26
|
+
proccessed_assets = @client.assets(limit: 1000).map do |asset|
|
25
27
|
result = { 'id' => asset.sys[:id], 'title' => asset.title }
|
26
28
|
result['file'] = {
|
27
29
|
'filename' => ::File.basename(asset.file.file_name, '.*'),
|
@@ -35,7 +37,7 @@ module Contentful
|
|
35
37
|
def content_types
|
36
38
|
proccessed_content_types = @client.content_types.map do |type|
|
37
39
|
result = { 'id' => type.sys[:id], 'name' => type.name }
|
38
|
-
result['
|
40
|
+
result['displayField'] = type.display_field unless type.display_field.nil?
|
39
41
|
|
40
42
|
result['fields'] = type.fields.map do |field|
|
41
43
|
map_field_properties(field.properties)
|
@@ -49,12 +51,12 @@ module Contentful
|
|
49
51
|
def entries
|
50
52
|
entries = {}
|
51
53
|
|
52
|
-
@client.entries.each do |entry|
|
53
|
-
result = { 'id' => entry.sys[:id] }
|
54
|
+
@client.entries(limit: 1000).each do |entry|
|
55
|
+
result = { 'sys' => { 'id' => entry.sys[:id] }, 'fields' => {} }
|
54
56
|
|
55
57
|
entry.fields.each do |key, value|
|
56
58
|
value = map_field(value)
|
57
|
-
result[key] = value unless value.nil?
|
59
|
+
result['fields'][key] = value unless value.nil?
|
58
60
|
end
|
59
61
|
|
60
62
|
ct_id = entry.content_type.sys[:id]
|
@@ -70,7 +72,7 @@ module Contentful
|
|
70
72
|
|
71
73
|
if value.is_a?(Contentful::Asset) || value.is_a?(Contentful::Entry)
|
72
74
|
return {
|
73
|
-
'
|
75
|
+
'linkType' => value.class.name.split('::').last,
|
74
76
|
'id' => value.sys[:id]
|
75
77
|
}
|
76
78
|
end
|
@@ -81,8 +83,6 @@ module Contentful
|
|
81
83
|
end
|
82
84
|
|
83
85
|
def map_field_properties(properties)
|
84
|
-
properties['link_type'] = properties.delete(:linkType) unless properties[:linkType].nil?
|
85
|
-
|
86
86
|
items = properties[:items]
|
87
87
|
properties[:items] = map_field_properties(items.properties) unless items.nil?
|
88
88
|
|
@@ -13,18 +13,16 @@ module Contentful
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def run
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
raise e
|
27
|
-
end
|
16
|
+
create_content_types
|
17
|
+
create_assets
|
18
|
+
create_entries
|
19
|
+
rescue Contentful::Management::Error => e
|
20
|
+
error = e.error
|
21
|
+
puts "Error at: #{error[:url]}"
|
22
|
+
puts "Message: #{error[:message]}"
|
23
|
+
puts "Details: #{error[:details]}"
|
24
|
+
|
25
|
+
raise e
|
28
26
|
end
|
29
27
|
|
30
28
|
def content_types
|
@@ -66,12 +64,12 @@ module Contentful
|
|
66
64
|
field.id = f['id']
|
67
65
|
field.name = f['name']
|
68
66
|
field.type = f['type']
|
69
|
-
field.link_type = f['
|
67
|
+
field.link_type = f['linkType'] if link?(f)
|
70
68
|
|
71
69
|
if array?(f)
|
72
70
|
array_field = Contentful::Management::Field.new
|
73
71
|
array_field.type = f['items']['type']
|
74
|
-
array_field.link_type = f['items']['
|
72
|
+
array_field.link_type = f['items']['linkType']
|
75
73
|
field.items = array_field
|
76
74
|
end
|
77
75
|
|
@@ -85,7 +83,7 @@ module Contentful
|
|
85
83
|
end
|
86
84
|
|
87
85
|
def link?(field)
|
88
|
-
field.key?('
|
86
|
+
field.key?('linkType')
|
89
87
|
end
|
90
88
|
|
91
89
|
def array?(field)
|
@@ -117,13 +115,11 @@ module Contentful
|
|
117
115
|
|
118
116
|
def create_entries
|
119
117
|
content_types = []
|
120
|
-
entries.
|
118
|
+
processed_entries = entries.map do |content_type_id, entry_list|
|
121
119
|
content_type = space.content_types.find(content_type_id)
|
122
120
|
content_types << content_type
|
123
121
|
|
124
|
-
entry_list.
|
125
|
-
puts "Creating Entry #{index} for #{content_type_id.capitalize}"
|
126
|
-
|
122
|
+
entry_list.each.map do |e|
|
127
123
|
array_fields = []
|
128
124
|
regular_fields = []
|
129
125
|
e.each do |field_name, value|
|
@@ -147,17 +143,39 @@ module Contentful
|
|
147
143
|
end
|
148
144
|
|
149
145
|
regular_fields.each do |rf|
|
150
|
-
|
146
|
+
value = e.delete(rf)
|
147
|
+
if value.is_a? ::Contentful::Bootstrap::Templates::Links::Base
|
148
|
+
value = value.to_management_object
|
149
|
+
end
|
150
|
+
e[rf.to_sym] = value
|
151
151
|
end
|
152
152
|
|
153
|
-
entry = content_type.entries.create(e
|
153
|
+
entry = content_type.entries.create({:id => e[:id]})
|
154
154
|
entry.save
|
155
|
+
|
156
|
+
e = e.clone
|
157
|
+
e[:id] = entry.id # in case no ID was specified in template
|
158
|
+
e
|
155
159
|
end
|
156
|
-
end
|
160
|
+
end.flatten
|
157
161
|
|
158
|
-
|
159
|
-
|
162
|
+
processed_entries = processed_entries.map do |e|
|
163
|
+
puts "Creating Entry #{e[:id]}"
|
164
|
+
|
165
|
+
entry = space.entries.find(e[:id])
|
166
|
+
e.delete(:id)
|
167
|
+
entry.update(e)
|
168
|
+
entry.save
|
169
|
+
|
170
|
+
10.times do
|
171
|
+
break if space.entries.find(entry.id).sys[:version] >= 4
|
172
|
+
sleep(1)
|
173
|
+
end
|
174
|
+
|
175
|
+
entry.id
|
160
176
|
end
|
177
|
+
|
178
|
+
processed_entries.each { |e| space.entries.find(e).publish }
|
161
179
|
end
|
162
180
|
end
|
163
181
|
end
|