contentful-management 3.2.0 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
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 +16 -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/resource/refresher.rb +1 -0
  13. data/lib/contentful/management/resource_requester.rb +2 -2
  14. data/lib/contentful/management/tag.rb +27 -0
  15. data/lib/contentful/management/version.rb +1 -1
  16. data/spec/fixtures/vcr_cassettes/editor_interfaces/update_sidebar.yml +553 -0
  17. data/spec/fixtures/vcr_cassettes/entry/references.yml +496 -0
  18. data/spec/fixtures/vcr_cassettes/environment/tag_proxy.yml +658 -0
  19. data/spec/fixtures/vcr_cassettes/tag/add_tag_to_asset.yml +456 -0
  20. data/spec/fixtures/vcr_cassettes/tag/add_tag_to_entry.yml +315 -0
  21. data/spec/fixtures/vcr_cassettes/tag/all.yml +252 -0
  22. data/spec/fixtures/vcr_cassettes/tag/create_asset_with_tags.yml +147 -0
  23. data/spec/fixtures/vcr_cassettes/tag/create_entry_with_tags.yml +293 -0
  24. data/spec/fixtures/vcr_cassettes/tag/create_visibility_private.yml +125 -0
  25. data/spec/fixtures/vcr_cassettes/tag/create_visibility_public.yml +125 -0
  26. data/spec/fixtures/vcr_cassettes/tag/destroy.yml +208 -0
  27. data/spec/fixtures/vcr_cassettes/tag/destroy_referenced.yml +226 -0
  28. data/spec/fixtures/vcr_cassettes/tag/find.yml +125 -0
  29. data/spec/fixtures/vcr_cassettes/tag/not_found.yml +98 -0
  30. data/spec/fixtures/vcr_cassettes/tag/remove_tag_from_asset.yml +456 -0
  31. data/spec/fixtures/vcr_cassettes/tag/remove_tag_from_entry.yml +315 -0
  32. data/spec/fixtures/vcr_cassettes/tag/update.yml +251 -0
  33. data/spec/lib/contentful/management/editor_interface_spec.rb +30 -0
  34. data/spec/lib/contentful/management/entry_spec.rb +11 -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 +45 -7
  38. data/.travis.yml +0 -12
@@ -0,0 +1,186 @@
1
+ require 'spec_helper'
2
+ require 'contentful/management/space'
3
+ require 'contentful/management/client'
4
+
5
+ module Contentful
6
+ module Management
7
+ describe Tag do
8
+ let(:token) { ENV.fetch('CF_TEST_CMA_TOKEN', '<ACCESS_TOKEN>') }
9
+ let(:space_id) { 'o4h6g9w3pooi' }
10
+ let(:tag_id) { 'fooTag' }
11
+
12
+ let!(:client) { Contentful::Management::Client.new(token) }
13
+
14
+ subject { client.tags(space_id, 'master') }
15
+
16
+ describe '.all' do
17
+ it 'class method also works' do
18
+ vcr('tag/all') { expect(Contentful::Management::Tag.all(client, 'o4h6g9w3pooi', 'master')).to be_kind_of Contentful::Management::Array }
19
+ end
20
+ it 'returns a Contentful::Array' do
21
+ vcr('tag/all') { expect(described_class.all(client, 'o4h6g9w3pooi', 'master')).to be_kind_of Contentful::Management::Array }
22
+ end
23
+ it 'builds a Contentful::Management::Tag object' do
24
+ vcr('tag/all') { expect(described_class.all(client, 'o4h6g9w3pooi', 'master').first).to be_kind_of Contentful::Management::Tag }
25
+ end
26
+ end
27
+
28
+ describe '.find' do
29
+ it 'class method also works' do
30
+ vcr('tag/find') { expect(Contentful::Management::Tag.find(client, space_id, 'master', tag_id)).to be_kind_of Contentful::Management::Tag }
31
+ end
32
+ it 'returns a Contentful::Management::Tag' do
33
+ vcr('tag/find') { expect(subject.find(tag_id)).to be_kind_of Contentful::Management::Tag }
34
+ end
35
+ it 'returns the tag for a given tag id' do
36
+ vcr('tag/find') do
37
+ tag = subject.find(tag_id)
38
+ expect(tag.id).to eql tag_id
39
+ expect(tag.name).to eql 'Foo Tag'
40
+ end
41
+ end
42
+ it 'returns an error when tag does not exists' do
43
+ vcr('tag/not_found') do
44
+ result = subject.find('not_exist')
45
+ expect(result).to be_kind_of Contentful::Management::NotFound
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '.create' do
51
+ it "create tag with default 'private' visibility" do
52
+ vcr('tag/create_visibility_private') do
53
+ tag = client.tags(space_id, 'master').create(name: 'test private', id: 'testPrivate')
54
+ expect(tag.name).to eql 'test private'
55
+ expect(tag.id).to eql 'testPrivate'
56
+ expect(tag.sys[:visibility]).to eql 'private'
57
+ end
58
+ end
59
+
60
+ it "create tag with 'public' visibility" do
61
+ vcr('tag/create_visibility_public') do
62
+ tag = client.tags(space_id, 'master').create(name: 'test public', id: 'testPublic', visibility: 'public')
63
+ expect(tag.name).to eql 'test public'
64
+ expect(tag.id).to eql 'testPublic'
65
+ expect(tag.sys[:visibility]).to eql 'public'
66
+ end
67
+ end
68
+ end
69
+
70
+ describe '.update' do
71
+ it 'updates tag name' do
72
+ vcr('tag/update') do
73
+ tag = subject.find(tag_id)
74
+ tag.update(name: 'updated tag')
75
+ expect(tag.name).to eq 'updated tag'
76
+ end
77
+ end
78
+ end
79
+
80
+ describe '#destroy' do
81
+ it 'returns validation error when tag is referenced by another entity' do
82
+ vcr('tag/destroy_referenced') do
83
+ result = subject.find('icon').destroy
84
+ message = "HTTP status code: 422 Unprocessable Entity\n"\
85
+ "Message: Validation error\n"\
86
+ "Details: \n"\
87
+ "\t* Name: reference - Path: '' - Value: ''\n"\
88
+ "Request ID: 727a53d1-e679-4654-8bec-f955da1334e9"
89
+
90
+ expect(result).to be_kind_of Contentful::Management::Error
91
+ expect(result.message).to eq message
92
+ end
93
+ end
94
+
95
+ it 'returns true when content type is not activated' do
96
+ vcr('tag/destroy') do
97
+ result = subject.find('randomTag').destroy
98
+ expect(result).to eql true
99
+ end
100
+ end
101
+ end
102
+
103
+ describe 'tag an entry' do
104
+ it 'creates entry with tags' do
105
+ vcr('tag/create_entry_with_tags') do
106
+ content_type = client.content_types(space_id, 'master').find('simple')
107
+ entry = client.entries(space_id, 'master').create(
108
+ content_type,
109
+ title: 'Entry title',
110
+ _metadata: { "tags": [{ "sys": { "type": "Link", "linkType": "Tag", "id": "icon" } }] }
111
+ )
112
+
113
+ expect(entry._metadata[:tags].count).to eq(1)
114
+ expect(entry._metadata[:tags].first.id).to eq('icon')
115
+ end
116
+ end
117
+
118
+ it 'add tags to an entry' do
119
+ vcr('tag/add_tag_to_entry') do
120
+ entry = client.entries(space_id, 'master').find('28spH12WTOl0xUQeC4AL1a')
121
+ expect(entry._metadata[:tags]).to be_empty
122
+
123
+ result = entry.update(_metadata: { "tags": [{ "sys": { "type": "Link", "linkType": "Tag", "id": "icon" } }] })
124
+ expect(result).to be_kind_of Contentful::Management::Entry
125
+ expect(result._metadata[:tags].count).to eq(1)
126
+ expect(result._metadata[:tags].first.id).to eq('icon')
127
+ end
128
+ end
129
+
130
+ it 'remove tags from an entry' do
131
+ vcr('tag/remove_tag_from_entry') do
132
+ entry = client.entries(space_id, 'master').find('28spH12WTOl0xUQeC4AL1a')
133
+ expect(entry._metadata[:tags]).not_to be_empty
134
+
135
+ entry.update(_metadata: { "tags": [] })
136
+ expect(entry._metadata[:tags]).to be_empty
137
+ end
138
+ end
139
+ end
140
+
141
+ describe 'tag an asset' do
142
+ it 'creates asset with tags' do
143
+ vcr('tag/create_asset_with_tags') do
144
+ file = Contentful::Management::File.new
145
+ file.properties[:contentType] = 'image/jpeg'
146
+ file.properties[:fileName] = 'pic1.jpg'
147
+ file.properties[:upload] = 'https://upload.wikimedia.org/wikipedia/commons/c/c7/Gasometer_Berlin_Sch%C3%B6neberg_2011.jpg'
148
+
149
+ asset = client.assets(space_id, 'master').create(
150
+ title: 'Asset title',
151
+ file: file,
152
+ _metadata: { "tags": [{ "sys": { "type": "Link", "linkType": "Tag", "id": "icon" } }] }
153
+ )
154
+
155
+ expect(asset._metadata[:tags].count).to eq(1)
156
+ expect(asset._metadata[:tags].first.id).to eq('icon')
157
+ end
158
+ end
159
+
160
+ it 'add tags to an asset' do
161
+ vcr('tag/add_tag_to_asset') do
162
+ environment = client.environments(space_id).find('master')
163
+ asset = environment.assets.find('686aLBcjj1f47uFWxrepj6')
164
+ expect(asset._metadata[:tags]).to be_empty
165
+
166
+ result = asset.update(_metadata: { "tags": [{ "sys": { "type": "Link", "linkType": "Tag", "id": "icon" } }] })
167
+ expect(result).to be_kind_of Contentful::Management::Asset
168
+ expect(result._metadata[:tags].count).to eq(1)
169
+ expect(result._metadata[:tags].first.id).to eq('icon')
170
+ end
171
+ end
172
+
173
+ it 'remove tags from an asset' do
174
+ vcr('tag/remove_tag_from_asset') do
175
+ environment = client.environments(space_id).find('master')
176
+ asset = environment.assets.find('686aLBcjj1f47uFWxrepj6')
177
+ expect(asset._metadata[:tags]).not_to be_empty
178
+
179
+ asset.update(_metadata: { "tags": [] })
180
+ expect(asset._metadata[:tags]).to be_empty
181
+ end
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentful-management
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Protas
8
8
  - Tomasz Warkocki
9
9
  - Contentful GmbH (Andreas Tiefenthaler)
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-06-11 00:00:00.000000000 Z
13
+ date: 2022-06-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: http
@@ -286,12 +286,12 @@ executables:
286
286
  extensions: []
287
287
  extra_rdoc_files: []
288
288
  files:
289
+ - ".circleci/config.yml"
289
290
  - ".gitignore"
290
291
  - ".reek"
291
292
  - ".rspec"
292
293
  - ".rubocop.yml"
293
294
  - ".rubocop_todo.yml"
294
- - ".travis.yml"
295
295
  - ".yardopts"
296
296
  - CHANGELOG.md
297
297
  - Gemfile
@@ -328,6 +328,7 @@ files:
328
328
  - lib/contentful/management/client_space_membership_methods_factory.rb
329
329
  - lib/contentful/management/client_space_methods_factory.rb
330
330
  - lib/contentful/management/client_space_periodic_usage_methods_factory.rb
331
+ - lib/contentful/management/client_tag_methods_factory.rb
331
332
  - lib/contentful/management/client_ui_extension_methods_factory.rb
332
333
  - lib/contentful/management/client_upload_methods_factory.rb
333
334
  - lib/contentful/management/client_user_methods_factory.rb
@@ -350,6 +351,7 @@ files:
350
351
  - lib/contentful/management/environment_editor_interface_methods_factory.rb
351
352
  - lib/contentful/management/environment_entry_methods_factory.rb
352
353
  - lib/contentful/management/environment_locale_methods_factory.rb
354
+ - lib/contentful/management/environment_tag_methods_factory.rb
353
355
  - lib/contentful/management/environment_ui_extension_methods_factory.rb
354
356
  - lib/contentful/management/error.rb
355
357
  - lib/contentful/management/field.rb
@@ -546,6 +548,7 @@ files:
546
548
  - spec/fixtures/vcr_cassettes/delete_request.yml
547
549
  - spec/fixtures/vcr_cassettes/editor_interfaces/default_for_space.yml
548
550
  - spec/fixtures/vcr_cassettes/editor_interfaces/update.yml
551
+ - spec/fixtures/vcr_cassettes/editor_interfaces/update_sidebar.yml
549
552
  - spec/fixtures/vcr_cassettes/entry/all.yml
550
553
  - spec/fixtures/vcr_cassettes/entry/archive.yml
551
554
  - spec/fixtures/vcr_cassettes/entry/archive_published.yml
@@ -596,6 +599,7 @@ files:
596
599
  - spec/fixtures/vcr_cassettes/entry/publish_already_published.yml
597
600
  - spec/fixtures/vcr_cassettes/entry/published_false.yml
598
601
  - spec/fixtures/vcr_cassettes/entry/published_true.yml
602
+ - spec/fixtures/vcr_cassettes/entry/references.yml
599
603
  - spec/fixtures/vcr_cassettes/entry/reload.yml
600
604
  - spec/fixtures/vcr_cassettes/entry/save_update.yml
601
605
  - spec/fixtures/vcr_cassettes/entry/search_filter/equality_operator.yml
@@ -638,6 +642,7 @@ files:
638
642
  - spec/fixtures/vcr_cassettes/environment/find_3.yml
639
643
  - spec/fixtures/vcr_cassettes/environment/issue_189.yml
640
644
  - spec/fixtures/vcr_cassettes/environment/not_found.yml
645
+ - spec/fixtures/vcr_cassettes/environment/tag_proxy.yml
641
646
  - spec/fixtures/vcr_cassettes/get_request.yml
642
647
  - spec/fixtures/vcr_cassettes/locale/all_for_space.yml
643
648
  - spec/fixtures/vcr_cassettes/locale/create_for_space.yml
@@ -738,6 +743,20 @@ files:
738
743
  - spec/fixtures/vcr_cassettes/space_memberships/find_2.yml
739
744
  - spec/fixtures/vcr_cassettes/space_periodic_usage/all.yml
740
745
  - spec/fixtures/vcr_cassettes/space_periodic_usage/filters.yml
746
+ - spec/fixtures/vcr_cassettes/tag/add_tag_to_asset.yml
747
+ - spec/fixtures/vcr_cassettes/tag/add_tag_to_entry.yml
748
+ - spec/fixtures/vcr_cassettes/tag/all.yml
749
+ - spec/fixtures/vcr_cassettes/tag/create_asset_with_tags.yml
750
+ - spec/fixtures/vcr_cassettes/tag/create_entry_with_tags.yml
751
+ - spec/fixtures/vcr_cassettes/tag/create_visibility_private.yml
752
+ - spec/fixtures/vcr_cassettes/tag/create_visibility_public.yml
753
+ - spec/fixtures/vcr_cassettes/tag/destroy.yml
754
+ - spec/fixtures/vcr_cassettes/tag/destroy_referenced.yml
755
+ - spec/fixtures/vcr_cassettes/tag/find.yml
756
+ - spec/fixtures/vcr_cassettes/tag/not_found.yml
757
+ - spec/fixtures/vcr_cassettes/tag/remove_tag_from_asset.yml
758
+ - spec/fixtures/vcr_cassettes/tag/remove_tag_from_entry.yml
759
+ - spec/fixtures/vcr_cassettes/tag/update.yml
741
760
  - spec/fixtures/vcr_cassettes/ui_extension/all.yml
742
761
  - spec/fixtures/vcr_cassettes/ui_extension/create.yml
743
762
  - spec/fixtures/vcr_cassettes/ui_extension/create_parameters.yml
@@ -784,6 +803,7 @@ files:
784
803
  - spec/lib/contentful/management/space_membership_spec.rb
785
804
  - spec/lib/contentful/management/space_periodic_usage_spec.rb
786
805
  - spec/lib/contentful/management/space_spec.rb
806
+ - spec/lib/contentful/management/tag_spec.rb
787
807
  - spec/lib/contentful/management/ui_extension_spec.rb
788
808
  - spec/lib/contentful/management/upload_spec.rb
789
809
  - spec/lib/contentful/management/user_spec.rb
@@ -797,7 +817,7 @@ homepage: https://github.com/contentful/contentful-management.rb
797
817
  licenses:
798
818
  - MIT
799
819
  metadata: {}
800
- post_install_message:
820
+ post_install_message:
801
821
  rdoc_options: []
802
822
  require_paths:
803
823
  - lib
@@ -812,8 +832,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
812
832
  - !ruby/object:Gem::Version
813
833
  version: '0'
814
834
  requirements: []
815
- rubygems_version: 3.0.3
816
- signing_key:
835
+ rubygems_version: 3.1.2
836
+ signing_key:
817
837
  specification_version: 4
818
838
  summary: contentful management api
819
839
  test_files:
@@ -959,6 +979,7 @@ test_files:
959
979
  - spec/fixtures/vcr_cassettes/delete_request.yml
960
980
  - spec/fixtures/vcr_cassettes/editor_interfaces/default_for_space.yml
961
981
  - spec/fixtures/vcr_cassettes/editor_interfaces/update.yml
982
+ - spec/fixtures/vcr_cassettes/editor_interfaces/update_sidebar.yml
962
983
  - spec/fixtures/vcr_cassettes/entry/all.yml
963
984
  - spec/fixtures/vcr_cassettes/entry/archive.yml
964
985
  - spec/fixtures/vcr_cassettes/entry/archive_published.yml
@@ -1009,6 +1030,7 @@ test_files:
1009
1030
  - spec/fixtures/vcr_cassettes/entry/publish_already_published.yml
1010
1031
  - spec/fixtures/vcr_cassettes/entry/published_false.yml
1011
1032
  - spec/fixtures/vcr_cassettes/entry/published_true.yml
1033
+ - spec/fixtures/vcr_cassettes/entry/references.yml
1012
1034
  - spec/fixtures/vcr_cassettes/entry/reload.yml
1013
1035
  - spec/fixtures/vcr_cassettes/entry/save_update.yml
1014
1036
  - spec/fixtures/vcr_cassettes/entry/search_filter/equality_operator.yml
@@ -1051,6 +1073,7 @@ test_files:
1051
1073
  - spec/fixtures/vcr_cassettes/environment/find_3.yml
1052
1074
  - spec/fixtures/vcr_cassettes/environment/issue_189.yml
1053
1075
  - spec/fixtures/vcr_cassettes/environment/not_found.yml
1076
+ - spec/fixtures/vcr_cassettes/environment/tag_proxy.yml
1054
1077
  - spec/fixtures/vcr_cassettes/get_request.yml
1055
1078
  - spec/fixtures/vcr_cassettes/locale/all_for_space.yml
1056
1079
  - spec/fixtures/vcr_cassettes/locale/create_for_space.yml
@@ -1151,6 +1174,20 @@ test_files:
1151
1174
  - spec/fixtures/vcr_cassettes/space_memberships/find_2.yml
1152
1175
  - spec/fixtures/vcr_cassettes/space_periodic_usage/all.yml
1153
1176
  - spec/fixtures/vcr_cassettes/space_periodic_usage/filters.yml
1177
+ - spec/fixtures/vcr_cassettes/tag/add_tag_to_asset.yml
1178
+ - spec/fixtures/vcr_cassettes/tag/add_tag_to_entry.yml
1179
+ - spec/fixtures/vcr_cassettes/tag/all.yml
1180
+ - spec/fixtures/vcr_cassettes/tag/create_asset_with_tags.yml
1181
+ - spec/fixtures/vcr_cassettes/tag/create_entry_with_tags.yml
1182
+ - spec/fixtures/vcr_cassettes/tag/create_visibility_private.yml
1183
+ - spec/fixtures/vcr_cassettes/tag/create_visibility_public.yml
1184
+ - spec/fixtures/vcr_cassettes/tag/destroy.yml
1185
+ - spec/fixtures/vcr_cassettes/tag/destroy_referenced.yml
1186
+ - spec/fixtures/vcr_cassettes/tag/find.yml
1187
+ - spec/fixtures/vcr_cassettes/tag/not_found.yml
1188
+ - spec/fixtures/vcr_cassettes/tag/remove_tag_from_asset.yml
1189
+ - spec/fixtures/vcr_cassettes/tag/remove_tag_from_entry.yml
1190
+ - spec/fixtures/vcr_cassettes/tag/update.yml
1154
1191
  - spec/fixtures/vcr_cassettes/ui_extension/all.yml
1155
1192
  - spec/fixtures/vcr_cassettes/ui_extension/create.yml
1156
1193
  - spec/fixtures/vcr_cassettes/ui_extension/create_parameters.yml
@@ -1197,6 +1234,7 @@ test_files:
1197
1234
  - spec/lib/contentful/management/space_membership_spec.rb
1198
1235
  - spec/lib/contentful/management/space_periodic_usage_spec.rb
1199
1236
  - spec/lib/contentful/management/space_spec.rb
1237
+ - spec/lib/contentful/management/tag_spec.rb
1200
1238
  - spec/lib/contentful/management/ui_extension_spec.rb
1201
1239
  - spec/lib/contentful/management/upload_spec.rb
1202
1240
  - spec/lib/contentful/management/user_spec.rb
data/.travis.yml DELETED
@@ -1,12 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.6.1
4
- - 2.5.1
5
- - 2.4.1
6
- - 2.3.1
7
-
8
- before_install: gem install bundler
9
- script: bundle exec rake rspec_rubocop
10
- notifications:
11
- slack:
12
- secure: P+BWOt+sKPUlIwxUMaD7o4bVG19nIsedyv9D1MCBJELKxTYkXOyJECSNw1f5SDf9z0n4lKhfp8SY0dVigvxdUBd9/wsGqRZMMI2sykDJ8E85cYsUb8corEnIgQtwwzkAzWzhCbmWrZe39ai1Sr5ET/7bdEJ7SXIKbFS350SOn9s=