contentful-management 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/contentful/management/asset.rb +0 -13
- data/lib/contentful/management/content_type.rb +1 -14
- data/lib/contentful/management/content_type_entry_methods_factory.rb +1 -0
- data/lib/contentful/management/editor_interface.rb +1 -9
- data/lib/contentful/management/entry.rb +2 -21
- data/lib/contentful/management/resource.rb +25 -7
- data/lib/contentful/management/resource_requester.rb +4 -3
- data/lib/contentful/management/ui_extension.rb +4 -9
- data/lib/contentful/management/version.rb +1 -1
- data/spec/fixtures/vcr_cassettes/content_type/{create_with_StructuredText_field.yml → create_with_RichText_field.yml} +8 -8
- data/spec/lib/contentful/management/content_type_spec.rb +10 -10
- data/spec/lib/contentful/management/ui_extension_spec.rb +10 -10
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 683b48fdab7cafe30ccbc6ba4359db731ce08a97f59b83cae82397a3982f03bf
|
4
|
+
data.tar.gz: bf94afa87c07baa3daca8e6b70dad36000fadffcd41334e625ddadfe4f25197f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbebbb891e59e74e85919ea4e8e992ace7c467b652a098d8668cf5b587744789ac8fc4de1dff1026a1a010ad0d85aa33c99bfbfb01fd0a437e2c8e287841fb56
|
7
|
+
data.tar.gz: 6e0af2ee33543eab79af415edaa8939a6ab747d858d8717d16a621aaf45a898e50dca21cb0fdf2282c2b691b599d3935a4d87f2781c5c57da85baaed05157025
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
## Master
|
4
4
|
|
5
|
+
## 2.5.0
|
6
|
+
|
7
|
+
As `RichText` moves from `alpha` to `beta`, we're treating this as a feature release.
|
8
|
+
|
9
|
+
### Added
|
10
|
+
* Added `#save` method to resources, generalizing how to create/update them.
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
* Renamed `StructuredText` to `RichText`.
|
14
|
+
|
5
15
|
## 2.4.0
|
6
16
|
### Added
|
7
17
|
* Added support for StructuredText field type.
|
@@ -64,19 +64,6 @@ module Contentful
|
|
64
64
|
self
|
65
65
|
end
|
66
66
|
|
67
|
-
# If an asset is a new object gets created in the Contentful, otherwise the existing asset gets updated.
|
68
|
-
# @see _ https://github.com/contentful/contentful-management.rb for details.
|
69
|
-
#
|
70
|
-
# @return [Contentful::Management::Asset]
|
71
|
-
def save
|
72
|
-
if id
|
73
|
-
update(title: title, description: description, file: file)
|
74
|
-
else
|
75
|
-
new_instance = self.class.create(client, sys[:space].id, fields: instance_variable_get(:@fields))
|
76
|
-
refresh_data(new_instance)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
67
|
# Returns currently supported locale or default locale.
|
81
68
|
# @return [String] current_locale
|
82
69
|
def locale
|
@@ -26,7 +26,7 @@ module Contentful
|
|
26
26
|
ARRAY = 'Array'.freeze,
|
27
27
|
OBJECT = 'Object'.freeze,
|
28
28
|
LOCATION = 'Location'.freeze,
|
29
|
-
STRUCTURED_TEXT = '
|
29
|
+
STRUCTURED_TEXT = 'RichText'.freeze
|
30
30
|
].freeze
|
31
31
|
|
32
32
|
include Contentful::Management::Resource
|
@@ -74,19 +74,6 @@ module Contentful
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
# If a content type is a new object gets created in the Contentful, otherwise the existing entry gets updated.
|
78
|
-
# @see _ README for details.
|
79
|
-
#
|
80
|
-
# @return [Contentful::Management::ContentType]
|
81
|
-
def save
|
82
|
-
if id
|
83
|
-
update(@properties)
|
84
|
-
else
|
85
|
-
new_instance = self.class.create(client, space.id, environment_id, @properties)
|
86
|
-
refresh_data(new_instance)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
77
|
# This method merges existing fields with new one, when adding, creating or updating new fields.
|
91
78
|
# @private
|
92
79
|
def merged_fields(new_field)
|
@@ -66,19 +66,11 @@ module Contentful
|
|
66
66
|
content_type_id: content_type.id,
|
67
67
|
editor_id: id
|
68
68
|
},
|
69
|
-
{ 'controls' => attributes
|
69
|
+
{ 'controls' => attributes[:controls] || controls },
|
70
70
|
version: sys[:version]
|
71
71
|
)
|
72
72
|
end
|
73
73
|
|
74
|
-
# Saves the current editor interface.
|
75
|
-
# @see _ README for details.
|
76
|
-
#
|
77
|
-
# @return [Contentful::Management::EditorInterface]
|
78
|
-
def save
|
79
|
-
update(controls: controls) if id
|
80
|
-
end
|
81
|
-
|
82
74
|
# Destroys an EditorInterface.
|
83
75
|
#
|
84
76
|
# Not Supported
|
@@ -61,8 +61,8 @@ module Contentful
|
|
61
61
|
end
|
62
62
|
|
63
63
|
# @private
|
64
|
-
def self.create_headers(_client, attributes)
|
65
|
-
content_type = attributes[:content_type]
|
64
|
+
def self.create_headers(_client, attributes, instance = nil)
|
65
|
+
content_type = instance.nil? ? attributes[:content_type] : (instance.content_type || instance.sys[:contentType])
|
66
66
|
content_type_id = content_type.respond_to?(:id) ? content_type.id : content_type[:id]
|
67
67
|
|
68
68
|
{ content_type_id: content_type_id }
|
@@ -130,25 +130,6 @@ module Contentful
|
|
130
130
|
self.locale = attributes[:locale] || client.default_locale
|
131
131
|
end
|
132
132
|
|
133
|
-
# If an entry is a new object gets created in the Contentful, otherwise the existing entry gets updated.
|
134
|
-
# @see _ README for details.
|
135
|
-
#
|
136
|
-
# @return [Contentful::Management::Entry]
|
137
|
-
def save
|
138
|
-
if id
|
139
|
-
update({})
|
140
|
-
else
|
141
|
-
new_instance = Contentful::Management::Entry.create(
|
142
|
-
client,
|
143
|
-
content_type.space.id,
|
144
|
-
environment_id,
|
145
|
-
content_type: content_type,
|
146
|
-
fields: instance_variable_get(:@fields)
|
147
|
-
)
|
148
|
-
refresh_data(new_instance)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
133
|
# Returns the currently supported local.
|
153
134
|
#
|
154
135
|
# @return [String] current_locale
|
@@ -62,18 +62,24 @@ module Contentful
|
|
62
62
|
#
|
63
63
|
# @return [Contentful::Management::Resource]
|
64
64
|
def update(attributes)
|
65
|
+
headers = self.class.create_headers(client, attributes, self)
|
66
|
+
headers = headers.merge(update_headers)
|
67
|
+
|
65
68
|
ResourceRequester.new(client, self.class).update(
|
66
69
|
self,
|
67
|
-
|
68
|
-
space_id: space.id,
|
69
|
-
environment_id: environment_id,
|
70
|
-
resource_id: id
|
71
|
-
},
|
70
|
+
update_url_attributes,
|
72
71
|
query_attributes(attributes),
|
73
|
-
|
72
|
+
headers
|
74
73
|
)
|
75
74
|
end
|
76
75
|
|
76
|
+
# Creates or updates a resource.
|
77
|
+
#
|
78
|
+
# @return [Contentful::Management::Resource]
|
79
|
+
def save
|
80
|
+
update({})
|
81
|
+
end
|
82
|
+
|
77
83
|
# Destroys a resource.
|
78
84
|
#
|
79
85
|
# @return [true, Contentful::Management::Error] success
|
@@ -130,6 +136,18 @@ module Contentful
|
|
130
136
|
|
131
137
|
protected
|
132
138
|
|
139
|
+
def update_headers
|
140
|
+
{ version: sys[:version] }
|
141
|
+
end
|
142
|
+
|
143
|
+
def update_url_attributes
|
144
|
+
{
|
145
|
+
space_id: space.id,
|
146
|
+
environment_id: environment_id,
|
147
|
+
resource_id: id
|
148
|
+
}
|
149
|
+
end
|
150
|
+
|
133
151
|
def query_attributes(attributes)
|
134
152
|
attributes
|
135
153
|
end
|
@@ -249,7 +267,7 @@ module Contentful
|
|
249
267
|
end
|
250
268
|
|
251
269
|
# @private
|
252
|
-
def create_headers(_client, _attributes)
|
270
|
+
def create_headers(_client, _attributes, _instance = nil)
|
253
271
|
{}
|
254
272
|
end
|
255
273
|
|
@@ -35,7 +35,7 @@ module Contentful
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def update(object, endpoint_options = {}, attributes = {}, headers = {})
|
38
|
-
object.refresh_data(put(endpoint_options, attributes, headers))
|
38
|
+
object.refresh_data(put(endpoint_options, attributes, headers, object))
|
39
39
|
end
|
40
40
|
|
41
41
|
def destroy(endpoint_options = {})
|
@@ -69,7 +69,8 @@ module Contentful
|
|
69
69
|
ResourceBuilder.new(request.get, client).run
|
70
70
|
end
|
71
71
|
|
72
|
-
def put(endpoint_options = {}, attributes = {}, headers = {})
|
72
|
+
def put(endpoint_options = {}, attributes = {}, headers = {}, object = nil)
|
73
|
+
is_update = !object.nil? && object.id
|
73
74
|
request = Request.new(
|
74
75
|
client,
|
75
76
|
resource_class.build_endpoint(endpoint_options),
|
@@ -77,7 +78,7 @@ module Contentful
|
|
77
78
|
nil,
|
78
79
|
headers
|
79
80
|
)
|
80
|
-
ResourceBuilder.new(request.put, client).run
|
81
|
+
ResourceBuilder.new(is_update ? request.put : request.post, client).run
|
81
82
|
end
|
82
83
|
|
83
84
|
def delete(endpoint_options = {}, attributes = {}, headers = {})
|
@@ -22,13 +22,13 @@ module Contentful
|
|
22
22
|
def self.create_attributes(_client, attributes)
|
23
23
|
extension = attributes['extension'] || attributes[:extension]
|
24
24
|
|
25
|
-
fail 'Invalid UI Extension attributes' unless valid_extension(extension)
|
25
|
+
fail 'Invalid UI Extension attributes' unless valid_extension?(extension)
|
26
26
|
|
27
27
|
{ 'extension' => extension }
|
28
28
|
end
|
29
29
|
|
30
30
|
# @private
|
31
|
-
def self.valid_extension(extension)
|
31
|
+
def self.valid_extension?(extension)
|
32
32
|
return false unless extension.key?('name')
|
33
33
|
return false unless extension.key?('fieldTypes') && extension['fieldTypes'].is_a?(::Array)
|
34
34
|
return false unless extension.key?('src') || extension.key?('srcdoc')
|
@@ -41,13 +41,8 @@ module Contentful
|
|
41
41
|
#
|
42
42
|
# @return [Contentful::Management::UIExtension]
|
43
43
|
def save
|
44
|
-
self.class.valid_extension(extension)
|
45
|
-
|
46
|
-
update(extension: extension)
|
47
|
-
else
|
48
|
-
new_instance = self.class.create(client, sys[:space].id, environment_id, extension: extension)
|
49
|
-
refresh_data(new_instance)
|
50
|
-
end
|
44
|
+
fail 'Invalid UI extension attributes' unless self.class.valid_extension?(extension)
|
45
|
+
update(extension: extension)
|
51
46
|
end
|
52
47
|
|
53
48
|
# Returns extension name
|
@@ -5,9 +5,9 @@ http_interactions:
|
|
5
5
|
uri: https://api.contentful.com/spaces/ctgv7kwgsghk/environments/master/content_types
|
6
6
|
body:
|
7
7
|
encoding: UTF-8
|
8
|
-
string: '{"name":"
|
9
|
-
field","fields":[{"id":"
|
10
|
-
Field","type":"
|
8
|
+
string: '{"name":"RichText","description":"Content type with RichText
|
9
|
+
field","fields":[{"id":"my_RichText_field","name":"My RichText
|
10
|
+
Field","type":"RichText"}]}'
|
11
11
|
headers:
|
12
12
|
X-Contentful-User-Agent:
|
13
13
|
- sdk contentful-management.rb/2.3.0; platform ruby/2.5.1; os macOS/16;
|
@@ -119,13 +119,13 @@ http_interactions:
|
|
119
119
|
"version": 1
|
120
120
|
},
|
121
121
|
"displayField": null,
|
122
|
-
"name": "
|
123
|
-
"description": "Content type with
|
122
|
+
"name": "RichText",
|
123
|
+
"description": "Content type with RichText field",
|
124
124
|
"fields": [
|
125
125
|
{
|
126
|
-
"id": "
|
127
|
-
"name": "My
|
128
|
-
"type": "
|
126
|
+
"id": "my_RichText_field",
|
127
|
+
"name": "My RichText Field",
|
128
|
+
"type": "RichText",
|
129
129
|
"localized": false,
|
130
130
|
"required": false,
|
131
131
|
"validations": [],
|
@@ -188,7 +188,7 @@ module Contentful
|
|
188
188
|
end
|
189
189
|
end
|
190
190
|
|
191
|
-
Contentful::Management::ContentType::FIELD_TYPES.reject { |f| f == '
|
191
|
+
Contentful::Management::ContentType::FIELD_TYPES.reject { |f| f == 'RichText' }.each do |field_type|
|
192
192
|
it "creates within a space with #{ field_type } field" do
|
193
193
|
vcr("content_type/create_with_#{ field_type }_field") do
|
194
194
|
field = Contentful::Management::Field.new
|
@@ -213,22 +213,22 @@ module Contentful
|
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
216
|
-
it "creates within a space with
|
217
|
-
vcr("content_type/
|
216
|
+
it "creates within a space with RichText field" do
|
217
|
+
vcr("content_type/create_with_RichText_field") do
|
218
218
|
subject = client.content_types('ctgv7kwgsghk', 'master')
|
219
219
|
|
220
220
|
field = Contentful::Management::Field.new
|
221
|
-
field.id = "
|
222
|
-
field.name = "My
|
223
|
-
field.type = '
|
221
|
+
field.id = "my_RichText_field"
|
222
|
+
field.name = "My RichText Field"
|
223
|
+
field.type = 'RichText'
|
224
224
|
content_type = subject.create(
|
225
|
-
name: "
|
226
|
-
description: "Content type with
|
225
|
+
name: "RichText",
|
226
|
+
description: "Content type with RichText field",
|
227
227
|
fields: [field]
|
228
228
|
)
|
229
229
|
expect(content_type).to be_kind_of Contentful::Management::ContentType
|
230
|
-
expect(content_type.name).to eq "
|
231
|
-
expect(content_type.description).to eq "Content type with
|
230
|
+
expect(content_type.name).to eq "RichText"
|
231
|
+
expect(content_type.description).to eq "Content type with RichText field"
|
232
232
|
expect(content_type.fields.size).to eq 1
|
233
233
|
result_field = content_type.fields.first
|
234
234
|
expect(result_field.id).to eq field.id
|
@@ -14,11 +14,11 @@ module Contentful
|
|
14
14
|
subject { client.ui_extensions(space_id, 'master') }
|
15
15
|
|
16
16
|
describe 'class methods' do
|
17
|
-
describe '::valid_extension' do
|
17
|
+
describe '::valid_extension?' do
|
18
18
|
it 'false when name is missing' do
|
19
19
|
extension = {}
|
20
20
|
|
21
|
-
expect(described_class.valid_extension(extension)).to be_falsey
|
21
|
+
expect(described_class.valid_extension?(extension)).to be_falsey
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'false when fieldTypes is missing' do
|
@@ -26,7 +26,7 @@ module Contentful
|
|
26
26
|
'name' => 'foobar'
|
27
27
|
}
|
28
28
|
|
29
|
-
expect(described_class.valid_extension(extension)).to be_falsey
|
29
|
+
expect(described_class.valid_extension?(extension)).to be_falsey
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'false when fieldTypes is present but not an array' do
|
@@ -35,7 +35,7 @@ module Contentful
|
|
35
35
|
'fieldTypes' => 'baz'
|
36
36
|
}
|
37
37
|
|
38
|
-
expect(described_class.valid_extension(extension)).to be_falsey
|
38
|
+
expect(described_class.valid_extension?(extension)).to be_falsey
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'false when both src and srcdoc missing' do
|
@@ -44,7 +44,7 @@ module Contentful
|
|
44
44
|
'fieldTypes' => ['Symbol']
|
45
45
|
}
|
46
46
|
|
47
|
-
expect(described_class.valid_extension(extension)).to be_falsey
|
47
|
+
expect(described_class.valid_extension?(extension)).to be_falsey
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'true when all of the above are passed' do
|
@@ -54,7 +54,7 @@ module Contentful
|
|
54
54
|
'src' => 'foo'
|
55
55
|
}
|
56
56
|
|
57
|
-
expect(described_class.valid_extension(extension)).to be_truthy
|
57
|
+
expect(described_class.valid_extension?(extension)).to be_truthy
|
58
58
|
|
59
59
|
extension = {
|
60
60
|
'name' => 'foobar',
|
@@ -62,7 +62,7 @@ module Contentful
|
|
62
62
|
'srcdoc' => 'foo'
|
63
63
|
}
|
64
64
|
|
65
|
-
expect(described_class.valid_extension(extension)).to be_truthy
|
65
|
+
expect(described_class.valid_extension?(extension)).to be_truthy
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'false if sidebar is present but not boolean' do
|
@@ -73,7 +73,7 @@ module Contentful
|
|
73
73
|
'sidebar' => true
|
74
74
|
}
|
75
75
|
|
76
|
-
expect(described_class.valid_extension(extension)).to be_truthy
|
76
|
+
expect(described_class.valid_extension?(extension)).to be_truthy
|
77
77
|
|
78
78
|
extension = {
|
79
79
|
'name' => 'foobar',
|
@@ -82,7 +82,7 @@ module Contentful
|
|
82
82
|
'sidebar' => false
|
83
83
|
}
|
84
84
|
|
85
|
-
expect(described_class.valid_extension(extension)).to be_truthy
|
85
|
+
expect(described_class.valid_extension?(extension)).to be_truthy
|
86
86
|
|
87
87
|
extension = {
|
88
88
|
'name' => 'foobar',
|
@@ -91,7 +91,7 @@ module Contentful
|
|
91
91
|
'sidebar' => 'foobar'
|
92
92
|
}
|
93
93
|
|
94
|
-
expect(described_class.valid_extension(extension)).to be_falsey
|
94
|
+
expect(described_class.valid_extension?(extension)).to be_falsey
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contentful-management
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Protas
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2018-
|
13
|
+
date: 2018-10-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: http
|
@@ -466,7 +466,7 @@ files:
|
|
466
466
|
- spec/fixtures/vcr_cassettes/content_type/create_with_Location_field.yml
|
467
467
|
- spec/fixtures/vcr_cassettes/content_type/create_with_Number_field.yml
|
468
468
|
- spec/fixtures/vcr_cassettes/content_type/create_with_Object_field.yml
|
469
|
-
- spec/fixtures/vcr_cassettes/content_type/
|
469
|
+
- spec/fixtures/vcr_cassettes/content_type/create_with_RichText_field.yml
|
470
470
|
- spec/fixtures/vcr_cassettes/content_type/create_with_Symbol_field.yml
|
471
471
|
- spec/fixtures/vcr_cassettes/content_type/create_with_Text_field.yml
|
472
472
|
- spec/fixtures/vcr_cassettes/content_type/deactivate.yml
|
@@ -853,7 +853,7 @@ test_files:
|
|
853
853
|
- spec/fixtures/vcr_cassettes/content_type/create_with_Location_field.yml
|
854
854
|
- spec/fixtures/vcr_cassettes/content_type/create_with_Number_field.yml
|
855
855
|
- spec/fixtures/vcr_cassettes/content_type/create_with_Object_field.yml
|
856
|
-
- spec/fixtures/vcr_cassettes/content_type/
|
856
|
+
- spec/fixtures/vcr_cassettes/content_type/create_with_RichText_field.yml
|
857
857
|
- spec/fixtures/vcr_cassettes/content_type/create_with_Symbol_field.yml
|
858
858
|
- spec/fixtures/vcr_cassettes/content_type/create_with_Text_field.yml
|
859
859
|
- spec/fixtures/vcr_cassettes/content_type/deactivate.yml
|