contentful-management 3.7.0 → 3.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +1 -1
- data/.rubocop_todo.yml +72 -7
- data/CHANGELOG.md +9 -0
- data/README.md +19 -0
- data/contentful-management.gemspec +4 -3
- data/lib/contentful/management/api_key.rb +2 -0
- data/lib/contentful/management/array.rb +2 -0
- data/lib/contentful/management/asset.rb +5 -3
- data/lib/contentful/management/client.rb +8 -4
- data/lib/contentful/management/client_api_key_methods_factory.rb +2 -0
- data/lib/contentful/management/client_asset_methods_factory.rb +2 -0
- data/lib/contentful/management/client_association_all_published_method_factory.rb +2 -0
- data/lib/contentful/management/client_association_methods_factory.rb +2 -0
- data/lib/contentful/management/client_content_type_methods_factory.rb +2 -0
- data/lib/contentful/management/client_editor_interface_methods_factory.rb +2 -0
- data/lib/contentful/management/client_entry_methods_factory.rb +2 -0
- data/lib/contentful/management/client_environment_methods_factory.rb +2 -0
- data/lib/contentful/management/client_locale_methods_factory.rb +2 -0
- data/lib/contentful/management/client_organization_methods_factory.rb +2 -0
- data/lib/contentful/management/client_organization_periodic_usage_methods_factory.rb +2 -0
- data/lib/contentful/management/client_personal_access_tokens_methods_factory.rb +2 -0
- data/lib/contentful/management/client_preview_api_key_methods_factory.rb +2 -0
- data/lib/contentful/management/client_role_methods_factory.rb +2 -0
- data/lib/contentful/management/client_snapshot_methods_factory.rb +2 -0
- data/lib/contentful/management/client_space_membership_methods_factory.rb +2 -0
- data/lib/contentful/management/client_space_methods_factory.rb +2 -0
- data/lib/contentful/management/client_space_periodic_usage_methods_factory.rb +2 -0
- data/lib/contentful/management/client_tag_methods_factory.rb +2 -0
- data/lib/contentful/management/client_ui_extension_methods_factory.rb +2 -0
- data/lib/contentful/management/client_upload_methods_factory.rb +2 -0
- data/lib/contentful/management/client_user_methods_factory.rb +2 -0
- data/lib/contentful/management/client_webhook_call_methods_factory.rb +2 -0
- data/lib/contentful/management/client_webhook_health_methods_factory.rb +2 -0
- data/lib/contentful/management/client_webhook_methods_factory.rb +2 -0
- data/lib/contentful/management/content_type.rb +13 -11
- data/lib/contentful/management/content_type_editor_interface_methods_factory.rb +2 -0
- data/lib/contentful/management/content_type_entry_methods_factory.rb +2 -0
- data/lib/contentful/management/content_type_snapshot_methods_factory.rb +2 -0
- data/lib/contentful/management/dynamic_entry.rb +3 -3
- data/lib/contentful/management/editor_interface.rb +3 -1
- data/lib/contentful/management/entry.rb +5 -3
- data/lib/contentful/management/entry_association_methods_factory.rb +2 -0
- data/lib/contentful/management/entry_snapshot_methods_factory.rb +2 -0
- data/lib/contentful/management/environment.rb +2 -0
- data/lib/contentful/management/environment_asset_methods_factory.rb +2 -0
- data/lib/contentful/management/environment_association_methods_factory.rb +2 -0
- data/lib/contentful/management/environment_content_type_methods_factory.rb +2 -0
- data/lib/contentful/management/environment_editor_interface_methods_factory.rb +2 -0
- data/lib/contentful/management/environment_entry_methods_factory.rb +2 -0
- data/lib/contentful/management/environment_locale_methods_factory.rb +2 -0
- data/lib/contentful/management/environment_tag_methods_factory.rb +2 -0
- data/lib/contentful/management/environment_ui_extension_methods_factory.rb +2 -0
- data/lib/contentful/management/error.rb +5 -2
- data/lib/contentful/management/field.rb +3 -0
- data/lib/contentful/management/file.rb +2 -0
- data/lib/contentful/management/link.rb +2 -0
- data/lib/contentful/management/locale.rb +3 -1
- data/lib/contentful/management/location.rb +2 -0
- data/lib/contentful/management/organization.rb +2 -0
- data/lib/contentful/management/organization_periodic_usage.rb +2 -0
- data/lib/contentful/management/organization_user_methods_factory.rb +2 -0
- data/lib/contentful/management/personal_access_token.rb +2 -0
- data/lib/contentful/management/preview_api_key.rb +2 -0
- data/lib/contentful/management/request.rb +3 -8
- data/lib/contentful/management/resource/all_published.rb +2 -0
- data/lib/contentful/management/resource/archiver.rb +2 -0
- data/lib/contentful/management/resource/array_like.rb +2 -0
- data/lib/contentful/management/resource/asset_fields.rb +2 -0
- data/lib/contentful/management/resource/entry_fields.rb +2 -0
- data/lib/contentful/management/resource/environment_aware.rb +2 -0
- data/lib/contentful/management/resource/field_aware.rb +2 -0
- data/lib/contentful/management/resource/fields.rb +3 -1
- data/lib/contentful/management/resource/metadata.rb +3 -0
- data/lib/contentful/management/resource/publisher.rb +2 -0
- data/lib/contentful/management/resource/refresher.rb +3 -0
- data/lib/contentful/management/resource/system_properties.rb +3 -1
- data/lib/contentful/management/resource.rb +4 -3
- data/lib/contentful/management/resource_builder.rb +5 -2
- data/lib/contentful/management/resource_requester.rb +4 -1
- data/lib/contentful/management/response.rb +4 -2
- data/lib/contentful/management/role.rb +3 -1
- data/lib/contentful/management/snapshot.rb +2 -0
- data/lib/contentful/management/space.rb +3 -0
- data/lib/contentful/management/space_api_key_methods_factory.rb +2 -0
- data/lib/contentful/management/space_association_methods_factory.rb +2 -0
- data/lib/contentful/management/space_environment_methods_factory.rb +2 -0
- data/lib/contentful/management/space_membership.rb +2 -0
- data/lib/contentful/management/space_periodic_usage.rb +2 -0
- data/lib/contentful/management/space_preview_api_key_methods_factory.rb +2 -0
- data/lib/contentful/management/space_role_methods_factory.rb +2 -0
- data/lib/contentful/management/space_space_membership_methods_factory.rb +2 -0
- data/lib/contentful/management/space_user_methods_factory.rb +2 -0
- data/lib/contentful/management/space_webhook_methods_factory.rb +2 -0
- data/lib/contentful/management/support.rb +4 -2
- data/lib/contentful/management/tag.rb +2 -0
- data/lib/contentful/management/ui_extension.rb +4 -0
- data/lib/contentful/management/upload.rb +2 -0
- data/lib/contentful/management/user.rb +2 -0
- data/lib/contentful/management/validation.rb +2 -0
- data/lib/contentful/management/version.rb +3 -1
- data/lib/contentful/management/webhook.rb +2 -0
- data/lib/contentful/management/webhook_call.rb +2 -0
- data/lib/contentful/management/webhook_health.rb +2 -0
- data/lib/contentful/management/webhook_webhook_call_methods_factory.rb +2 -0
- data/lib/contentful/management/webhook_webhook_health_methods_factory.rb +2 -0
- data/lib/contentful/management.rb +2 -0
- data/spec/fixtures/vcr_cassettes/content_type/fields/resource_link_with_params.yml +316 -0
- data/spec/lib/contentful/management/content_type_spec.rb +28 -0
- metadata +15 -19
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Contentful
|
2
4
|
module Management
|
3
5
|
# All errors raised by the contentful gem are either instances of Contentful::Management::Error
|
@@ -66,7 +68,7 @@ module Contentful
|
|
66
68
|
error_message << "Message: #{message}"
|
67
69
|
error_message << "Details: #{handle_details(details)}" if details
|
68
70
|
error_message << "Request ID: #{request_id}" if request_id
|
69
|
-
rescue
|
71
|
+
rescue StandardError
|
70
72
|
error_message << "Message: #{default_error_message}"
|
71
73
|
end
|
72
74
|
|
@@ -89,6 +91,7 @@ module Contentful
|
|
89
91
|
|
90
92
|
handle_detail = proc do |detail|
|
91
93
|
return detail if detail.is_a?(String)
|
94
|
+
|
92
95
|
detail.fetch('details', nil)
|
93
96
|
end
|
94
97
|
|
@@ -177,7 +180,7 @@ module Contentful
|
|
177
180
|
# 429
|
178
181
|
class RateLimitExceeded < Error
|
179
182
|
# Rate Limit Reset Header Key
|
180
|
-
RATE_LIMIT_RESET_HEADER_KEY = 'x-contentful-ratelimit-reset'
|
183
|
+
RATE_LIMIT_RESET_HEADER_KEY = 'x-contentful-ratelimit-reset'
|
181
184
|
|
182
185
|
def reset_time?
|
183
186
|
# rubocop:disable Style/DoubleNegation
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'resource'
|
2
4
|
require_relative 'validation'
|
3
5
|
module Contentful
|
@@ -16,6 +18,7 @@ module Contentful
|
|
16
18
|
property :disabled, :boolean
|
17
19
|
property :localized, :boolean
|
18
20
|
property :validations, Validation
|
21
|
+
property :allowedResources
|
19
22
|
|
20
23
|
# Takes a field object of content type
|
21
24
|
# Merges existing properties, items and validations of field with new one
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'resource'
|
2
4
|
require_relative 'resource/environment_aware'
|
3
5
|
|
@@ -38,7 +40,7 @@ module Contentful
|
|
38
40
|
optional: optional,
|
39
41
|
fallbackCode: fallback_code
|
40
42
|
}.merge(
|
41
|
-
attributes.
|
43
|
+
attributes.transform_keys(&:to_sym)
|
42
44
|
)
|
43
45
|
end
|
44
46
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Contentful
|
2
4
|
module Management
|
3
5
|
# This object represents a request that is to be made. It gets initialized by the client
|
@@ -70,14 +72,7 @@ module Contentful
|
|
70
72
|
private
|
71
73
|
|
72
74
|
def normalize_query(query)
|
73
|
-
|
74
|
-
query.map do |key, value|
|
75
|
-
[
|
76
|
-
key.to_sym,
|
77
|
-
value
|
78
|
-
]
|
79
|
-
end
|
80
|
-
]
|
75
|
+
query.transform_keys(&:to_sym)
|
81
76
|
end
|
82
77
|
end
|
83
78
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative '../file'
|
2
4
|
|
3
5
|
module Contentful
|
@@ -33,7 +35,7 @@ module Contentful
|
|
33
35
|
|
34
36
|
# Create accessors for content type, asset, entry objects.
|
35
37
|
def self.included(base)
|
36
|
-
base.fields_coercions.
|
38
|
+
base.fields_coercions.each_key do |name|
|
37
39
|
accessor_name = Contentful::Management::Support.snakify(name)
|
38
40
|
base.send :define_method, accessor_name do
|
39
41
|
fields[name.to_sym]
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Contentful
|
2
4
|
module Management
|
3
5
|
module Resource
|
@@ -26,6 +28,7 @@ module Contentful
|
|
26
28
|
|
27
29
|
def extract_metadata_from_object!(object)
|
28
30
|
return unless object.key?('metadata')
|
31
|
+
|
29
32
|
object['metadata'].each do |key, value|
|
30
33
|
@_metadata[key.to_sym] = if key == 'tags'
|
31
34
|
coerce_tags(value)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Contentful
|
2
4
|
module Management
|
3
5
|
module Resource
|
@@ -13,6 +15,7 @@ module Contentful
|
|
13
15
|
# @private
|
14
16
|
def refresh_find
|
15
17
|
return self.class.find(client, space.id, environment_id, id) if environment_id
|
18
|
+
|
16
19
|
self.class.find(client, space.id, id)
|
17
20
|
end
|
18
21
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Contentful
|
2
4
|
module Management
|
3
5
|
module Resource
|
@@ -48,7 +50,7 @@ module Contentful
|
|
48
50
|
def self.included(base)
|
49
51
|
base.extend(ClassMethods)
|
50
52
|
|
51
|
-
base.sys_coercions.
|
53
|
+
base.sys_coercions.each_key do |name|
|
52
54
|
accessor_name = Contentful::Management::Support.snakify(name)
|
53
55
|
base.send :define_method, accessor_name do
|
54
56
|
sys[name.to_sym]
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'date'
|
2
4
|
require_relative 'resource/refresher'
|
3
5
|
require_relative 'resource/system_properties'
|
@@ -215,6 +217,7 @@ module Contentful
|
|
215
217
|
base = "#{base}/environments/#{endpoint_options[:environment_id]}" if endpoint_options[:environment_id]
|
216
218
|
base = "#{base}/#{endpoint}"
|
217
219
|
return "#{base}/#{endpoint_options[:resource_id]}#{endpoint_options[:suffix]}" if endpoint_options[:resource_id]
|
220
|
+
|
218
221
|
base
|
219
222
|
end
|
220
223
|
|
@@ -317,9 +320,7 @@ module Contentful
|
|
317
320
|
@property_coercions = superclass.property_coercions.dup.merge(@property_coercions || {})
|
318
321
|
end
|
319
322
|
|
320
|
-
if superclass.respond_to? :sys_coercions
|
321
|
-
@sys_coercions = superclass.sys_coercions.dup.merge(@sys_coercions || {})
|
322
|
-
end
|
323
|
+
@sys_coercions = superclass.sys_coercions.dup.merge(@sys_coercions || {}) if superclass.respond_to? :sys_coercions
|
323
324
|
|
324
325
|
if superclass.respond_to? :fields_coercions
|
325
326
|
@fields_coercions = superclass.fields_coercions.dup.merge(@fields_coercions || {})
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'tag'
|
2
4
|
require_relative 'link'
|
3
5
|
require_relative 'user'
|
@@ -106,8 +108,8 @@ module Contentful
|
|
106
108
|
end
|
107
109
|
|
108
110
|
@resource
|
109
|
-
rescue UnparsableResource =>
|
110
|
-
|
111
|
+
rescue UnparsableResource => e
|
112
|
+
e
|
111
113
|
end
|
112
114
|
|
113
115
|
# Creates a single resource from the response object
|
@@ -217,6 +219,7 @@ module Contentful
|
|
217
219
|
res.public_send(name)[child_name.to_sym] = create_resource(child_object)
|
218
220
|
end
|
219
221
|
next if %w[includes metadata].include?(name)
|
222
|
+
|
220
223
|
detect_child_arrays(potential_objects).each do |child_name, _child_array|
|
221
224
|
replace_child_array res.public_send(name)[child_name.to_sym]
|
222
225
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Contentful
|
2
4
|
module Management
|
3
5
|
# Generic Resource Request Class
|
@@ -56,7 +58,7 @@ module Contentful
|
|
56
58
|
|
57
59
|
def resource_class?(object)
|
58
60
|
object.resource?
|
59
|
-
rescue
|
61
|
+
rescue StandardError
|
60
62
|
false
|
61
63
|
end
|
62
64
|
|
@@ -93,6 +95,7 @@ module Contentful
|
|
93
95
|
)
|
94
96
|
response = request.delete
|
95
97
|
return true if response.status == :no_content
|
98
|
+
|
96
99
|
ResourceBuilder.new(response, client).run
|
97
100
|
end
|
98
101
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'multi_json'
|
2
4
|
require_relative 'error'
|
3
5
|
|
@@ -87,8 +89,8 @@ module Contentful
|
|
87
89
|
|
88
90
|
def parse_json!
|
89
91
|
@object = load_json
|
90
|
-
rescue MultiJson::LoadError =>
|
91
|
-
@error_message =
|
92
|
+
rescue MultiJson::LoadError => e
|
93
|
+
@error_message = e.message
|
92
94
|
UnparsableJson.new(self)
|
93
95
|
end
|
94
96
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'resource'
|
2
4
|
|
3
5
|
module Contentful
|
@@ -54,7 +56,7 @@ module Contentful
|
|
54
56
|
permissions: permissions,
|
55
57
|
policies: policies
|
56
58
|
}.merge(
|
57
|
-
attributes.
|
59
|
+
attributes.transform_keys(&:to_sym)
|
58
60
|
)
|
59
61
|
end
|
60
62
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'role'
|
2
4
|
require_relative 'locale'
|
3
5
|
require_relative 'api_key'
|
@@ -28,6 +30,7 @@ module Contentful
|
|
28
30
|
# @private
|
29
31
|
def self.build_endpoint(endpoint_options)
|
30
32
|
return "spaces/#{endpoint_options[:space_id]}" if endpoint_options.key?(:space_id)
|
33
|
+
|
31
34
|
'spaces'
|
32
35
|
end
|
33
36
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Contentful
|
2
4
|
module Management
|
3
5
|
# Utility methods used by the contentful management gem
|
@@ -5,7 +7,7 @@ module Contentful
|
|
5
7
|
class << self
|
6
8
|
# Transforms CamelCase into snake_case (taken from zucker)
|
7
9
|
def snakify(object)
|
8
|
-
snake = String(object).gsub(/(?<!^)[A-Z]/) { "_#{
|
10
|
+
snake = String(object).gsub(/(?<!^)[A-Z]/) { "_#{::Regexp.last_match(0)}" }
|
9
11
|
snake.downcase
|
10
12
|
end
|
11
13
|
|
@@ -14,7 +16,7 @@ module Contentful
|
|
14
16
|
query_hash.merge(attribute_hash) do |_key, oldval, newval|
|
15
17
|
oldval = oldval.to_hash if oldval.respond_to?(:to_hash)
|
16
18
|
newval = newval.to_hash if newval.respond_to?(:to_hash)
|
17
|
-
oldval.
|
19
|
+
oldval.instance_of?(::Hash) && newval.instance_of?(::Hash) ? deep_hash_merge(oldval, newval) : newval
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'resource'
|
2
4
|
require_relative 'resource/environment_aware'
|
3
5
|
|
@@ -33,6 +35,7 @@ module Contentful
|
|
33
35
|
return false unless extension.key?('fieldTypes') && extension['fieldTypes'].is_a?(::Array)
|
34
36
|
return false unless extension.key?('src') || extension.key?('srcdoc')
|
35
37
|
return false if extension.key?('sidebar') && ![false, true].include?(extension['sidebar'])
|
38
|
+
|
36
39
|
true
|
37
40
|
end
|
38
41
|
|
@@ -42,6 +45,7 @@ module Contentful
|
|
42
45
|
# @return [Contentful::Management::UIExtension]
|
43
46
|
def save
|
44
47
|
fail 'Invalid UI extension attributes' unless self.class.valid_extension?(extension)
|
48
|
+
|
45
49
|
update(extension: extension)
|
46
50
|
end
|
47
51
|
|