contentful-management 3.1.0 → 3.4.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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +23 -0
  3. data/CHANGELOG.md +10 -0
  4. data/README.md +45 -1
  5. data/lib/contentful/management/asset.rb +2 -2
  6. data/lib/contentful/management/client.rb +10 -0
  7. data/lib/contentful/management/client_tag_methods_factory.rb +11 -0
  8. data/lib/contentful/management/editor_interface.rb +12 -4
  9. data/lib/contentful/management/entry.rb +3 -3
  10. data/lib/contentful/management/environment.rb +10 -0
  11. data/lib/contentful/management/environment_tag_methods_factory.rb +11 -0
  12. data/lib/contentful/management/organization_user_methods_factory.rb +2 -2
  13. data/lib/contentful/management/resource/refresher.rb +1 -0
  14. data/lib/contentful/management/resource_requester.rb +2 -2
  15. data/lib/contentful/management/space_user_methods_factory.rb +2 -2
  16. data/lib/contentful/management/tag.rb +27 -0
  17. data/lib/contentful/management/version.rb +1 -1
  18. data/spec/fixtures/vcr_cassettes/editor_interfaces/update_sidebar.yml +553 -0
  19. data/spec/fixtures/vcr_cassettes/environment/tag_proxy.yml +658 -0
  20. data/spec/fixtures/vcr_cassettes/tag/add_tag_to_asset.yml +456 -0
  21. data/spec/fixtures/vcr_cassettes/tag/add_tag_to_entry.yml +315 -0
  22. data/spec/fixtures/vcr_cassettes/tag/all.yml +252 -0
  23. data/spec/fixtures/vcr_cassettes/tag/create_asset_with_tags.yml +147 -0
  24. data/spec/fixtures/vcr_cassettes/tag/create_entry_with_tags.yml +293 -0
  25. data/spec/fixtures/vcr_cassettes/tag/create_visibility_private.yml +125 -0
  26. data/spec/fixtures/vcr_cassettes/tag/create_visibility_public.yml +125 -0
  27. data/spec/fixtures/vcr_cassettes/tag/destroy.yml +208 -0
  28. data/spec/fixtures/vcr_cassettes/tag/destroy_referenced.yml +226 -0
  29. data/spec/fixtures/vcr_cassettes/tag/find.yml +125 -0
  30. data/spec/fixtures/vcr_cassettes/tag/not_found.yml +98 -0
  31. data/spec/fixtures/vcr_cassettes/tag/remove_tag_from_asset.yml +456 -0
  32. data/spec/fixtures/vcr_cassettes/tag/remove_tag_from_entry.yml +315 -0
  33. data/spec/fixtures/vcr_cassettes/tag/update.yml +251 -0
  34. data/spec/lib/contentful/management/editor_interface_spec.rb +30 -0
  35. data/spec/lib/contentful/management/environment_spec.rb +12 -0
  36. data/spec/lib/contentful/management/tag_spec.rb +186 -0
  37. metadata +43 -7
  38. data/.travis.yml +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1537c2cc75f3daacb31c8764f6b7464ed762f662df0437a9a1cb70808f7f5275
4
- data.tar.gz: a7613ed0ba9808ecb6636f3bf7ceb20c45ee0c3ef803e7e735f9c9583c18a0b4
3
+ metadata.gz: 6c115843f4cb0a16069a1a41ada3cc3661f274ab5b2e53a3b51f085f30bd7377
4
+ data.tar.gz: 2c9c760b683b0f2174b24d1d40473a90dc1d001f6da8fccd32c70e5f511e1633
5
5
  SHA512:
6
- metadata.gz: 84a0848640c0e345695f76357e1154a83d591aa93698733cc08edd20f719d03121e07dfd08a4b42b274441b992618ddafc9ecab6f19d8ece3a2df6948cffa4d5
7
- data.tar.gz: b0f25603b7e59daaf240ffa5770d50fa5b701c47faf8911be5b8a94099428b4eeb94aceed2cce832c071d5116e1cc9f2e027e1a47beab82356a0b6f9b24a2f05
6
+ metadata.gz: be21b3435d4a8c17661f3db6f31e17a799962ed6cb0acac6edfdeee6f6242283cbd610f0b3af9e6929148b3a0c9fb39a9c3f13fc7f1f6d7d45ee56f138ba8a99
7
+ data.tar.gz: a8cabfecc97f19740953a33dd92e6d5bc44479f4b393359d614d85c23d7a85f37cba0cc1de80c628a47598006a0154d9ba8c9119d85765e9a32751cefce463c1
@@ -0,0 +1,23 @@
1
+ version: 2.1
2
+
3
+ jobs:
4
+ test_and_lint:
5
+ parameters:
6
+ ruby-version:
7
+ type: string
8
+ docker:
9
+ - image: cimg/ruby:<< parameters.ruby-version >>
10
+ steps:
11
+ - checkout
12
+ - run: gem install bundler
13
+ - run: bundle install
14
+ - run: bundle exec rake rspec_rubocop
15
+
16
+ workflows:
17
+ version: 2
18
+ workflow:
19
+ jobs:
20
+ - test_and_lint:
21
+ matrix:
22
+ parameters:
23
+ ruby-version: ["2.6", "2.7", "3.0"]
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## Master
4
4
 
5
+ ## 3.4.0
6
+ * Changed CI/CD vendor
7
+ * Added support for Tags API
8
+
9
+ ## 3.3.0
10
+ * Added getter/setter for EditorInterface#sidebar
11
+
12
+ ## 3.2.0
13
+ * Added support for parameters on Users API. [#227](https://github.com/contentful/contentful-management.rb/pull/227)
14
+
5
15
  ## 3.1.0
6
16
  ### Added
7
17
  * Added read support for Users API.
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Contentful::Management
2
- [![Gem Version](https://badge.fury.io/rb/contentful-management.svg)](http://badge.fury.io/rb/contentful-management) [![Build Status](https://travis-ci.org/contentful/contentful-management.rb.svg)](https://travis-ci.org/contentful/contentful-management.rb)
2
+ [![Gem Version](https://badge.fury.io/rb/contentful-management.svg)](http://badge.fury.io/rb/contentful-management) [![CircleCI](https://circleci.com/gh/contentful/contentful-management.rb/tree/master.svg?style=svg)](https://app.circleci.com/pipelines/github/contentful/contentful-management.rb?branch=master)
3
3
 
4
4
  Ruby client for the Contentful Content Management API.
5
5
 
@@ -640,6 +640,50 @@ Destroying a locale:
640
640
  blog_post_locale.destroy
641
641
  ```
642
642
 
643
+ ### Tags
644
+
645
+ Retrieving all tags from the environment:
646
+
647
+ ```ruby
648
+ tags = environment.tags.all
649
+ ```
650
+
651
+ Retrieving one tag by ID from the environment:
652
+
653
+ ```ruby
654
+ tag = environment.tags.find(tag_id)
655
+ ```
656
+
657
+ Creating a tag:
658
+
659
+ ```ruby
660
+ environment.tags.create(name: 'tag name', id: 'tagID')
661
+ ```
662
+
663
+ Updating a tag:
664
+
665
+ ```ruby
666
+ tag.update(name: 'new name')
667
+ ```
668
+
669
+ Destroying a tag:
670
+
671
+ ```ruby
672
+ tag.destroy
673
+ ```
674
+
675
+ Tagging an entry:
676
+
677
+ ```ruby
678
+ entry.update(_metadata: {"tags": [{ "sys": { "type": "Link", "linkType": "Tag", "id": "fooTag" } }]})
679
+ ```
680
+
681
+ Tagging an asset:
682
+
683
+ ```ruby
684
+ asset.update(_metadata: {"tags": [{ "sys": { "type": "Link", "linkType": "Tag", "id": "fooTag" } }]})
685
+ ```
686
+
643
687
  ### Roles
644
688
 
645
689
  Retrieving all roles from the space:
@@ -40,7 +40,7 @@ module Contentful
40
40
  fields[:description] = { locale => attributes[:description] } if attributes[:description]
41
41
  fields[:file] = { locale => attributes[:file].properties } if attributes[:file]
42
42
 
43
- { fields: fields }
43
+ { fields: fields, metadata: attributes[:_metadata] }
44
44
  end
45
45
 
46
46
  # @private
@@ -122,7 +122,7 @@ module Contentful
122
122
  self.description = attributes[:description] || description
123
123
  self.file = attributes[:file] || file
124
124
 
125
- { fields: fields_for_query }
125
+ { fields: fields_for_query, metadata: attributes[:_metadata] }
126
126
  end
127
127
  end
128
128
  end
@@ -10,6 +10,7 @@ require 'contentful/management/version'
10
10
  require 'contentful/management/response'
11
11
  require 'contentful/management/resource_builder'
12
12
 
13
+ require 'contentful/management/client_tag_methods_factory'
13
14
  require 'contentful/management/client_role_methods_factory'
14
15
  require 'contentful/management/client_user_methods_factory'
15
16
  require 'contentful/management/client_space_methods_factory'
@@ -194,6 +195,15 @@ module Contentful
194
195
  ClientAssetMethodsFactory.new(self, space_id, environment_id)
195
196
  end
196
197
 
198
+ # Allows manipulation of tags in context of the current client
199
+ # Allows listing all tags for client, creating new and finding one by ID.
200
+ # @see _ README for details.
201
+ #
202
+ # @return [Contentful::Management::ClientTagMethodsFactory]
203
+ def tags(space_id, environment_id)
204
+ ClientTagMethodsFactory.new(self, space_id, environment_id)
205
+ end
206
+
197
207
  # Allows manipulation of content types in context of the current client
198
208
  # Allows listing all content types for client, creating new and finding one by ID.
199
209
  # @see _ README for details.
@@ -0,0 +1,11 @@
1
+ require_relative 'client_association_methods_factory'
2
+
3
+ module Contentful
4
+ module Management
5
+ # Wrapper for Tag API for usage from within Client
6
+ # @private
7
+ class ClientTagMethodsFactory
8
+ include Contentful::Management::ClientAssociationMethodsFactory
9
+ end
10
+ end
11
+ end
@@ -11,6 +11,7 @@ module Contentful
11
11
  include Contentful::Management::Resource::EnvironmentAware
12
12
 
13
13
  property :controls, :array
14
+ property :sidebar, :array
14
15
 
15
16
  # Gets the Default Editor Interface
16
17
  #
@@ -39,7 +40,10 @@ module Contentful
39
40
 
40
41
  # @private
41
42
  def self.create_attributes(_client, attributes)
42
- { 'controls' => attributes.fetch(:controls) }
43
+ {
44
+ 'controls' => attributes.fetch(:controls),
45
+ 'sidebar' => attributes.fetch(:sidebar)
46
+ }
43
47
  end
44
48
 
45
49
  # @private
@@ -54,7 +58,7 @@ module Contentful
54
58
  # Updates an Editor Interface
55
59
  #
56
60
  # @param [Hash] attributes
57
- # @option attributes [Array<Hash>] :controls
61
+ # @option attributes [Array<Hash>] :controls, :sidebar
58
62
  #
59
63
  # @return [Contentful::Management::EditorInterface]
60
64
  def update(attributes)
@@ -66,7 +70,10 @@ module Contentful
66
70
  content_type_id: content_type.id,
67
71
  editor_id: id
68
72
  },
69
- { 'controls' => attributes[:controls] || controls },
73
+ {
74
+ 'controls' => attributes[:controls] || controls,
75
+ 'sidebar' => attributes[:sidebar] || sidebar
76
+ },
70
77
  version: sys[:version]
71
78
  )
72
79
  end
@@ -86,7 +93,8 @@ module Contentful
86
93
 
87
94
  def query_attributes(attributes)
88
95
  {
89
- controls: controls
96
+ controls: controls,
97
+ sidebar: sidebar
90
98
  }.merge(
91
99
  attributes.each_with_object({}) { |(k, v), result| result[k.to_sym] = v }
92
100
  )
@@ -58,8 +58,7 @@ module Contentful
58
58
  end
59
59
 
60
60
  client.register_dynamic_entry(content_type.id, DynamicEntry.create(content_type, client))
61
-
62
- { fields: fields_for_create }
61
+ { fields: fields_for_create, metadata: attributes[:_metadata] }
63
62
  end
64
63
 
65
64
  # @private
@@ -183,7 +182,8 @@ module Contentful
183
182
  protected
184
183
 
185
184
  def query_attributes(attributes)
186
- { fields: Contentful::Management::Support.deep_hash_merge(fields_for_query, fields_from_attributes(attributes)) }
185
+ { metadata: attributes.delete(:_metadata),
186
+ fields: Contentful::Management::Support.deep_hash_merge(fields_for_query, fields_from_attributes(attributes)) }
187
187
  end
188
188
 
189
189
  private
@@ -4,6 +4,7 @@ require_relative 'environment_locale_methods_factory'
4
4
  require_relative 'environment_content_type_methods_factory'
5
5
  require_relative 'environment_ui_extension_methods_factory'
6
6
  require_relative 'environment_editor_interface_methods_factory'
7
+ require_relative 'environment_tag_methods_factory'
7
8
 
8
9
  module Contentful
9
10
  module Management
@@ -121,6 +122,15 @@ module Contentful
121
122
  EnvironmentEditorInterfaceMethodsFactory.new(self)
122
123
  end
123
124
 
125
+ # Allows manipulation of tags in context of the current environment
126
+ # Allows listing all tags for the current environment, creating new and finding one by ID.
127
+ # @see _ README for details.
128
+ #
129
+ # @return [Contentful::Management::EnvironmentTagMethodsFactory]
130
+ def tags
131
+ EnvironmentTagMethodsFactory.new(self)
132
+ end
133
+
124
134
  # Gets the environment ID
125
135
  def environment_id
126
136
  id
@@ -0,0 +1,11 @@
1
+ require_relative 'environment_association_methods_factory'
2
+
3
+ module Contentful
4
+ module Management
5
+ # Wrapper for Tag API for usage from within Environment
6
+ # @private
7
+ class EnvironmentTagMethodsFactory
8
+ include Contentful::Management::EnvironmentAssociationMethodsFactory
9
+ end
10
+ end
11
+ end
@@ -14,8 +14,8 @@ module Contentful
14
14
  User.find(client, nil, nil, id, @organization_id)
15
15
  end
16
16
 
17
- def all
18
- User.all(client, nil, nil, {}, @organization_id)
17
+ def all(params = {})
18
+ User.all(client, nil, nil, params, @organization_id)
19
19
  end
20
20
  end
21
21
  end
@@ -24,6 +24,7 @@ module Contentful
24
24
  @properties = resource.instance_variable_get(:@properties)
25
25
  @fields = resource.instance_variable_get(:@fields)
26
26
  @sys = resource.instance_variable_get(:@sys).merge(locale: locale)
27
+ @_metadata = resource.instance_variable_get(:@_metadata)
27
28
  self
28
29
  end
29
30
  end
@@ -38,8 +38,8 @@ module Contentful
38
38
  object.refresh_data(put(endpoint_options, attributes, headers, object))
39
39
  end
40
40
 
41
- def destroy(endpoint_options = {})
42
- delete(endpoint_options)
41
+ def destroy(endpoint_options = {}, attributes = {}, headers = {})
42
+ delete(endpoint_options, attributes, headers)
43
43
  end
44
44
 
45
45
  def archive(object, endpoint_options = {}, headers = {})
@@ -15,8 +15,8 @@ module Contentful
15
15
  User.find(space.client, space.id, nil, id)
16
16
  end
17
17
 
18
- def all
19
- User.all(space.client, space.id)
18
+ def all(params = {})
19
+ User.all(space.client, space.id, nil, params, nil)
20
20
  end
21
21
  end
22
22
  end
@@ -1,4 +1,5 @@
1
1
  require_relative 'resource'
2
+ require_relative 'resource/environment_aware'
2
3
 
3
4
  module Contentful
4
5
  module Management
@@ -6,9 +7,35 @@ module Contentful
6
7
  # https://www.contentful.com/developers/docs/references/content-management-api/#/reference/content-tags
7
8
  class Tag
8
9
  include Contentful::Management::Resource
10
+ include Contentful::Management::Resource::Refresher
9
11
  include Contentful::Management::Resource::SystemProperties
12
+ include Contentful::Management::Resource::EnvironmentAware
10
13
 
11
14
  property :name
15
+
16
+ # @private
17
+ def self.create_attributes(_client, attributes)
18
+ return {} if attributes.nil? || attributes.empty?
19
+
20
+ {
21
+ 'name' => attributes.fetch(:name),
22
+ 'sys' => {
23
+ 'visibility' => attributes.fetch(:visibility, 'private'),
24
+ 'id' => attributes.fetch(:id),
25
+ 'type' => 'Tag'
26
+ }
27
+ }
28
+ end
29
+
30
+ def destroy
31
+ ResourceRequester.new(client, self.class).destroy(
32
+ { space_id: space.id,
33
+ environment_id: environment_id,
34
+ resource_id: id },
35
+ {},
36
+ version: sys[:version]
37
+ )
38
+ end
12
39
  end
13
40
  end
14
41
  end
@@ -3,6 +3,6 @@ module Contentful
3
3
  # Management Namespace
4
4
  module Management
5
5
  # Gem Version
6
- VERSION = '3.1.0'.freeze
6
+ VERSION = '3.4.0'.freeze
7
7
  end
8
8
  end