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
@@ -0,0 +1,119 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: https://api.contentful.com/spaces/zjvxmotjud5s/webhook_definitions/some_id
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"name":"some_webhook","url":"https://www.example2.com","headers":[{"key":"MyHeader","value":"foobar"}]}'
9
+ headers:
10
+ User-Agent:
11
+ - RubyContentfulManagementGem/1.0.1
12
+ Authorization:
13
+ - Bearer <ACCESS_TOKEN>
14
+ Content-Type:
15
+ - application/vnd.contentful.management.v1+json
16
+ Connection:
17
+ - close
18
+ Host:
19
+ - api.contentful.com
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Accept-Ranges:
26
+ - bytes
27
+ Access-Control-Allow-Headers:
28
+ - Accept,Accept-Language,Authorization,Cache-Control,Content-Length,Content-Range,Content-Type,DNT,Destination,Expires,If-Match,If-Modified-Since,If-None-Match,Keep-Alive,Last-Modified,Origin,Pragma,Range,User-Agent,X-Http-Method-Override,X-Mx-ReqToken,X-Requested-With,X-Contentful-Version,X-Contentful-Content-Type,X-Contentful-Organization,X-Contentful-Skip-Transformation,X-Contentful-User-Agent
29
+ Access-Control-Allow-Methods:
30
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Access-Control-Expose-Headers:
34
+ - Etag
35
+ Access-Control-Max-Age:
36
+ - '1728000'
37
+ Cache-Control:
38
+ - max-age=0
39
+ Content-Type:
40
+ - application/vnd.contentful.management.v1+json
41
+ Date:
42
+ - Mon, 11 Apr 2016 12:02:42 GMT
43
+ Etag:
44
+ - '"01be3e0e10cb470efae890f743919134"'
45
+ Server:
46
+ - nginx
47
+ Status:
48
+ - 200 OK
49
+ Strict-Transport-Security:
50
+ - max-age=15768000
51
+ X-Content-Type-Options:
52
+ - nosniff
53
+ X-Contentful-Request-Id:
54
+ - b89-586923734
55
+ Content-Length:
56
+ - '779'
57
+ Connection:
58
+ - Close
59
+ Set-Cookie:
60
+ - incap_ses_298_673446=smiVONW/3z4SYfTFKrYiBGKSC1cAAAAAWFRx31EjUEYkINQqH3WjVA==;
61
+ path=/; Domain=.contentful.com
62
+ - nlbi_673446=vrUaNl0JVwteQduiaoBaJgAAAAC8NTjiFbae4xBPiFqTka40; path=/; Domain=.contentful.com
63
+ - visid_incap_673446=gUN9MJSOQeC2jpXLGMK41mKSC1cAAAAAQUIPAAAAAAAW7GMqfuKypNg7FVuYvw1a;
64
+ expires=Tue, 11 Apr 2017 09:48:50 GMT; path=/; Domain=.contentful.com
65
+ X-Iinfo:
66
+ - 6-47862086-47862138 NNNN CT(135 136 0) RT(1460376161233 384) q(0 0 2 -1) r(5
67
+ 5) U5
68
+ X-Cdn:
69
+ - Incapsula
70
+ body:
71
+ encoding: UTF-8
72
+ string: |+
73
+ {
74
+ "url":"https://www.example2.com",
75
+ "httpBasicUsername":null,
76
+ "name":"some_webhook",
77
+ "headers":[
78
+ {
79
+ "key":"MyHeader",
80
+ "value":"foobar"
81
+ }
82
+ ],
83
+ "topics":[
84
+ "*.publish",
85
+ "*.unpublish"
86
+ ],
87
+ "sys":{
88
+ "type":"WebhookDefinition",
89
+ "id":"some_id",
90
+ "version":1,
91
+ "space":{
92
+ "sys":{
93
+ "type":"Link",
94
+ "linkType":"Space",
95
+ "id":"zjvxmotjud5s"
96
+ }
97
+ },
98
+ "createdBy":{
99
+ "sys":{
100
+ "type":"Link",
101
+ "linkType":"User",
102
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
103
+ }
104
+ },
105
+ "createdAt":"2016-04-11T12:01:38Z",
106
+ "updatedBy":{
107
+ "sys":{
108
+ "type":"Link",
109
+ "linkType":"User",
110
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
111
+ }
112
+ },
113
+ "updatedAt":"2016-04-11T12:02:42Z"
114
+ }
115
+ }
116
+
117
+ http_version:
118
+ recorded_at: Mon, 11 Apr 2016 12:02:42 GMT
119
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,117 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.contentful.com/spaces/zjvxmotjud5s/webhook_definitions
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"name":"test_topics","url":"https://www.example3.com","topics":["Entry.save","Entry.publish","ContentType.*"]}'
9
+ headers:
10
+ User-Agent:
11
+ - RubyContentfulManagementGem/1.0.1
12
+ Authorization:
13
+ - Bearer <ACCESS_TOKEN>
14
+ Content-Type:
15
+ - application/vnd.contentful.management.v1+json
16
+ Connection:
17
+ - close
18
+ Host:
19
+ - api.contentful.com
20
+ response:
21
+ status:
22
+ code: 201
23
+ message: Created
24
+ headers:
25
+ Accept-Ranges:
26
+ - bytes
27
+ Access-Control-Allow-Headers:
28
+ - Accept,Accept-Language,Authorization,Cache-Control,Content-Length,Content-Range,Content-Type,DNT,Destination,Expires,If-Match,If-Modified-Since,If-None-Match,Keep-Alive,Last-Modified,Origin,Pragma,Range,User-Agent,X-Http-Method-Override,X-Mx-ReqToken,X-Requested-With,X-Contentful-Version,X-Contentful-Content-Type,X-Contentful-Organization,X-Contentful-Skip-Transformation,X-Contentful-User-Agent
29
+ Access-Control-Allow-Methods:
30
+ - DELETE,GET,HEAD,POST,PUT,OPTIONS
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Access-Control-Expose-Headers:
34
+ - Etag
35
+ Access-Control-Max-Age:
36
+ - '1728000'
37
+ Cache-Control:
38
+ - max-age=0
39
+ Content-Type:
40
+ - application/vnd.contentful.management.v1+json
41
+ Date:
42
+ - Mon, 11 Apr 2016 12:07:22 GMT
43
+ Etag:
44
+ - '"dd51fac46eba663bcf7329d8b7ee8b2d"'
45
+ Location:
46
+ - https://api.contentful.com/spaces/zjvxmotjud5s/webhook_definitions/6M41zyKGz55qnovKxmQpDq
47
+ Server:
48
+ - nginx
49
+ Status:
50
+ - 201 Created
51
+ Strict-Transport-Security:
52
+ - max-age=15768000
53
+ X-Content-Type-Options:
54
+ - nosniff
55
+ X-Contentful-Request-Id:
56
+ - 0b5-378528942
57
+ Content-Length:
58
+ - '755'
59
+ Connection:
60
+ - Close
61
+ Set-Cookie:
62
+ - incap_ses_298_673446=ObNhKWt19F4cF/bFKrYiBHmTC1cAAAAAkqUyDYhnniovgNttVTfJiA==;
63
+ path=/; Domain=.contentful.com
64
+ - nlbi_673446=91YRMe7grEIWz1qEaoBaJgAAAABieAw9TAy6uXkiSIdAo7qF; path=/; Domain=.contentful.com
65
+ - visid_incap_673446=5hUsKWioRmWE8c2RlEOdQnmTC1cAAAAAQUIPAAAAAACl2BFxadnn1v0+QIVhz6Py;
66
+ expires=Tue, 11 Apr 2017 09:48:50 GMT; path=/; Domain=.contentful.com
67
+ X-Iinfo:
68
+ - 8-70349673-70349687 NNNN CT(145 137 0) RT(1460376440866 93) q(0 0 3 -1) r(6
69
+ 6) U5
70
+ X-Cdn:
71
+ - Incapsula
72
+ body:
73
+ encoding: UTF-8
74
+ string: |+
75
+ {
76
+ "url":"https://www.example3.com",
77
+ "httpBasicUsername":null,
78
+ "name":"test_topics",
79
+ "headers":[],
80
+ "topics":[
81
+ "Entry.save",
82
+ "Entry.publish",
83
+ "ContentType.*"
84
+ ],
85
+ "sys":{
86
+ "type":"WebhookDefinition",
87
+ "id":"6M41zyKGz55qnovKxmQpDq",
88
+ "version":0,
89
+ "space":{
90
+ "sys":{
91
+ "type":"Link",
92
+ "linkType":"Space",
93
+ "id":"zjvxmotjud5s"
94
+ }
95
+ },
96
+ "createdBy":{
97
+ "sys":{
98
+ "type":"Link",
99
+ "linkType":"User",
100
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
101
+ }
102
+ },
103
+ "createdAt":"2016-04-11T12:07:21Z",
104
+ "updatedBy":{
105
+ "sys":{
106
+ "type":"Link",
107
+ "linkType":"User",
108
+ "id":"4SejVrWT96dvL9IV4Nb7sQ"
109
+ }
110
+ },
111
+ "updatedAt":"2016-04-11T12:07:21Z"
112
+ }
113
+ }
114
+
115
+ http_version:
116
+ recorded_at: Mon, 11 Apr 2016 12:07:22 GMT
117
+ recorded_with: VCR 2.9.3
@@ -38,6 +38,10 @@ module Contentful
38
38
 
39
39
  describe '.all_published' do
40
40
  let!(:space_id) { 'bjwq7b86vgmm' }
41
+ before :each do
42
+ expect_any_instance_of(Contentful::Management::Asset.client_association_class).to receive(:warn)
43
+ end
44
+
41
45
  it 'class method also works' do
42
46
  vcr('asset/all_public') { expect(Contentful::Management::Asset.all_published(client, space_id)).to be_kind_of Contentful::Management::Array }
43
47
  end
@@ -207,6 +207,42 @@ module Contentful
207
207
  end
208
208
  end
209
209
  end
210
+
211
+ it 'creates a content_type with an omitted field' do
212
+ vcr('content_type/omitted_field') {
213
+ space = client.spaces.find('ngtgiva4wofg')
214
+
215
+ omitted_field = Contentful::Management::Field.new
216
+ omitted_field.id = 'omitted_field'
217
+ omitted_field.name = 'omitted_field'
218
+ omitted_field.type = 'Symbol'
219
+ omitted_field.omitted = true
220
+
221
+ name_field = Contentful::Management::Field.new
222
+ name_field.id = 'name'
223
+ name_field.name = 'name'
224
+ name_field.type = 'Symbol'
225
+
226
+ content_type = space.content_types.new
227
+ content_type.id = 'omitted_ct'
228
+ content_type.name = 'Omitted CT'
229
+ content_type.fields = [omitted_field, name_field]
230
+ content_type.display_field = 'name'
231
+
232
+ content_type.save
233
+ content_type.activate
234
+
235
+ content_type.reload
236
+
237
+ field = content_type.fields.detect { |f| f.name == 'omitted_field' }
238
+
239
+ expect(field.omitted).to be_truthy
240
+
241
+ field = content_type.fields.detect { |f| f.name == 'name' }
242
+
243
+ expect(field.omitted).to be_falsey
244
+ }
245
+ end
210
246
  end
211
247
 
212
248
  describe '#update' do
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+ require 'contentful/management/space'
3
+ require 'contentful/management/client'
4
+
5
+ module Contentful
6
+ module Management
7
+ describe EditorInterface do
8
+ let(:token) { '<ACCESS_TOKEN>' }
9
+ let(:space_id) { 'oe3b689om6k5' }
10
+ let(:content_type_id) { 'testInterfaces' }
11
+ let(:editor_interface_id) { 'default' }
12
+
13
+ let(:editor_interface_attrs) {
14
+ {
15
+ controls: [
16
+ {
17
+ 'fieldId' => 'symbol1',
18
+ 'widgetId' => 'urlEditor'
19
+ }
20
+ ]
21
+ }
22
+ }
23
+
24
+ let!(:client) { Client.new(token) }
25
+
26
+ subject { client.editor_interfaces }
27
+
28
+ describe '.default' do
29
+ it 'class method also works' do
30
+ vcr('editor_interfaces/default_for_space') { expect(Contentful::Management::EditorInterface.default(client, space_id, content_type_id)).to be_kind_of Contentful::Management::EditorInterface }
31
+ end
32
+ it 'builds a Contentful::Management::Locale object' do
33
+ vcr('editor_interfaces/default_for_space') { expect(subject.default(space_id, content_type_id)).to be_kind_of Contentful::Management::EditorInterface }
34
+ end
35
+ end
36
+
37
+ describe '#update' do
38
+ let(:content_type_id) { 'smallerType' }
39
+
40
+ it 'can update the editor_interface' do
41
+ vcr('editor_interfaces/update') do
42
+ editor_interface = subject.default(space_id, content_type_id)
43
+
44
+ expect(editor_interface.controls.first['widgetId']).to eq 'singleline'
45
+
46
+ editor_interface.controls.first['widgetId'] = 'urlEditor'
47
+ editor_interface.update(controls: editor_interface.controls)
48
+
49
+ editor_interface.reload
50
+
51
+ expect(editor_interface.controls.first['widgetId']).to eq 'urlEditor'
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -44,6 +44,11 @@ module Contentful
44
44
 
45
45
  describe '.all_published' do
46
46
  let!(:space_id) { 'bjwq7b86vgmm' }
47
+
48
+ before :each do
49
+ expect_any_instance_of(Contentful::Management::Entry.client_association_class).to receive(:warn)
50
+ end
51
+
47
52
  it 'class method also works' do
48
53
  vcr('entry/all_public') { expect(Contentful::Management::Entry.all_published(client, space_id)).to be_kind_of Contentful::Management::Array }
49
54
  end
@@ -0,0 +1,125 @@
1
+ require 'spec_helper'
2
+ require 'contentful/management/space'
3
+ require 'contentful/management/client'
4
+
5
+ module Contentful
6
+ module Management
7
+ describe Role do
8
+ let(:token) { '<ACCESS_TOKEN>' }
9
+ let(:space_id) { '03vrieuz7eun' }
10
+ let(:role_id) { '0rQMQMd6ZTgeF7hxjz7JDi' }
11
+
12
+ let(:role_attrs) {
13
+ {
14
+ name: 'testRoleCreate',
15
+ description: 'test role',
16
+ permissions: {
17
+ 'ContentDelivery' => 'all',
18
+ 'ContentModel' => ['read'],
19
+ 'Settings' => []
20
+ },
21
+ policies: [
22
+ {
23
+ effect: 'allow',
24
+ actions: 'all',
25
+ constraint: {
26
+ and: [
27
+ {
28
+ equals: [
29
+ { doc: 'sys.type' },
30
+ 'Entry'
31
+ ]
32
+ },
33
+ {
34
+ equals: [
35
+ { doc: 'sys.type' },
36
+ 'Asset'
37
+ ]
38
+ }
39
+ ]
40
+ }
41
+ }
42
+ ]
43
+ }
44
+ }
45
+
46
+ let!(:client) { Client.new(token) }
47
+
48
+ subject { client.roles }
49
+
50
+ describe '.all' do
51
+ it 'class method also works' do
52
+ vcr('roles/all_for_space') { expect(Contentful::Management::Role.all(client, space_id)).to be_kind_of Contentful::Management::Array }
53
+ end
54
+ it 'returns a Contentful::Array' do
55
+ vcr('roles/all_for_space') { expect(subject.all(space_id)).to be_kind_of Contentful::Management::Array }
56
+ end
57
+ it 'builds a Contentful::Management::Locale object' do
58
+ vcr('roles/all_for_space') { expect(subject.all(space_id).first).to be_kind_of Contentful::Management::Role }
59
+ end
60
+ end
61
+
62
+ describe '.find' do
63
+ it 'class method also works' do
64
+ vcr('roles/find') { expect(Contentful::Management::Role.find(client, space_id, role_id)).to be_kind_of Contentful::Management::Role }
65
+ end
66
+ it 'returns a Contentful::Management::Role' do
67
+ vcr('roles/find') { expect(subject.find(space_id, role_id)).to be_kind_of Contentful::Management::Role }
68
+ end
69
+ it 'returns the locale for a given key' do
70
+ vcr('roles/find') do
71
+ role = subject.find(space_id, role_id)
72
+ expect(role.id).to eq role_id
73
+ end
74
+ end
75
+ it 'returns an error when content_type does not exists' do
76
+ vcr('roles/find_for_space_not_found') do
77
+ result = subject.find(space_id, 'not_exist')
78
+ expect(result).to be_kind_of Contentful::Management::NotFound
79
+ end
80
+ end
81
+ end
82
+ describe '.create' do
83
+ it 'create role for space' do
84
+ vcr('roles/create_for_space') do
85
+ role = subject.create(space_id, role_attrs)
86
+
87
+ expect(role.name).to eq 'testRoleCreate'
88
+ expect(role.description).to eq 'test role'
89
+ expect(role.permissions['ContentDelivery']).to eq 'all'
90
+ expect(role.policies.first['effect']).to eq 'allow'
91
+ end
92
+ end
93
+ end
94
+ describe '#update' do
95
+ it 'can update the role' do
96
+ vcr('roles/update') do
97
+ role = subject.find(space_id, role_id)
98
+ role.update(name: 'Something')
99
+
100
+ role.reload
101
+
102
+ expect(role.name).to eq 'Something'
103
+ end
104
+ end
105
+ end
106
+
107
+ describe '#destroy' do
108
+ it 'can destroy roles' do
109
+ vcr('roles/destroy') do
110
+ role_attrs[:name] = 'ToDelete'
111
+ role = subject.create(space_id, role_attrs)
112
+
113
+ expect(subject.find(space_id, role.id).name).to eq 'ToDelete'
114
+
115
+ role.destroy
116
+
117
+ error = subject.find(space_id, role.id)
118
+
119
+ expect(error).to be_a Contentful::Management::NotFound
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end