contentful-management 1.0.1 → 1.1.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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/Gemfile +1 -0
  4. data/README.md +245 -151
  5. data/lib/contentful/management/client.rb +20 -0
  6. data/lib/contentful/management/client_association_all_published_method_factory.rb +4 -0
  7. data/lib/contentful/management/client_content_type_methods_factory.rb +4 -0
  8. data/lib/contentful/management/client_editor_interface_methods_factory.rb +35 -0
  9. data/lib/contentful/management/client_role_methods_factory.rb +15 -0
  10. data/lib/contentful/management/client_webhook_methods_factory.rb +1 -1
  11. data/lib/contentful/management/content_type.rb +12 -0
  12. data/lib/contentful/management/content_type_editor_interface_methods_factory.rb +22 -0
  13. data/lib/contentful/management/editor_interface.rb +85 -0
  14. data/lib/contentful/management/field.rb +1 -0
  15. data/lib/contentful/management/resource/all_published.rb +1 -0
  16. data/lib/contentful/management/resource/refresher.rb +7 -3
  17. data/lib/contentful/management/resource_builder.rb +5 -1
  18. data/lib/contentful/management/role.rb +33 -0
  19. data/lib/contentful/management/space.rb +28 -0
  20. data/lib/contentful/management/space_association_all_published_method_factory.rb +1 -0
  21. data/lib/contentful/management/space_editor_interface_methods_factory.rb +21 -0
  22. data/lib/contentful/management/space_role_methods_factory.rb +15 -0
  23. data/lib/contentful/management/version.rb +1 -1
  24. data/lib/contentful/management/webhook.rb +4 -1
  25. data/spec/fixtures/vcr_cassettes/content_type/omitted_field.yml +640 -0
  26. data/spec/fixtures/vcr_cassettes/editor_interfaces/default_for_space.yml +252 -0
  27. data/spec/fixtures/vcr_cassettes/editor_interfaces/update.yml +348 -0
  28. data/spec/fixtures/vcr_cassettes/roles/all_for_space.yml +238 -0
  29. data/spec/fixtures/vcr_cassettes/roles/create_for_space.yml +143 -0
  30. data/spec/fixtures/vcr_cassettes/roles/destroy.yml +430 -0
  31. data/spec/fixtures/vcr_cassettes/roles/find.yml +155 -0
  32. data/spec/fixtures/vcr_cassettes/roles/find_for_space_not_found.yml +82 -0
  33. data/spec/fixtures/vcr_cassettes/roles/update.yml +459 -0
  34. data/spec/fixtures/vcr_cassettes/webhook/create_with_name_and_headers.yml +119 -0
  35. data/spec/fixtures/vcr_cassettes/webhook/topics.yml +117 -0
  36. data/spec/lib/contentful/management/asset_spec.rb +4 -0
  37. data/spec/lib/contentful/management/content_type_spec.rb +36 -0
  38. data/spec/lib/contentful/management/editor_interface_spec.rb +57 -0
  39. data/spec/lib/contentful/management/entry_spec.rb +5 -0
  40. data/spec/lib/contentful/management/role_spec.rb +125 -0
  41. data/spec/lib/contentful/management/webhook_spec.rb +37 -0
  42. metadata +35 -2
@@ -11,6 +11,8 @@ require 'contentful/management/client_asset_methods_factory'
11
11
  require 'contentful/management/client_content_type_methods_factory'
12
12
  require 'contentful/management/client_entry_methods_factory'
13
13
  require 'contentful/management/client_locale_methods_factory'
14
+ require 'contentful/management/client_role_methods_factory'
15
+ require 'contentful/management/client_editor_interface_methods_factory'
14
16
  require 'contentful/management/client_webhook_methods_factory'
15
17
 
16
18
  require_relative 'request'
@@ -122,6 +124,24 @@ module Contentful
122
124
  ClientLocaleMethodsFactory.new(self)
123
125
  end
124
126
 
127
+ # Allows manipulation of roles in context of the current client
128
+ # Allows listing all roles for client, creating new and finding one by id.
129
+ # @see _ README for details.
130
+ #
131
+ # @return [Contentful::Management::ClientRoleMethodsFactory]
132
+ def roles
133
+ ClientRoleMethodsFactory.new(self)
134
+ end
135
+
136
+ # Allows manipulation of editor interfaces in context of the current client
137
+ # Allows listing all editor interfaces for client, creating new and finding one by id.
138
+ # @see _ README for details.
139
+ #
140
+ # @return [Contentful::Management::ClientEditorInterfaceMethodsFactory]
141
+ def editor_interfaces
142
+ ClientEditorInterfaceMethodsFactory.new(self)
143
+ end
144
+
125
145
  # Allows manipulation of webhooks in context of the current client
126
146
  # Allows listing all webhooks for client, creating new and finding one by id.
127
147
  # @see _ README for details.
@@ -8,9 +8,13 @@ module Contentful
8
8
  # @param [String] space_id
9
9
  # @param [Hash] params
10
10
  # @see _ For complete option list: http://docs.contentfulcda.apiary.io/#reference/search-parameters
11
+ # @deprecated This call will be soon removed from the API except for Content Types
11
12
  #
12
13
  # @return [Contentful::Management::Array<Contentful::Management::Resource>]
13
14
  def all_published(space_id, params = {})
15
+ warn('This call will soon be removed from the API except for Content Types') unless params.key?(:suppress_warning)
16
+ params.delete(:suppress_warning) if params.key?(:suppress_warning)
17
+
14
18
  @resource_requester.all(
15
19
  { space_id: space_id, public: true },
16
20
  params
@@ -8,6 +8,10 @@ module Contentful
8
8
  class ClientContentTypeMethodsFactory
9
9
  include Contentful::Management::ClientAssociationMethodsFactory
10
10
  include Contentful::Management::ClientAssociationAllPublishedMethodsFactory
11
+
12
+ def all_published(space_id, params = {})
13
+ super(space_id, { suppress_warning: true }.merge(params))
14
+ end
11
15
  end
12
16
  end
13
17
  end
@@ -0,0 +1,35 @@
1
+ require_relative 'client_association_methods_factory'
2
+ require_relative 'editor_interface'
3
+
4
+ module Contentful
5
+ module Management
6
+ # Wrapper for EditorInterface API for usage from within Client
7
+ # @private
8
+ class ClientEditorInterfaceMethodsFactory
9
+ attr_reader :client
10
+
11
+ def initialize(client)
12
+ @client = client
13
+ @resource_requester = ResourceRequester.new(client, associated_class)
14
+ end
15
+
16
+ # Gets the Default Editor Interface
17
+ #
18
+ # @param [String] space_id
19
+ # @param [String] content_type_id
20
+ # @param [Hash] params
21
+ # @see _ For complete option list: http://docs.contentfulcda.apiary.io/#reference/search-parameters
22
+ #
23
+ # @return [Contentful::Management::EditorInterface]
24
+ def default(space_id, content_type_id)
25
+ @resource_requester.all(space_id: space_id, content_type_id: content_type_id, editor_id: 'default')
26
+ end
27
+
28
+ private
29
+
30
+ def associated_class
31
+ EditorInterface
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'client_association_methods_factory'
2
+
3
+ module Contentful
4
+ module Management
5
+ # Wrapper for Role API for usage from within Client
6
+ # @private
7
+ class ClientRoleMethodsFactory
8
+ include Contentful::Management::ClientAssociationMethodsFactory
9
+
10
+ def new(*)
11
+ fail 'Not supported'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -2,7 +2,7 @@ require_relative 'client_association_methods_factory'
2
2
 
3
3
  module Contentful
4
4
  module Management
5
- # Wrapper for ApiKey API for usage from within Client
5
+ # Wrapper for Webhook API for usage from within Client
6
6
  # @private
7
7
  class ClientWebhookMethodsFactory
8
8
  include Contentful::Management::ClientAssociationMethodsFactory
@@ -2,6 +2,7 @@ require_relative 'resource'
2
2
  require_relative 'field'
3
3
  require_relative 'validation'
4
4
  require_relative 'content_type_entry_methods_factory'
5
+ require_relative 'content_type_editor_interface_methods_factory'
5
6
  require_relative 'support'
6
7
  require_relative 'resource/all_published'
7
8
  require_relative 'resource/publisher'
@@ -141,6 +142,17 @@ module Contentful
141
142
  Contentful::Management::ContentTypeEntryMethodsFactory.new(self)
142
143
  end
143
144
 
145
+ # Use this method only in the context of content type.
146
+ # Allows you to create an editor interface.
147
+ # @see _ README for details.
148
+ #
149
+ # @private
150
+ #
151
+ # @return [Contentful::Management::ContentTypeEditorInterfaceMethodsFactory]
152
+ def editor_interface
153
+ Contentful::Management::ContentTypeEditorInterfaceMethodsFactory.new(self)
154
+ end
155
+
144
156
  # @private
145
157
  def self.fields_to_nested_properties_hash(fields)
146
158
  fields.map do |field|
@@ -0,0 +1,22 @@
1
+ require_relative 'client_editor_interface_methods_factory'
2
+ require_relative 'editor_interface'
3
+
4
+ module Contentful
5
+ module Management
6
+ # Wrapper for Editor Interface API for a specific Content Type
7
+ # @private
8
+ class ContentTypeEditorInterfaceMethodsFactory
9
+ attr_reader :content_type, :editor_interfaces_client
10
+
11
+ # @private
12
+ def initialize(content_type)
13
+ @content_type = content_type
14
+ @editor_interfaces_client = ClientEditorInterfaceMethodsFactory.new(content_type.client)
15
+ end
16
+
17
+ def default
18
+ editor_interfaces_client.default(content_type.space.id, content_type.id)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,85 @@
1
+ require_relative 'resource'
2
+
3
+ module Contentful
4
+ module Management
5
+ # Resource class for Editor Interface.
6
+ class EditorInterface
7
+ include Contentful::Management::Resource
8
+ include Contentful::Management::Resource::SystemProperties
9
+ include Contentful::Management::Resource::Refresher
10
+
11
+ property :controls, :array
12
+
13
+ # Gets the Default Editor Interface
14
+ #
15
+ # @param [String] space_id
16
+ # @param [String] content_type_id
17
+ # @param [Hash] params
18
+ # @see _ For complete option list: http://docs.contentfulcda.apiary.io/#reference/search-parameters
19
+ #
20
+ # @return [Contentful::Management::EditorInterface]
21
+ def self.default(client, space_id, content_type_id)
22
+ ClientEditorInterfaceMethodsFactory.new(client).default(space_id, content_type_id)
23
+ end
24
+
25
+ # Finds an EditorInterface.
26
+ #
27
+ # Not Supported
28
+ def self.find(*)
29
+ fail 'Not supported'
30
+ end
31
+
32
+ # Creates an EditorInterface.
33
+ #
34
+ # Not Supported
35
+ def self.create(*)
36
+ fail 'Not supported'
37
+ end
38
+
39
+ # @private
40
+ def self.create_attributes(_client, attributes)
41
+ { 'controls' => attributes.fetch(:controls) }
42
+ end
43
+
44
+ # @private
45
+ def self.build_endpoint(endpoint_options)
46
+ space_id = endpoint_options.fetch(:space_id)
47
+ content_type_id = endpoint_options.fetch(:content_type_id)
48
+
49
+ "/#{space_id}/content_types/#{content_type_id}/editor_interface"
50
+ end
51
+
52
+ # Updates an Editor Interface
53
+ #
54
+ # @param [Hash] attributes
55
+ # @option attributes [Array<Hash>] :controls
56
+ #
57
+ # @return [Contentful::Management::EditorInterface]
58
+ def update(attributes)
59
+ ResourceRequester.new(client, self.class).update(
60
+ self,
61
+ { space_id: space.id, content_type_id: content_type.id, editor_id: id },
62
+ { 'controls' => attributes.fetch(:controls) },
63
+ version: sys[:version]
64
+ )
65
+ end
66
+
67
+ # Destroys an EditorInterface.
68
+ #
69
+ # Not Supported
70
+ def destroy
71
+ fail 'Not supported'
72
+ end
73
+
74
+ protected
75
+
76
+ def refresh_find
77
+ self.class.default(client, space.id, content_type.id)
78
+ end
79
+
80
+ def query_attributes(attributes)
81
+ attributes.each_with_object({}) { |(k, v), result| result[k.to_sym] = v }
82
+ end
83
+ end
84
+ end
85
+ end
@@ -15,6 +15,7 @@ module Contentful
15
15
  property :localized, :boolean
16
16
  property :validations, Validation
17
17
  property :disabled, :boolean
18
+ property :omitted, :boolean
18
19
 
19
20
  # Takes a field object of content type
20
21
  # Merges existing properties, items and validations of field with new one
@@ -13,6 +13,7 @@ module Contentful
13
13
  # @option parameters [String] :content_type
14
14
  # @option parameters [Integer] :limit
15
15
  # @option parameters [Integer] :skip
16
+ # @deprecated This call will be soon removed from the API except for Content Types
16
17
  #
17
18
  # @return [Contentful::Management::Array<Contentful::Management::Resource>]
18
19
  def all_published(client, space_id, parameters = {})
@@ -6,9 +6,13 @@ module Contentful
6
6
  # Reload an object
7
7
  # Updates the current version of the object to the version on the system
8
8
  def reload
9
- self_class = self.class
10
- resource = self.is_a?(Space) ? self_class.find(client, id) : self_class.find(client, space.id, id)
11
- refresh_data(resource) if resource.is_a? self_class
9
+ resource = refresh_find
10
+ refresh_data(resource) if resource.is_a? self.class
11
+ end
12
+
13
+ # @private
14
+ def refresh_find
15
+ self.class.find(client, space.id, id)
12
16
  end
13
17
 
14
18
  # @private
@@ -10,6 +10,8 @@ require_relative 'asset'
10
10
  require_relative 'webhook'
11
11
  require_relative 'api_key'
12
12
  require_relative 'locale'
13
+ require_relative 'role'
14
+ require_relative 'editor_interface'
13
15
 
14
16
  module Contentful
15
17
  module Management
@@ -27,7 +29,9 @@ module Contentful
27
29
  'Link' => Contentful::Management::Link,
28
30
  'WebhookDefinition' => Contentful::Management::Webhook,
29
31
  'ApiKey' => Contentful::Management::ApiKey,
30
- 'Locale' => Contentful::Management::Locale
32
+ 'Locale' => Contentful::Management::Locale,
33
+ 'Role' => Contentful::Management::Role,
34
+ 'EditorInterface' => Contentful::Management::EditorInterface
31
35
  }
32
36
  # Default Entry Mapping
33
37
  # @see _ README for more information on Entry Mapping
@@ -0,0 +1,33 @@
1
+ require_relative 'resource'
2
+
3
+ module Contentful
4
+ module Management
5
+ # Resource class for Role.
6
+ class Role
7
+ include Contentful::Management::Resource
8
+ include Contentful::Management::Resource::SystemProperties
9
+ include Contentful::Management::Resource::Refresher
10
+
11
+ property :name, :string
12
+ property :description, :string
13
+ property :permissions, :hash
14
+ property :policies, :array
15
+
16
+ # @private
17
+ def self.create_attributes(_client, attributes)
18
+ {
19
+ 'name' => attributes.fetch(:name),
20
+ 'description' => attributes.fetch(:description),
21
+ 'permissions' => attributes.fetch(:permissions),
22
+ 'policies' => attributes.fetch(:policies)
23
+ }
24
+ end
25
+
26
+ protected
27
+
28
+ def query_attributes(attributes)
29
+ attributes.each_with_object({}) { |(k, v), result| result[k.to_sym] = v }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -9,6 +9,10 @@ require_relative 'entry'
9
9
  require_relative 'space_entry_methods_factory'
10
10
  require_relative 'webhook'
11
11
  require_relative 'space_webhook_methods_factory'
12
+ require_relative 'role'
13
+ require_relative 'space_role_methods_factory'
14
+ require_relative 'editor_interface'
15
+ require_relative 'space_editor_interface_methods_factory'
12
16
  require_relative 'api_key'
13
17
  require_relative 'space_api_key_methods_factory'
14
18
 
@@ -145,6 +149,24 @@ module Contentful
145
149
  SpaceLocaleMethodsFactory.new(self)
146
150
  end
147
151
 
152
+ # Allows manipulation of roles in context of the current space
153
+ # Allows listing all roles of space, creating new and finding one by id.
154
+ # @see _ README for details.
155
+ #
156
+ # @return [Contentful::Management::SpaceRoleMethodsFactory]
157
+ def roles
158
+ SpaceRoleMethodsFactory.new(self)
159
+ end
160
+
161
+ # Allows manipulation of editor interfaces in context of the current space
162
+ # Allows listing all editor interfaces of space, creating new and finding one by id.
163
+ # @see _ README for details.
164
+ #
165
+ # @return [Contentful::Management::SpaceEditorInterfaceMethodsFactory]
166
+ def editor_interfaces
167
+ SpaceEditorInterfaceMethodsFactory.new(self)
168
+ end
169
+
148
170
  # Allows manipulation of assets in context of the current space
149
171
  # Allows listing all assets of space, creating new and finding one by id.
150
172
  # @see _ README for details.
@@ -188,6 +210,12 @@ module Contentful
188
210
  return locale.code unless locale.nil?
189
211
  @default_locale
190
212
  end
213
+
214
+ protected
215
+
216
+ def refresh_find
217
+ self.class.find(client, id)
218
+ end
191
219
  end
192
220
  end
193
221
  end
@@ -2,6 +2,7 @@ module Contentful
2
2
  module Management
3
3
  # Wrapper for /public API for usage from within Space Wrapper Classes
4
4
  # @private
5
+ # @deprecated This call will be soon removed from the API except for Content Types
5
6
  module SpaceAssociationAllPublishedMethodsFactory
6
7
  def all_published(params = {})
7
8
  associated_class.all_published(space.client, space.id, params)
@@ -0,0 +1,21 @@
1
+ require_relative 'client_editor_interface_methods_factory'
2
+ require_relative 'editor_interface'
3
+
4
+ module Contentful
5
+ module Management
6
+ # Wrapper for EditorInterface API for usage from within Space
7
+ # @private
8
+ class SpaceEditorInterfaceMethodsFactory
9
+ attr_reader :space, :editor_interfaces_client
10
+
11
+ def initialize(space)
12
+ @space = space
13
+ @editor_interfaces_client = ClientEditorInterfaceMethodsFactory.new(space.client)
14
+ end
15
+
16
+ def default(content_type_id)
17
+ editor_interfaces_client.default(space.id, content_type_id)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'space_association_methods_factory'
2
+
3
+ module Contentful
4
+ module Management
5
+ # Wrapper for Role API for usage from within Space
6
+ # @private
7
+ class SpaceRoleMethodsFactory
8
+ include Contentful::Management::SpaceAssociationMethodsFactory
9
+
10
+ def new
11
+ fail 'Not supported'
12
+ end
13
+ end
14
+ end
15
+ end