contentful-management 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bb620d6df69c4e84f671fe8a91e91f1fae53310
4
- data.tar.gz: f1cb940d955248205c1c564d45aa25e8c59de0d4
3
+ metadata.gz: 9e9540f9f6f76faa7bc81ffc078b274f6ad41c9f
4
+ data.tar.gz: 627329c7f26dcb8f7866def702f06d0c44721777
5
5
  SHA512:
6
- metadata.gz: e7b895437b69329cab7a8d4e45454cf304bcedbb911463ed5fd5b92d37b1cc479c31a164ee96ee46991ced0eddcbf38c186544eeeef135a38b819e6382a78d34
7
- data.tar.gz: ba872718b2b957c72a36956c72db232b1edbb537d14bd18520ccb32a1921666ae423b8b2172c73a1c84894edd40db732f8bddf775af5751294af4a2fa21f3d66
6
+ metadata.gz: 8d249c4f1a49c297c970a712c9e7a934b52928e839b2d7fa63e451c714ed7e002e26799eb8aa3550dd1cce1ab3d88537ebd6a30455c996bff32fd306fb6e0f13
7
+ data.tar.gz: e6e6a254e522a42befd514c7877db377c4f0c32abca8760fc8fb2f291afc155a815fca42057fb77e89a490269ce6251a5f95d1c6e51eb6832ae9ee1a2166f794
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## Master
4
4
 
5
+ ## 1.1.0
6
+ ### Added
7
+ * Add Roles and Permissions Support
8
+ * Add Headers, Topics and Webhook Name Support
9
+ * Add Editor Interfaces Support
10
+ * Add `:omitted` property to Content Type Fields
11
+
12
+ ### Changed
13
+ * Added Deprecation warning for `assets.all_published` and `entries.all_published`. This methods will be completely removed soon.
14
+
5
15
  ## 1.0.1
6
16
  ### Changed
7
17
  * Changed locale selection priority when requesting fields [#91](https://github.com/contentful/contentful-management.rb/issues/91)
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ gemspec
5
5
 
6
6
  group :development do
7
7
  gem 'guard'
8
+ gem 'listen', '3.0.0'
8
9
  gem 'guard-rspec'
9
10
  gem 'guard-rubocop'
10
11
  gem 'pry'
data/README.md CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  # Contentful::Management
3
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)
4
3
 
@@ -85,131 +84,6 @@ blog_space.name = 'New Blog Space'
85
84
  blog_space.save
86
85
  ```
87
86
 
88
- ### Content Types
89
-
90
- Retrieving all content types from a space:
91
-
92
- ```ruby
93
- blog_post_content_types = blog_space.content_types.all
94
- ```
95
-
96
- Retrieving all published content types from a space:
97
-
98
- ```ruby
99
- blog_post_content_types = blog_space.content_types.all_published
100
- ```
101
-
102
- Retrieving one content type by id from a space:
103
-
104
- ```ruby
105
- blog_post_content_type = blog_space.content_types.find(id)
106
- ```
107
-
108
- Creating a field for a content type:
109
-
110
- ```ruby
111
- title_field = Contentful::Management::Field.new
112
- title_field.id = 'blog_post_title'
113
- title_field.name = 'Post Title'
114
- title_field.type = 'Text'
115
- blog_post_content_type.fields.add(field)
116
- ```
117
-
118
- or
119
-
120
- ```ruby
121
- blog_post_content_type.fields.create(id: 'title_field_id', name: 'Post Title', type: 'Text')
122
- ```
123
- - if the field_id exists, the related field will be updated.
124
-
125
- or the field of link type:
126
- ```ruby
127
- blog_post_content_type.fields.create(id: 'my_entry_link_field', name: 'My Entry Link Field', type: 'Link', link_type: 'Entry')
128
- ```
129
-
130
- or the field of an array type:
131
- ```ruby
132
- items = Contentful::Management::Field.new
133
- items.type = 'Link'
134
- items.link_type = 'Entry'
135
- blog_post_content_type.fields.create(id: 'my_array_field', name: 'My Array Field', type: 'Array', items: items)
136
- ```
137
-
138
- Deleting a field from the content type:
139
-
140
- ```ruby
141
- blog_post_content_type.fields.destroy(title_field_id)
142
- ```
143
-
144
- Creating a content type:
145
-
146
- ```ruby
147
- blog_space.content_types.create(name: 'Post', fields: [title_field, body_field])
148
- ```
149
-
150
- or
151
-
152
- ```ruby
153
- blog_post_content_type = blog_space.content_types.new
154
- blog_post_content_type.name = 'Post'
155
- blog_post_content_type.fields = [title_field, body_field]
156
- blog_post_content_type.save
157
- ```
158
-
159
- Destroying a content type:
160
-
161
- ```ruby
162
- blog_post_content_type.destroy
163
- ```
164
-
165
- Activating or deactivating a content type:
166
-
167
- ```ruby
168
- blog_post_content_type.activate
169
- blog_post_content_type.deactivate
170
- ```
171
-
172
- Checking if a content type is active:
173
-
174
- ```ruby
175
- blog_post_content_type.active?
176
- ```
177
-
178
- Updating a content type:
179
-
180
- ```ruby
181
- blog_post_content_type.update(name: 'Post', description: 'Post Description', fields: [title_field])
182
- ```
183
-
184
- ### Locales
185
-
186
- Retrieving all locales from the space:
187
-
188
- ```ruby
189
- blog_post_locales = blog_space.locales.all
190
- ```
191
-
192
- Retrieving one locale by the locale-id from the space:
193
-
194
- ```ruby
195
- blog_post_locale = blog_space.locales.find(locale_id)
196
- ```
197
-
198
- Creating a locale
199
- ```ruby
200
- blog_space.locales.create(name: 'German', code: 'de-DE')
201
- ```
202
-
203
- Updating a locale
204
- ```ruby
205
- blog_post_locale.update(name: 'German', code: 'de-DE')
206
- ```
207
-
208
- Destroying a locale
209
- ```ruby
210
- blog_post_locale.destroy
211
- ```
212
-
213
87
  ### Assets
214
88
 
215
89
  Retrieving all assets from the space:
@@ -218,7 +92,7 @@ Retrieving all assets from the space:
218
92
  blog_post_assets = blog_space.assets.all
219
93
  ```
220
94
 
221
- Retrieving all published assets from the space:
95
+ Retrieving all published assets from the space: **DEPRECATED**
222
96
 
223
97
  ```ruby
224
98
  blog_post_assets = blog_space.assets.all_published
@@ -330,7 +204,7 @@ Retrieving all entries from the space:
330
204
  entries = blog_space.entries.all
331
205
  ```
332
206
 
333
- Retrieving all published entries from the space:
207
+ Retrieving all published entries from the space: **DEPRECATED**
334
208
 
335
209
  ```ruby
336
210
  entries = blog_space.entries.all_published
@@ -435,57 +309,103 @@ my_entry.published?
435
309
  > * Enable [Content Type Cache](#content-type-cache) at Client Instantiation time
436
310
  > * Query Entries through `space.entries.find` instead of `Entry.find(space_id, entry_id)`
437
311
 
438
- ### Webhooks
312
+ ### Content Types
439
313
 
440
- Retrieving all webhooks from the space:
314
+ Retrieving all content types from a space:
441
315
 
442
316
  ```ruby
443
- webhooks = blog_space.webhooks.all
317
+ blog_post_content_types = blog_space.content_types.all
444
318
  ```
445
- Retrieving one webhook by the webhook-id from the space:
319
+
320
+ Retrieving all published content types from a space:
446
321
 
447
322
  ```ruby
448
- blog_post_webhook = blog_space.webhooks.find(webhook_id)
323
+ blog_post_content_types = blog_space.content_types.all_published
449
324
  ```
450
325
 
451
- Creating a webhook
326
+ Retrieving one content type by id from a space:
452
327
 
453
328
  ```ruby
454
- blog_space.webhooks.create(url: 'https://www.example.com', httpBasicUsername: 'username', httpBasicPassword: 'password')
329
+ blog_post_content_type = blog_space.content_types.find(id)
455
330
  ```
456
331
 
457
- Updating a webhook
332
+ Creating a field for a content type:
458
333
 
459
334
  ```ruby
460
- blog_post_webhook.update(url: 'https://www.newlink.com')
335
+ title_field = Contentful::Management::Field.new
336
+ title_field.id = 'blog_post_title'
337
+ title_field.name = 'Post Title'
338
+ title_field.type = 'Text'
339
+ blog_post_content_type.fields.add(field)
461
340
  ```
462
341
 
463
- Destroying webhook:
342
+ or
464
343
 
465
344
  ```ruby
466
- blog_post_webhook.destroy
345
+ blog_post_content_type.fields.create(id: 'title_field_id', name: 'Post Title', type: 'Text')
467
346
  ```
347
+ - if the field_id exists, the related field will be updated.
468
348
 
469
- ### Api Keys
349
+ or the field of link type:
350
+ ```ruby
351
+ blog_post_content_type.fields.create(id: 'my_entry_link_field', name: 'My Entry Link Field', type: 'Link', link_type: 'Entry')
352
+ ```
470
353
 
471
- Retrieving all api keys from the space:
354
+ or the field of an array type:
355
+ ```ruby
356
+ items = Contentful::Management::Field.new
357
+ items.type = 'Link'
358
+ items.link_type = 'Entry'
359
+ blog_post_content_type.fields.create(id: 'my_array_field', name: 'My Array Field', type: 'Array', items: items)
360
+ ```
361
+
362
+ Deleting a field from the content type:
472
363
 
473
364
  ```ruby
474
- blog_post_api_keys = blog_space.api_keys.all
365
+ blog_post_content_type.fields.destroy(title_field_id)
475
366
  ```
476
367
 
477
- Retrieving one api key by the api-key-id from the space:
368
+ Creating a content type:
478
369
 
479
370
  ```ruby
480
- blog_post_api_key = blog_space.api_keys.find(api_key_id)
371
+ blog_space.content_types.create(name: 'Post', fields: [title_field, body_field])
481
372
  ```
482
373
 
483
- Creating an api key
374
+ or
375
+
484
376
  ```ruby
485
- blog_space.api_keys.create(name: 'foobar key', description: 'key for foobar mobile app')
377
+ blog_post_content_type = blog_space.content_types.new
378
+ blog_post_content_type.name = 'Post'
379
+ blog_post_content_type.fields = [title_field, body_field]
380
+ blog_post_content_type.save
381
+ ```
382
+
383
+ Destroying a content type:
384
+
385
+ ```ruby
386
+ blog_post_content_type.destroy
486
387
  ```
487
388
 
488
- ## Validations
389
+ Activating or deactivating a content type:
390
+
391
+ ```ruby
392
+ blog_post_content_type.activate
393
+ blog_post_content_type.deactivate
394
+ ```
395
+
396
+ Checking if a content type is active:
397
+
398
+ ```ruby
399
+ blog_post_content_type.active?
400
+ ```
401
+
402
+ Updating a content type:
403
+
404
+ ```ruby
405
+ blog_post_content_type.update(name: 'Post', description: 'Post Description', fields: [title_field])
406
+ ```
407
+
408
+ ### Validations
489
409
 
490
410
  #### in
491
411
 
@@ -567,6 +487,180 @@ validation_link_field.link_field = true
567
487
  content_type.fields.create(id: 'entry', validations: [validation_link_field])
568
488
  ```
569
489
 
490
+ ### Locales
491
+
492
+ Retrieving all locales from the space:
493
+
494
+ ```ruby
495
+ blog_post_locales = blog_space.locales.all
496
+ ```
497
+
498
+ Retrieving one locale by the locale-id from the space:
499
+
500
+ ```ruby
501
+ blog_post_locale = blog_space.locales.find(locale_id)
502
+ ```
503
+
504
+ Creating a locale
505
+ ```ruby
506
+ blog_space.locales.create(name: 'German', code: 'de-DE')
507
+ ```
508
+
509
+ Updating a locale
510
+ ```ruby
511
+ blog_post_locale.update(name: 'German', code: 'de-DE')
512
+ ```
513
+
514
+ Destroying a locale
515
+ ```ruby
516
+ blog_post_locale.destroy
517
+ ```
518
+
519
+ ### Roles
520
+
521
+ Retrieving all roles from the space:
522
+
523
+ ```ruby
524
+ blog_post_roles = blog_space.roles.all
525
+ ```
526
+
527
+ Retrieving one role by the locale-id from the space:
528
+
529
+ ```ruby
530
+ blog_post_role = blog_space.role.find(role_id)
531
+ ```
532
+
533
+ Creating a role
534
+ ```ruby
535
+ role_attributes = {
536
+ name: 'My Role',
537
+ description: 'foobar role',
538
+ permissions: {
539
+ 'ContentDelivery': 'all',
540
+ 'ContentModel': ['read'],
541
+ 'Settings': []
542
+ },
543
+ policies: [
544
+ {
545
+ effect: 'allow',
546
+ actions: 'all',
547
+ constraint: {
548
+ and: [
549
+ {
550
+ equals: [
551
+ { doc: 'sys.type' },
552
+ 'Entry'
553
+ ]
554
+ },
555
+ {
556
+ equals: [
557
+ { doc: 'sys.type' },
558
+ 'Asset'
559
+ ]
560
+ }
561
+ ]
562
+ }
563
+ }
564
+ ]
565
+ }
566
+ blog_space.roles.create(role_attributes)
567
+ ```
568
+
569
+ Updating a role
570
+ ```ruby
571
+ blog_post_role.update(name: 'Some Other Role') # Can change any attribute here
572
+ ```
573
+
574
+ Destroying a role
575
+ ```ruby
576
+ blog_post_role.destroy
577
+ ```
578
+
579
+ ### Webhooks
580
+
581
+ Retrieving all webhooks from the space:
582
+
583
+ ```ruby
584
+ webhooks = blog_space.webhooks.all
585
+ ```
586
+ Retrieving one webhook by the webhook-id from the space:
587
+
588
+ ```ruby
589
+ blog_post_webhook = blog_space.webhooks.find(webhook_id)
590
+ ```
591
+
592
+ Creating a webhook
593
+
594
+ ```ruby
595
+ blog_space.webhooks.create(
596
+ name: 'My Webhook',
597
+ url: 'https://www.example.com',
598
+ httpBasicUsername: 'username',
599
+ httpBasicPassword: 'password'
600
+ )
601
+ ```
602
+
603
+ Updating a webhook
604
+
605
+ ```ruby
606
+ blog_post_webhook.update(url: 'https://www.newlink.com')
607
+ ```
608
+
609
+ Destroying webhook:
610
+
611
+ ```ruby
612
+ blog_post_webhook.destroy
613
+ ```
614
+
615
+ Creating a Webhook with Custom Headers and Custom Topics:
616
+
617
+ ```ruby
618
+ blog_space.webhooks.create(
619
+ name: 'Entry Save Only',
620
+ url: 'https://www.example.com',
621
+ topics: [ 'Entry.save' ],
622
+ headers: [
623
+ {
624
+ key: 'X-My-Custom-Header',
625
+ value: 'Some Value'
626
+ }
627
+ ]
628
+ )
629
+ ```
630
+
631
+ ### Api Keys
632
+
633
+ Retrieving all api keys from the space:
634
+
635
+ ```ruby
636
+ blog_post_api_keys = blog_space.api_keys.all
637
+ ```
638
+
639
+ Retrieving one api key by the api-key-id from the space:
640
+
641
+ ```ruby
642
+ blog_post_api_key = blog_space.api_keys.find(api_key_id)
643
+ ```
644
+
645
+ Creating an api key
646
+ ```ruby
647
+ blog_space.api_keys.create(name: 'foobar key', description: 'key for foobar mobile app')
648
+ ```
649
+
650
+ ### Editor Interface
651
+
652
+ Retrieving editor interface for a content type:
653
+
654
+ ```ruby
655
+ blog_post_editor_interface = blog_post_content_type.editor_interface.default
656
+ ```
657
+
658
+ You can call the EditorInterface API from any level within the Content Model Hierarchy, take into account that you'll need to
659
+ pass the ids of the levels below it.
660
+
661
+ > Hierarchy is as follows:
662
+ > `No Object -> Space -> ContentType -> EditorInterface`
663
+
570
664
  ### Pagination
571
665
 
572
666
  ```ruby
@@ -575,7 +669,7 @@ blog_space.assets.all(limit: 5).next_page
575
669
  blog_space.entries.all(limit: 5).next_page
576
670
  ```
577
671
 
578
- ## Logging
672
+ ### Logging
579
673
 
580
674
  Logging is disabled by default, it can be enabled by setting a logger instance and a logging severity.
581
675
 
@@ -594,7 +688,7 @@ Logger.new('logfile.log')
594
688
 
595
689
  The default severity is set to INFO and logs only the request attributes (headers, parameters and url). Setting it to DEBUG will also log the raw JSON response.
596
690
 
597
- ## Raise Errors
691
+ ### Raise Errors
598
692
 
599
693
  If `:raise_errors` is set to true, an Exception will be raised in case of an error. The default is false, in this case a ```Contentful::Management::Error``` object will be returned.
600
694
 
@@ -602,7 +696,7 @@ If `:raise_errors` is set to true, an Exception will be raised in case of an err
602
696
  client = Contentful::Management::Client.new('access_token', raise_errors: true)
603
697
  ```
604
698
 
605
- ## Content Type Cache
699
+ ### Content Type Cache
606
700
 
607
701
  This allows for fetching Content Types for your Space at Client instantiation time, which prevents extra requests per Entry.
608
702
  To enable this, in your Client instantiation do:
@@ -613,7 +707,7 @@ client = Contentful::Management::Client.new(token, dynamic_entries: ['my_space_i
613
707
 
614
708
  You can enable the Cache for as many Spaces as you want.
615
709
 
616
- ## Proxy Support
710
+ ### Proxy Support
617
711
 
618
712
  This allows for using the CMA SDK through a proxy, for this, your proxy must support HTTPS and your server must have a valid signed certificate.
619
713