contentful-management 1.8.1 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +15 -0
  4. data/README.md +209 -41
  5. data/contentful-management.gemspec +1 -1
  6. data/lib/contentful/management/asset.rb +1 -1
  7. data/lib/contentful/management/client.rb +155 -31
  8. data/lib/contentful/management/client_organization_methods_factory.rb +23 -0
  9. data/lib/contentful/management/client_personal_access_tokens_methods_factory.rb +27 -0
  10. data/lib/contentful/management/client_snapshot_methods_factory.rb +16 -6
  11. data/lib/contentful/management/client_space_membership_methods_factory.rb +15 -0
  12. data/lib/contentful/management/client_ui_extension_methods_factory.rb +15 -0
  13. data/lib/contentful/management/client_user_methods_factory.rb +27 -0
  14. data/lib/contentful/management/client_webhook_call_methods_factory.rb +30 -0
  15. data/lib/contentful/management/client_webhook_health_methods_factory.rb +27 -0
  16. data/lib/contentful/management/content_type.rb +10 -0
  17. data/lib/contentful/management/content_type_snapshot_methods_factory.rb +35 -0
  18. data/lib/contentful/management/editor_interface.rb +1 -1
  19. data/lib/contentful/management/organization.rb +20 -0
  20. data/lib/contentful/management/personal_access_token.rb +45 -0
  21. data/lib/contentful/management/request.rb +0 -1
  22. data/lib/contentful/management/resource.rb +4 -2
  23. data/lib/contentful/management/resource_builder.rb +15 -0
  24. data/lib/contentful/management/snapshot.rb +31 -20
  25. data/lib/contentful/management/space.rb +32 -10
  26. data/lib/contentful/management/space_membership.rb +43 -0
  27. data/lib/contentful/management/space_space_membership_methods_factory.rb +15 -0
  28. data/lib/contentful/management/space_ui_extension_methods_factory.rb +15 -0
  29. data/lib/contentful/management/ui_extension.rb +106 -0
  30. data/lib/contentful/management/user.rb +28 -0
  31. data/lib/contentful/management/version.rb +1 -1
  32. data/lib/contentful/management/webhook.rb +20 -0
  33. data/lib/contentful/management/webhook_call.rb +77 -0
  34. data/lib/contentful/management/webhook_health.rb +79 -0
  35. data/lib/contentful/management/webhook_webhook_call_methods_factory.rb +30 -0
  36. data/lib/contentful/management/webhook_webhook_health_methods_factory.rb +28 -0
  37. data/spec/fixtures/vcr_cassettes/get_request.yml +34 -17
  38. data/spec/fixtures/vcr_cassettes/organization/all.yml +100 -0
  39. data/spec/fixtures/vcr_cassettes/personal_access_token/all.yml +101 -0
  40. data/spec/fixtures/vcr_cassettes/personal_access_token/create.yml +94 -0
  41. data/spec/fixtures/vcr_cassettes/personal_access_token/find.yml +91 -0
  42. data/spec/fixtures/vcr_cassettes/personal_access_token/find_not_found.yml +88 -0
  43. data/spec/fixtures/vcr_cassettes/personal_access_token/revoke.yml +179 -0
  44. data/spec/fixtures/vcr_cassettes/snapshot/ct_all.yml +207 -0
  45. data/spec/fixtures/vcr_cassettes/snapshot/ct_find.yml +198 -0
  46. data/spec/fixtures/vcr_cassettes/snapshot/ct_find_not_found.yml +94 -0
  47. data/spec/fixtures/vcr_cassettes/space/all_disabled_cache.yml +428 -0
  48. data/spec/fixtures/vcr_cassettes/space/disabled_cache.yml +120 -0
  49. data/spec/fixtures/vcr_cassettes/space_memberships/all.yml +190 -0
  50. data/spec/fixtures/vcr_cassettes/space_memberships/create.yml +143 -0
  51. data/spec/fixtures/vcr_cassettes/space_memberships/delete.yml +322 -0
  52. data/spec/fixtures/vcr_cassettes/space_memberships/find.yml +141 -0
  53. data/spec/fixtures/vcr_cassettes/ui_extension/all.yml +1020 -0
  54. data/spec/fixtures/vcr_cassettes/ui_extension/create.yml +133 -0
  55. data/spec/fixtures/vcr_cassettes/ui_extension/delete.yml +291 -0
  56. data/spec/fixtures/vcr_cassettes/ui_extension/find.yml +126 -0
  57. data/spec/fixtures/vcr_cassettes/user/find.yml +96 -0
  58. data/spec/fixtures/vcr_cassettes/webhook_call/all.yml +151 -0
  59. data/spec/fixtures/vcr_cassettes/webhook_call/find.yml +88 -0
  60. data/spec/fixtures/vcr_cassettes/webhook_call/find_not_found.yml +93 -0
  61. data/spec/fixtures/vcr_cassettes/webhook_health/find.yml +111 -0
  62. data/spec/lib/contentful/management/client_spec.rb +25 -26
  63. data/spec/lib/contentful/management/entry_spec.rb +48 -48
  64. data/spec/lib/contentful/management/organization_spec.rb +33 -0
  65. data/spec/lib/contentful/management/personal_access_token_spec.rb +85 -0
  66. data/spec/lib/contentful/management/snapshot_spec.rb +134 -47
  67. data/spec/lib/contentful/management/space_membership_spec.rb +147 -0
  68. data/spec/lib/contentful/management/space_spec.rb +35 -1
  69. data/spec/lib/contentful/management/ui_extension_spec.rb +276 -0
  70. data/spec/lib/contentful/management/user_spec.rb +52 -0
  71. data/spec/lib/contentful/management/webhook_calls_spec.rb +69 -0
  72. data/spec/lib/contentful/management/webhook_health_spec.rb +51 -0
  73. metadata +88 -8
  74. data/lib/contentful/management/http_client.rb +0 -89
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46acf87204ed06a260240bf8d5e8d2c82d10e24b
4
- data.tar.gz: a67f9c680391f7c6fe02d8a2c2ec22e0062095ec
3
+ metadata.gz: fb5ebdbf246240b9eeaf315eb01fd8950cce67a4
4
+ data.tar.gz: bb20ddab6ba4bd2ee7353e2d9c5eb841027955b3
5
5
  SHA512:
6
- metadata.gz: 97075bc41a91528d432fdeaa9cae8fa1344223912df5f20d9648e2c76e91d9f463fecd3e73c61a5ad36e9f8718db96c63140ba8c4fcf2405706ab1fdc622a0c4
7
- data.tar.gz: 408b3cd6e123d7a2cc7f5cc284a84fed774b57cb84b53e93b1ef6814ff14797d38c3305c41199b0cf56dfe04b20920ff44feef6ceff3d3f54e9af4650cd6bd6f
6
+ metadata.gz: a365765f6243235b658fc34e692939687e44d7d679fde7c3a93417c64d63bb0421d5fe128d9d5df831d3370d055ae7ff7ca7530892bfdc7962a68d57b1cf1139
7
+ data.tar.gz: 978075d563968f6cca95c76d0a96ab15fb4068c13e9f7f1f8c395a93ab9ae04103760647ce21c0c4f0aaf672eb7daa1a63699b3bf032b1ff1f53798daabf8b2c
data/.rubocop.yml CHANGED
@@ -20,7 +20,7 @@ Metrics/LineLength:
20
20
  Max: 135
21
21
 
22
22
  Metrics/ClassLength:
23
- Max: 300
23
+ Max: 350
24
24
 
25
25
  Style/SignalException:
26
26
  EnforcedStyle: 'semantic'
data/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  ## Master
4
4
 
5
+ ## 1.9.0
6
+ ### Added
7
+ * Added option to disable Content Type caching completely.
8
+ * Added UI Extension Endpoint.
9
+ * Added Space Memberships Endpoint.
10
+ * Added Webhook Calls Endpoint.
11
+ * Added Webhook Health Endpoint.
12
+ * Added Content Type Snapshots Endpoint.
13
+ * Added Organizations Endpoint.
14
+ * Added User Endpoint.
15
+ * Added Personal Access Tokens Endpoint.
16
+
17
+ ### Changed
18
+ * Rewrote HTTP internals in order to allow base-level resources and simplified Client.
19
+
5
20
  ## 1.8.1
6
21
  ### Added
7
22
  * Added missing validation property for assets [#121](https://github.com/contentful/contentful-management.rb/pull/121)
data/README.md CHANGED
@@ -8,8 +8,9 @@ Contentful is a content management platform for web applications, mobile apps an
8
8
  ## Setup
9
9
 
10
10
  Add this line to your application's Gemfile:
11
-
12
- gem 'contentful-management'
11
+ ```ruby
12
+ gem 'contentful-management'
13
+ ```
13
14
 
14
15
  ## Usage
15
16
 
@@ -21,6 +22,8 @@ Some examples can be found in the ```examples/``` directory or you take a look a
21
22
  At the beginning the API client instance should be created for each thread that is going to be used in your application:
22
23
 
23
24
  ```ruby
25
+ require 'contentful/management'
26
+
24
27
  client = Contentful::Management::Client.new('access_token')
25
28
  ```
26
29
 
@@ -34,7 +37,7 @@ Retrieving all spaces:
34
37
  spaces = client.spaces.all
35
38
  ```
36
39
 
37
- Retrieving one space by id:
40
+ Retrieving one space by ID:
38
41
 
39
42
  ```ruby
40
43
  blog_space = client.spaces.find('blog_space_id')
@@ -137,7 +140,7 @@ asset.file_with_locales= {'en-US' => en_file, 'pl' => pl_file}
137
140
  asset.save
138
141
  ```
139
142
 
140
- Process an Asset file after create:
143
+ Process an asset file after create:
141
144
  ```ruby
142
145
  asset.process_file
143
146
  ```
@@ -218,7 +221,7 @@ Finding an upload:
218
221
  upload = client.uploads.find('space_id', 'upload_id')
219
222
  ```
220
223
 
221
- Deleting an upload
224
+ Deleting an upload:
222
225
 
223
226
  ```ruby
224
227
  upload.destroy
@@ -267,7 +270,7 @@ or
267
270
  entries = content_type.entries.all
268
271
  ```
269
272
 
270
- Retrieving an entry by id:
273
+ Retrieving an entry by ID:
271
274
 
272
275
  ```ruby
273
276
  entry = blog_space.entries.find('entry_id')
@@ -348,11 +351,11 @@ Checking if the entry is published:
348
351
  my_entry.published?
349
352
  ```
350
353
 
351
- > Entries created with *empty fields*, will not return those fields in the response. Therefore, Entries that don't have Cache enabled, will need to
352
- > make an extra request to fetch the Content Type and fill the missing fields.
353
- > To allow for Content Type Caching:
354
- > * Enable [Content Type Cache](#content-type-cache) at Client Instantiation time
355
- > * Query Entries through `space.entries.find` instead of `Entry.find(space_id, entry_id)`
354
+ > Entries created with *empty fields*, will not return those fields in the response. Therefore, entries that don't have cache enabled, will need to
355
+ > make an extra request to fetch the content type and fill the missing fields.
356
+ > To allow for content type caching:
357
+ > * Enable [content type cache](#content-type-cache) at client instantiation time
358
+ > * Query entries through `space.entries.find` instead of `Entry.find(space_id, entry_id)`
356
359
 
357
360
  ### Content Types
358
361
 
@@ -368,7 +371,7 @@ Retrieving all published content types from a space:
368
371
  blog_post_content_types = blog_space.content_types.all_published
369
372
  ```
370
373
 
371
- Retrieving one content type by id from a space:
374
+ Retrieving one content type by ID from a space:
372
375
 
373
376
  ```ruby
374
377
  blog_post_content_type = blog_space.content_types.find(id)
@@ -540,23 +543,26 @@ Retrieving all locales from the space:
540
543
  blog_post_locales = blog_space.locales.all
541
544
  ```
542
545
 
543
- Retrieving one locale by the locale-id from the space:
546
+ Retrieving one locale by ID from the space:
544
547
 
545
548
  ```ruby
546
549
  blog_post_locale = blog_space.locales.find(locale_id)
547
550
  ```
548
551
 
549
- Creating a locale
552
+ Creating a locale:
553
+
550
554
  ```ruby
551
555
  blog_space.locales.create(name: 'German', code: 'de-DE')
552
556
  ```
553
557
 
554
- Updating a locale
558
+ Updating a locale:
559
+
555
560
  ```ruby
556
561
  blog_post_locale.update(name: 'German', code: 'de-DE')
557
562
  ```
558
563
 
559
- Destroying a locale
564
+ Destroying a locale:
565
+
560
566
  ```ruby
561
567
  blog_post_locale.destroy
562
568
  ```
@@ -569,13 +575,14 @@ Retrieving all roles from the space:
569
575
  blog_post_roles = blog_space.roles.all
570
576
  ```
571
577
 
572
- Retrieving one role by the locale-id from the space:
578
+ Retrieving one role by ID from the space:
573
579
 
574
580
  ```ruby
575
581
  blog_post_role = blog_space.role.find(role_id)
576
582
  ```
577
583
 
578
- Creating a role
584
+ Creating a role:
585
+
579
586
  ```ruby
580
587
  role_attributes = {
581
588
  name: 'My Role',
@@ -611,12 +618,14 @@ role_attributes = {
611
618
  blog_space.roles.create(role_attributes)
612
619
  ```
613
620
 
614
- Updating a role
621
+ Updating a role:
622
+
615
623
  ```ruby
616
624
  blog_post_role.update(name: 'Some Other Role') # Can change any attribute here
617
625
  ```
618
626
 
619
- Destroying a role
627
+ Destroying a role:
628
+
620
629
  ```ruby
621
630
  blog_post_role.destroy
622
631
  ```
@@ -628,13 +637,13 @@ Retrieving all webhooks from the space:
628
637
  ```ruby
629
638
  webhooks = blog_space.webhooks.all
630
639
  ```
631
- Retrieving one webhook by the webhook-id from the space:
640
+ Retrieving one webhook by ID from the space:
632
641
 
633
642
  ```ruby
634
643
  blog_post_webhook = blog_space.webhooks.find(webhook_id)
635
644
  ```
636
645
 
637
- Creating a webhook
646
+ Creating a webhook:
638
647
 
639
648
  ```ruby
640
649
  blog_space.webhooks.create(
@@ -645,19 +654,19 @@ blog_space.webhooks.create(
645
654
  )
646
655
  ```
647
656
 
648
- Updating a webhook
657
+ Updating a webhook:
649
658
 
650
659
  ```ruby
651
660
  blog_post_webhook.update(url: 'https://www.newlink.com')
652
661
  ```
653
662
 
654
- Destroying webhook:
663
+ Destroying a webhook:
655
664
 
656
665
  ```ruby
657
666
  blog_post_webhook.destroy
658
667
  ```
659
668
 
660
- Creating a Webhook with Custom Headers and Custom Topics:
669
+ Creating a webhook with custom headers and custom topics:
661
670
 
662
671
  ```ruby
663
672
  blog_space.webhooks.create(
@@ -673,25 +682,163 @@ blog_space.webhooks.create(
673
682
  )
674
683
  ```
675
684
 
676
- ### Api Keys
685
+ #### Webhook Calls
677
686
 
678
- Retrieving all api keys from the space:
687
+ Retrieving all webhook call details from a webhook:
688
+
689
+ ```ruby
690
+ all_call_details = my_webhook.webhook_calls.all
691
+ ```
692
+ Retrieving one webhook call detail by ID from a webhook:
693
+
694
+ ```ruby
695
+ call_details = my_webhook.webhook_calls.find(call_id)
696
+ ```
697
+
698
+ #### Webhook Health
699
+
700
+ Retrieving webhook health details from a webhook:
701
+
702
+ ```ruby
703
+ health_details = my_webhook.webhook_health.find
704
+ ```
705
+
706
+ ### Space Memberships
707
+
708
+ Retrieving all space memberships from the space:
709
+
710
+ ```ruby
711
+ memberships = blog_space.space_memberships.all
712
+ ```
713
+ Retrieving one space membership by ID from the space:
714
+
715
+ ```ruby
716
+ blog_post_membership = blog_space.space_memberships.find(membership_id)
717
+ ```
718
+
719
+ Creating a space membership:
720
+
721
+ ```ruby
722
+ blog_space.space_memberships.create(
723
+ admin: false,
724
+ roles: [
725
+ {
726
+ 'sys' => {
727
+ 'type' => 'Link',
728
+ 'linkType' => 'Role',
729
+ 'id' => 'my_role_id'
730
+ }
731
+ }
732
+ ],
733
+ email: 'foobar@example.com'
734
+ )
735
+ ```
736
+
737
+ Updating a space membership:
738
+
739
+ ```ruby
740
+ blog_post_membership.update(admin: true)
741
+ ```
742
+
743
+ Destroying a space membership:
744
+
745
+ ```ruby
746
+ blog_post_membership.destroy
747
+ ```
748
+
749
+ ### Organizations
750
+
751
+ Retrieving all organization details:
752
+
753
+ ```ruby
754
+ organizations = client.organizations.all
755
+ ```
756
+
757
+ ### Users
758
+
759
+ Retrieving current user details:
760
+
761
+ ```ruby
762
+ user = client.users.me
763
+ ```
764
+
765
+ ### UI Extensions
766
+
767
+ Retrieving all UI extensions from the space:
768
+
769
+ ```ruby
770
+ extensions = blog_space.ui_extensions.all
771
+ ```
772
+ Retrieving one UI extension by ID from the space:
773
+
774
+ ```ruby
775
+ blog_post_extension = blog_space.ui_extensions.find(extension_id)
776
+ ```
777
+
778
+ Creating a UI extension:
779
+
780
+ ```ruby
781
+ blog_space.ui_extensions.create(
782
+ extension: {
783
+ 'name' => 'My extension',
784
+ 'src' => 'https://www.example.com',
785
+ 'fieldTypes' => [{"type": "Symbol"}],
786
+ 'sidebar' => false
787
+ }
788
+ )
789
+ ```
790
+
791
+ Destroying a UI extension:
792
+
793
+ ```ruby
794
+ blog_post_extension.destroy
795
+ ```
796
+
797
+ ### API Keys
798
+
799
+ Retrieving all API keys from the space:
679
800
 
680
801
  ```ruby
681
802
  blog_post_api_keys = blog_space.api_keys.all
682
803
  ```
683
804
 
684
- Retrieving one api key by the api-key-id from the space:
805
+ Retrieving one API key by ID from the space:
685
806
 
686
807
  ```ruby
687
808
  blog_post_api_key = blog_space.api_keys.find(api_key_id)
688
809
  ```
689
810
 
690
- Creating an api key
811
+ Creating an API key:
691
812
  ```ruby
692
813
  blog_space.api_keys.create(name: 'foobar key', description: 'key for foobar mobile app')
693
814
  ```
694
815
 
816
+ ### Personal Access Tokens
817
+
818
+ Retrieving all personal access tokens:
819
+
820
+ ```ruby
821
+ tokens = client.personal_access_tokens.all
822
+ ```
823
+
824
+ Retrieving one personal access token by ID:
825
+
826
+ ```ruby
827
+ token = client.personal_access_tokens.find(token_id)
828
+ ```
829
+
830
+ Creating a personal access token:
831
+
832
+ ```ruby
833
+ client.personal_access_tokens.create(name: 'foobar key', scopes: ['content_management_manage'])
834
+ ```
835
+
836
+ Revoking a personal access token:
837
+
838
+ ```ruby
839
+ token.revoke
840
+ ```
841
+
695
842
  ### Editor Interface
696
843
 
697
844
  Retrieving editor interface for a content type:
@@ -700,26 +847,40 @@ Retrieving editor interface for a content type:
700
847
  blog_post_editor_interface = blog_post_content_type.editor_interface.default
701
848
  ```
702
849
 
703
- You can call the EditorInterface API from any level within the Content Model Hierarchy, take into account that you'll need to
704
- pass the ids of the levels below it.
850
+ You can call the EditorInterface API from any level within the content model hierarchy, take into account that you'll need to
851
+ pass the IDs of the levels below it.
705
852
 
706
853
  > Hierarchy is as follows:
707
854
  > `No Object -> Space -> ContentType -> EditorInterface`
708
855
 
709
- ### Snapshots
856
+ ### Entry Snapshots
710
857
 
711
- Retrieving all Snapshot for a given Entry:
858
+ Retrieving all snapshots for a given entry:
712
859
 
713
860
  ```ruby
714
861
  snapshots = entry.snapshots.all
715
862
  ```
716
863
 
717
- Retrieving a Snapshot for a given Entry:
864
+ Retrieving a snapshot for a given entry:
718
865
 
719
866
  ```ruby
720
867
  snapshot = entry.snapshots.find('some_snapshot_id')
721
868
  ```
722
869
 
870
+ ### Content Type Snapshots
871
+
872
+ Retrieving all snapshots for a given content type:
873
+
874
+ ```ruby
875
+ snapshots = content_type.snapshots.all
876
+ ```
877
+
878
+ Retrieving a snapshot for a given content type:
879
+
880
+ ```ruby
881
+ snapshot = content_type.snapshots.find('some_snapshot_id')
882
+ ```
883
+
723
884
  ### Pagination
724
885
 
725
886
  ```ruby
@@ -757,33 +918,40 @@ client = Contentful::Management::Client.new('access_token', raise_errors: true)
757
918
 
758
919
  ### Content Type Cache
759
920
 
760
- This allows for fetching Content Types for your Space at Client instantiation time, which prevents extra requests per Entry.
761
- To enable this, in your Client instantiation do:
921
+ This allows for fetching content types for your space at client instantiation time, which prevents extra requests per entry.
922
+ To enable this, in your client instantiation do:
762
923
 
763
924
  ```ruby
764
925
  client = Contentful::Management::Client.new(token, dynamic_entries: ['my_space_id'])
765
926
  ```
766
927
 
767
- You can enable the Cache for as many Spaces as you want.
928
+ You can enable the cache for as many spaces as you want. If no space is added, content types will be fetched upon space find.
929
+
930
+ To completely disable this feature, upon client instantiation do:
931
+
932
+ ```ruby
933
+ client = Contentful::Management::Client.new(token, disable_content_type_caching: true)
934
+ ```
768
935
 
769
936
  ### Proxy Support
770
937
 
771
938
  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.
772
939
 
773
- To enable this, in your Client instantiation do:
940
+ To enable this, in your client instantiation do:
941
+
774
942
 
775
943
  ```ruby
776
944
  PROXY_HOST = 'localhost'
777
945
  PROXY_PORT = 8888
778
946
 
779
- # Just Host/Port
947
+ # Just host/port
780
948
  client = Contributing::Management::Client.new(
781
949
  token,
782
950
  proxy_host: PROXY_HOST,
783
951
  proxy_port: PROXY_PORT
784
952
  )
785
953
 
786
- # With Username/Password
954
+ # With username/password
787
955
  client = Contributing::Management::Client.new(
788
956
  token,
789
957
  proxy_host: PROXY_HOST,
@@ -793,7 +961,7 @@ client = Contributing::Management::Client.new(
793
961
  )
794
962
  ```
795
963
 
796
- # Rate Limit Management
964
+ # Rate limit management
797
965
 
798
966
  With the following configuration options you can handle how rate limits are handled within your applications.
799
967