contentful-management 3.3.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 (33) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +23 -0
  3. data/CHANGELOG.md +4 -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/entry.rb +3 -3
  9. data/lib/contentful/management/environment.rb +10 -0
  10. data/lib/contentful/management/environment_tag_methods_factory.rb +11 -0
  11. data/lib/contentful/management/resource/refresher.rb +1 -0
  12. data/lib/contentful/management/resource_requester.rb +2 -2
  13. data/lib/contentful/management/tag.rb +27 -0
  14. data/lib/contentful/management/version.rb +1 -1
  15. data/spec/fixtures/vcr_cassettes/environment/tag_proxy.yml +658 -0
  16. data/spec/fixtures/vcr_cassettes/tag/add_tag_to_asset.yml +456 -0
  17. data/spec/fixtures/vcr_cassettes/tag/add_tag_to_entry.yml +315 -0
  18. data/spec/fixtures/vcr_cassettes/tag/all.yml +252 -0
  19. data/spec/fixtures/vcr_cassettes/tag/create_asset_with_tags.yml +147 -0
  20. data/spec/fixtures/vcr_cassettes/tag/create_entry_with_tags.yml +293 -0
  21. data/spec/fixtures/vcr_cassettes/tag/create_visibility_private.yml +125 -0
  22. data/spec/fixtures/vcr_cassettes/tag/create_visibility_public.yml +125 -0
  23. data/spec/fixtures/vcr_cassettes/tag/destroy.yml +208 -0
  24. data/spec/fixtures/vcr_cassettes/tag/destroy_referenced.yml +226 -0
  25. data/spec/fixtures/vcr_cassettes/tag/find.yml +125 -0
  26. data/spec/fixtures/vcr_cassettes/tag/not_found.yml +98 -0
  27. data/spec/fixtures/vcr_cassettes/tag/remove_tag_from_asset.yml +456 -0
  28. data/spec/fixtures/vcr_cassettes/tag/remove_tag_from_entry.yml +315 -0
  29. data/spec/fixtures/vcr_cassettes/tag/update.yml +251 -0
  30. data/spec/lib/contentful/management/environment_spec.rb +12 -0
  31. data/spec/lib/contentful/management/tag_spec.rb +186 -0
  32. metadata +41 -7
  33. data/.travis.yml +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df8e043eb2757aa5fc7ac3a679a7f7ac945869b350920f660586079e954fb540
4
- data.tar.gz: 8e58ce2d681d748c68987a7db23d7bbe846feea6c9b93f35be369a84e9b84bb4
3
+ metadata.gz: 6c115843f4cb0a16069a1a41ada3cc3661f274ab5b2e53a3b51f085f30bd7377
4
+ data.tar.gz: 2c9c760b683b0f2174b24d1d40473a90dc1d001f6da8fccd32c70e5f511e1633
5
5
  SHA512:
6
- metadata.gz: c19c035a3ab9a8dbb85c2e8679c15bfa83b7499c4e83927996536f595847d1201c636561d63a300bf2d8edbee507e57b020a56ac0b512ee290af121fecfe9107
7
- data.tar.gz: 91ed42d0f1356e1d0bc7076566587b6a54870472c16391272fb8b0cec7b834539b19682f3e42a3c232667fe97506cbbd8d0f9e25f29ab7368774d470b3afa5e0
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,10 @@
2
2
 
3
3
  ## Master
4
4
 
5
+ ## 3.4.0
6
+ * Changed CI/CD vendor
7
+ * Added support for Tags API
8
+
5
9
  ## 3.3.0
6
10
  * Added getter/setter for EditorInterface#sidebar
7
11
 
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
@@ -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
@@ -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 = {})
@@ -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.3.0'.freeze
6
+ VERSION = '3.4.0'.freeze
7
7
  end
8
8
  end