contentful-management 3.11.0 → 3.12.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.
- checksums.yaml +4 -4
- data/.github/workflows/codeql.yml +32 -0
- data/CHANGELOG.md +3 -0
- data/README.md +127 -1
- data/lib/contentful/management/client.rb +27 -0
- data/lib/contentful/management/client_taxonomy_concept_methods_factory.rb +34 -0
- data/lib/contentful/management/client_taxonomy_concept_scheme_methods_factory.rb +34 -0
- data/lib/contentful/management/content_type.rb +3 -0
- data/lib/contentful/management/resource/metadata.rb +8 -1
- data/lib/contentful/management/resource_builder.rb +5 -1
- data/lib/contentful/management/resource_requester.rb +11 -0
- data/lib/contentful/management/taxonomy_concept.rb +144 -0
- data/lib/contentful/management/taxonomy_concept_scheme.rb +108 -0
- data/lib/contentful/management/version.rb +1 -1
- data/spec/fixtures/vcr_cassettes/asset/update_with_concepts.yml +137 -0
- data/spec/fixtures/vcr_cassettes/content_type/update_with_metadata.yml +171 -0
- data/spec/fixtures/vcr_cassettes/entry/update_with_concepts.yml +182 -0
- data/spec/fixtures/vcr_cassettes/taxonomy_concept/all.yml +83 -0
- data/spec/fixtures/vcr_cassettes/taxonomy_concept/ancestors.yml +155 -0
- data/spec/fixtures/vcr_cassettes/taxonomy_concept/create.yml +77 -0
- data/spec/fixtures/vcr_cassettes/taxonomy_concept/create_with_id.yml +78 -0
- data/spec/fixtures/vcr_cassettes/taxonomy_concept/descendants.yml +153 -0
- data/spec/fixtures/vcr_cassettes/taxonomy_concept/destroy.yml +152 -0
- data/spec/fixtures/vcr_cassettes/taxonomy_concept/find.yml +79 -0
- data/spec/fixtures/vcr_cassettes/taxonomy_concept/total.yml +77 -0
- data/spec/fixtures/vcr_cassettes/taxonomy_concept/update.yml +158 -0
- data/spec/fixtures/vcr_cassettes/taxonomy_concept_scheme/all.yml +80 -0
- data/spec/fixtures/vcr_cassettes/taxonomy_concept_scheme/create.yml +78 -0
- data/spec/fixtures/vcr_cassettes/taxonomy_concept_scheme/destroy.yml +150 -0
- data/spec/fixtures/vcr_cassettes/taxonomy_concept_scheme/find.yml +78 -0
- data/spec/fixtures/vcr_cassettes/taxonomy_concept_scheme/total.yml +77 -0
- data/spec/fixtures/vcr_cassettes/taxonomy_concept_scheme/update.yml +155 -0
- data/spec/lib/contentful/management/asset_spec.rb +20 -0
- data/spec/lib/contentful/management/content_type_spec.rb +22 -0
- data/spec/lib/contentful/management/entry_spec.rb +22 -1
- data/spec/lib/contentful/management/taxonomy_concept_scheme_spec.rb +85 -0
- data/spec/lib/contentful/management/taxonomy_concept_spec.rb +116 -0
- metadata +46 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d3d63b88cb40993d64e55a0f9a50989a3e99963891555c7e68da940808147c7d
|
|
4
|
+
data.tar.gz: 7e246681551ffdfce7d5382cf614d95b5e0c556c577aab035ca82ba3eae56510
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4b3951f8ea5f59c913ff237226bba6570905312267b36088bd011fbf07e8befe2b4edf4d8e5561a1c35db5b094bc303488b8581b092e89e5a9ba6ade2df70173
|
|
7
|
+
data.tar.gz: 2fafc92979fbee9f7d28d9467f778b02b8478861055b7a55259c1b10b3ebcedc5fc6b41b74d6addc5006a9fe16a90fff388588e873651c42426d6ebd727b4b31
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "CodeQL Scan for GitHub Actions Workflows"
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
push:
|
|
6
|
+
branches: [master]
|
|
7
|
+
paths: [".github/workflows/**"]
|
|
8
|
+
pull_request:
|
|
9
|
+
branches: [master]
|
|
10
|
+
paths: [".github/workflows/**"]
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
analyze:
|
|
14
|
+
name: Analyze GitHub Actions workflows
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
permissions:
|
|
17
|
+
actions: read
|
|
18
|
+
contents: read
|
|
19
|
+
security-events: write
|
|
20
|
+
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v4
|
|
23
|
+
|
|
24
|
+
- name: Initialize CodeQL
|
|
25
|
+
uses: github/codeql-action/init@v3
|
|
26
|
+
with:
|
|
27
|
+
languages: actions
|
|
28
|
+
|
|
29
|
+
- name: Run CodeQL Analysis
|
|
30
|
+
uses: github/codeql-action/analyze@v3
|
|
31
|
+
with:
|
|
32
|
+
category: actions
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Contentful::Management
|
|
2
2
|
[](http://badge.fury.io/rb/contentful-management) [](https://app.circleci.com/pipelines/github/contentful/contentful-management.rb?branch=master)
|
|
3
3
|
|
|
4
|
-
Ruby client for the Contentful Content Management API.
|
|
4
|
+
Ruby client for the Contentful Content Management API (CMA).
|
|
5
5
|
|
|
6
6
|
[Contentful](https://www.contentful.com) provides a content infrastructure for digital teams to power content in websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship digital products faster.
|
|
7
7
|
|
|
@@ -711,6 +711,34 @@ Tagging an asset:
|
|
|
711
711
|
asset.update(_metadata: {"tags": [{ "sys": { "type": "Link", "linkType": "Tag", "id": "fooTag" } }]})
|
|
712
712
|
```
|
|
713
713
|
|
|
714
|
+
### Concepts
|
|
715
|
+
|
|
716
|
+
Adding concepts to an entry:
|
|
717
|
+
|
|
718
|
+
```ruby
|
|
719
|
+
entry.update(_metadata: {"concepts": [{ "sys": { "type": "Link", "linkType": "TaxonomyConcept", "id": "concept_id" } }]})
|
|
720
|
+
```
|
|
721
|
+
|
|
722
|
+
Adding concepts to an asset:
|
|
723
|
+
|
|
724
|
+
```ruby
|
|
725
|
+
asset.update(_metadata: {"concepts": [{ "sys": { "type": "Link", "linkType": "TaxonomyConcept", "id": "concept_id" } }]})
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
Adding concepts to a content type:
|
|
729
|
+
|
|
730
|
+
```ruby
|
|
731
|
+
content_type.update(_metadata: {"concepts": [{ "sys": { "type": "Link", "linkType": "TaxonomyConcept", "id": "concept_id" } }]})
|
|
732
|
+
```
|
|
733
|
+
|
|
734
|
+
Removing concepts from an entry, asset, or content type:
|
|
735
|
+
|
|
736
|
+
```ruby
|
|
737
|
+
entry.update(_metadata: {"concepts": [], "tags": []})
|
|
738
|
+
asset.update(_metadata: {"concepts": [], "tags": []})
|
|
739
|
+
content_type.update(_metadata: {"concepts": []})
|
|
740
|
+
```
|
|
741
|
+
|
|
714
742
|
### Roles
|
|
715
743
|
|
|
716
744
|
Retrieving all roles from the space:
|
|
@@ -972,6 +1000,104 @@ Retrieving one user by ID from the space:
|
|
|
972
1000
|
user = blog_space.users.find('user_id')
|
|
973
1001
|
```
|
|
974
1002
|
|
|
1003
|
+
### Taxonomy
|
|
1004
|
+
|
|
1005
|
+
Retrieving all concepts from an organization:
|
|
1006
|
+
|
|
1007
|
+
```ruby
|
|
1008
|
+
concepts = client.taxonomy_concepts('organization_id').all
|
|
1009
|
+
```
|
|
1010
|
+
|
|
1011
|
+
Retrieving one concept by ID from an organization:
|
|
1012
|
+
|
|
1013
|
+
```ruby
|
|
1014
|
+
concept = client.taxonomy_concepts('organization_id').find('concept_id')
|
|
1015
|
+
```
|
|
1016
|
+
|
|
1017
|
+
Creating a concept:
|
|
1018
|
+
|
|
1019
|
+
```ruby
|
|
1020
|
+
client.taxonomy_concepts('organization_id').create(prefLabel: { 'en-US' => 'Bicycles' })
|
|
1021
|
+
```
|
|
1022
|
+
|
|
1023
|
+
Creating a concept with a user-defined ID:
|
|
1024
|
+
|
|
1025
|
+
```ruby
|
|
1026
|
+
client.taxonomy_concepts('organization_id').create(id: 'my-custom-id', prefLabel: { 'en-US' => 'Bicycles' })
|
|
1027
|
+
```
|
|
1028
|
+
|
|
1029
|
+
Updating a concept:
|
|
1030
|
+
|
|
1031
|
+
```ruby
|
|
1032
|
+
concept.update([
|
|
1033
|
+
{ op: 'add', path: '/prefLabel/en-US', value: 'New Label' }
|
|
1034
|
+
])
|
|
1035
|
+
```
|
|
1036
|
+
|
|
1037
|
+
Destroying a concept:
|
|
1038
|
+
|
|
1039
|
+
```ruby
|
|
1040
|
+
concept.destroy
|
|
1041
|
+
```
|
|
1042
|
+
|
|
1043
|
+
Fetching the ancestors of a concept:
|
|
1044
|
+
|
|
1045
|
+
```ruby
|
|
1046
|
+
concept.ancestors
|
|
1047
|
+
```
|
|
1048
|
+
|
|
1049
|
+
Fetching the descendants of a concept:
|
|
1050
|
+
|
|
1051
|
+
```ruby
|
|
1052
|
+
concept.descendants
|
|
1053
|
+
```
|
|
1054
|
+
|
|
1055
|
+
Fetching the total number of concepts:
|
|
1056
|
+
|
|
1057
|
+
```ruby
|
|
1058
|
+
client.taxonomy_concepts('organization_id').total
|
|
1059
|
+
```
|
|
1060
|
+
|
|
1061
|
+
### Concept Schemes
|
|
1062
|
+
|
|
1063
|
+
Retrieving all concept schemes from an organization:
|
|
1064
|
+
|
|
1065
|
+
```ruby
|
|
1066
|
+
concept_schemes = client.taxonomy_concept_schemes('organization_id').all
|
|
1067
|
+
```
|
|
1068
|
+
|
|
1069
|
+
Retrieving one concept scheme by ID from an organization:
|
|
1070
|
+
|
|
1071
|
+
```ruby
|
|
1072
|
+
concept_scheme = client.taxonomy_concept_schemes('organization_id').find('concept_scheme_id')
|
|
1073
|
+
```
|
|
1074
|
+
|
|
1075
|
+
Updating a concept scheme:
|
|
1076
|
+
|
|
1077
|
+
```ruby
|
|
1078
|
+
concept_scheme.update([
|
|
1079
|
+
{ op: 'add', path: '/prefLabel/en-US', value: 'New Scheme Name' }
|
|
1080
|
+
])
|
|
1081
|
+
```
|
|
1082
|
+
|
|
1083
|
+
Destroying a concept scheme:
|
|
1084
|
+
|
|
1085
|
+
```ruby
|
|
1086
|
+
concept_scheme.destroy
|
|
1087
|
+
```
|
|
1088
|
+
|
|
1089
|
+
Creating a concept scheme:
|
|
1090
|
+
|
|
1091
|
+
```ruby
|
|
1092
|
+
client.taxonomy_concept_schemes('organization_id').create(prefLabel: { 'en-US' => 'New Scheme' })
|
|
1093
|
+
```
|
|
1094
|
+
|
|
1095
|
+
Fetching the total number of concept schemes:
|
|
1096
|
+
|
|
1097
|
+
```ruby
|
|
1098
|
+
client.taxonomy_concept_schemes('organization_id').total
|
|
1099
|
+
```
|
|
1100
|
+
|
|
975
1101
|
### UI Extensions
|
|
976
1102
|
|
|
977
1103
|
Retrieving all UI extensions from the environment:
|
|
@@ -35,6 +35,8 @@ require 'contentful/management/client_editor_interface_methods_factory'
|
|
|
35
35
|
require 'contentful/management/client_space_periodic_usage_methods_factory'
|
|
36
36
|
require 'contentful/management/client_personal_access_tokens_methods_factory'
|
|
37
37
|
require 'contentful/management/client_organization_periodic_usage_methods_factory'
|
|
38
|
+
require 'contentful/management/client_taxonomy_concept_methods_factory'
|
|
39
|
+
require 'contentful/management/client_taxonomy_concept_scheme_methods_factory'
|
|
38
40
|
|
|
39
41
|
module Contentful
|
|
40
42
|
module Management
|
|
@@ -152,6 +154,24 @@ module Contentful
|
|
|
152
154
|
ClientSpacePeriodicUsageMethodsFactory.new(self, organization_id)
|
|
153
155
|
end
|
|
154
156
|
|
|
157
|
+
# Allows manipulation of taxonomy concepts in context of the current client
|
|
158
|
+
# Allows listing all taxonomy concepts for client, creating new and finding one by ID.
|
|
159
|
+
# @see _ README for details.
|
|
160
|
+
#
|
|
161
|
+
# @return [Contentful::Management::ClientTaxonomyConceptMethodsFactory]
|
|
162
|
+
def taxonomy_concepts(organization_id)
|
|
163
|
+
ClientTaxonomyConceptMethodsFactory.new(self, organization_id)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Allows manipulation of taxonomy concept schemes in context of the current client
|
|
167
|
+
# Allows listing all taxonomy concept schemes for client, creating new and finding one by ID.
|
|
168
|
+
# @see _ README for details.
|
|
169
|
+
#
|
|
170
|
+
# @return [Contentful::Management::ClientTaxonomyConceptSchemeMethodsFactory]
|
|
171
|
+
def taxonomy_concept_schemes(organization_id)
|
|
172
|
+
ClientTaxonomyConceptSchemeMethodsFactory.new(self, organization_id)
|
|
173
|
+
end
|
|
174
|
+
|
|
155
175
|
# Allows viewing of users in context of the current client
|
|
156
176
|
# Allows listing all users for client.
|
|
157
177
|
# @see _ README for details.
|
|
@@ -474,6 +494,13 @@ module Contentful
|
|
|
474
494
|
end
|
|
475
495
|
end
|
|
476
496
|
|
|
497
|
+
# @private
|
|
498
|
+
def patch(request)
|
|
499
|
+
execute_request(request) do |url|
|
|
500
|
+
http_send(:patch, url, { json: request.query }, request_headers(request), proxy_parameters)
|
|
501
|
+
end
|
|
502
|
+
end
|
|
503
|
+
|
|
477
504
|
# Proxy Helper
|
|
478
505
|
#
|
|
479
506
|
# @param [Symbol] type
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'client_association_methods_factory'
|
|
4
|
+
|
|
5
|
+
module Contentful
|
|
6
|
+
module Management
|
|
7
|
+
# Wrapper for Taxonomy Concept API for usage from within Client
|
|
8
|
+
# @private
|
|
9
|
+
class ClientTaxonomyConceptMethodsFactory
|
|
10
|
+
include Contentful::Management::ClientAssociationMethodsFactory
|
|
11
|
+
|
|
12
|
+
def initialize(client, organization_id)
|
|
13
|
+
super(client)
|
|
14
|
+
@organization_id = organization_id
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def find(resource_id)
|
|
18
|
+
associated_class.find(client, @organization_id, resource_id)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def all(query = {})
|
|
22
|
+
associated_class.all(client, @organization_id, query)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def create(attributes)
|
|
26
|
+
associated_class.create(client, @organization_id, attributes)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def total
|
|
30
|
+
associated_class.total(client, @organization_id)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'client_association_methods_factory'
|
|
4
|
+
|
|
5
|
+
module Contentful
|
|
6
|
+
module Management
|
|
7
|
+
# Wrapper for Taxonomy Concept Scheme API for usage from within Client
|
|
8
|
+
# @private
|
|
9
|
+
class ClientTaxonomyConceptSchemeMethodsFactory
|
|
10
|
+
include Contentful::Management::ClientAssociationMethodsFactory
|
|
11
|
+
|
|
12
|
+
def initialize(client, organization_id)
|
|
13
|
+
super(client)
|
|
14
|
+
@organization_id = organization_id
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def find(resource_id)
|
|
18
|
+
associated_class.find(client, @organization_id, resource_id)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def all(query = {})
|
|
22
|
+
associated_class.all(client, @organization_id, query)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def create(attributes)
|
|
26
|
+
associated_class.create(client, @organization_id, attributes)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def total
|
|
30
|
+
associated_class.total(client, @organization_id)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -7,6 +7,7 @@ require_relative 'validation'
|
|
|
7
7
|
require_relative 'resource/publisher'
|
|
8
8
|
require_relative 'resource/all_published'
|
|
9
9
|
require_relative 'resource/environment_aware'
|
|
10
|
+
require_relative 'resource/metadata'
|
|
10
11
|
require_relative 'content_type_entry_methods_factory'
|
|
11
12
|
require_relative 'content_type_snapshot_methods_factory'
|
|
12
13
|
require_relative 'content_type_editor_interface_methods_factory'
|
|
@@ -37,6 +38,7 @@ module Contentful
|
|
|
37
38
|
extend Contentful::Management::Resource::AllPublished
|
|
38
39
|
include Contentful::Management::Resource::EnvironmentAware
|
|
39
40
|
include Contentful::Management::Resource::SystemProperties
|
|
41
|
+
include Contentful::Management::Resource::Metadata
|
|
40
42
|
|
|
41
43
|
property :name, :string
|
|
42
44
|
property :description, :string
|
|
@@ -170,6 +172,7 @@ module Contentful
|
|
|
170
172
|
parameters[:name] = attributes[:name] || name
|
|
171
173
|
parameters[:description] = attributes[:description] || description
|
|
172
174
|
parameters[:fields] = self.class.fields_to_nested_properties_hash(attributes[:fields] || fields)
|
|
175
|
+
parameters[:metadata] = attributes.delete(:_metadata) if attributes.key?(:_metadata)
|
|
173
176
|
|
|
174
177
|
parameters.delete_if { |_, v| v.nil? }
|
|
175
178
|
end
|
|
@@ -30,8 +30,11 @@ module Contentful
|
|
|
30
30
|
return unless object.key?('metadata')
|
|
31
31
|
|
|
32
32
|
object['metadata'].each do |key, value|
|
|
33
|
-
@_metadata[key.to_sym] =
|
|
33
|
+
@_metadata[key.to_sym] = case key
|
|
34
|
+
when 'tags'
|
|
34
35
|
coerce_tags(value)
|
|
36
|
+
when 'concepts'
|
|
37
|
+
coerce_concepts(value)
|
|
35
38
|
else
|
|
36
39
|
value
|
|
37
40
|
end
|
|
@@ -41,6 +44,10 @@ module Contentful
|
|
|
41
44
|
def coerce_tags(tags)
|
|
42
45
|
tags.map { |tag| Contentful::Management::Link.new(tag) }
|
|
43
46
|
end
|
|
47
|
+
|
|
48
|
+
def coerce_concepts(concepts)
|
|
49
|
+
concepts.map { |concept| Contentful::Management::Link.new(concept) }
|
|
50
|
+
end
|
|
44
51
|
end
|
|
45
52
|
end
|
|
46
53
|
end
|
|
@@ -28,6 +28,8 @@ require_relative 'editor_interface'
|
|
|
28
28
|
require_relative 'space_periodic_usage'
|
|
29
29
|
require_relative 'personal_access_token'
|
|
30
30
|
require_relative 'organization_periodic_usage'
|
|
31
|
+
require_relative 'taxonomy_concept'
|
|
32
|
+
require_relative 'taxonomy_concept_scheme'
|
|
31
33
|
|
|
32
34
|
module Contentful
|
|
33
35
|
module Management
|
|
@@ -62,7 +64,9 @@ module Contentful
|
|
|
62
64
|
'EditorInterface' => Contentful::Management::EditorInterface,
|
|
63
65
|
'Snapshot' => Contentful::Management::Snapshot,
|
|
64
66
|
'Upload' => Contentful::Management::Upload,
|
|
65
|
-
'Tag' => Contentful::Management::Tag
|
|
67
|
+
'Tag' => Contentful::Management::Tag,
|
|
68
|
+
'TaxonomyConcept' => Contentful::Management::TaxonomyConcept,
|
|
69
|
+
'TaxonomyConceptScheme' => Contentful::Management::TaxonomyConceptScheme
|
|
66
70
|
}.freeze
|
|
67
71
|
|
|
68
72
|
# Default Entry Mapping
|
|
@@ -54,6 +54,17 @@ module Contentful
|
|
|
54
54
|
end
|
|
55
55
|
alias unpublish unarchive
|
|
56
56
|
|
|
57
|
+
def patch(endpoint_options = {}, attributes = {}, headers = {})
|
|
58
|
+
request = Request.new(
|
|
59
|
+
client,
|
|
60
|
+
resource_class.build_endpoint(endpoint_options),
|
|
61
|
+
attributes,
|
|
62
|
+
nil,
|
|
63
|
+
headers
|
|
64
|
+
)
|
|
65
|
+
ResourceBuilder.new(client.patch(request), client).run
|
|
66
|
+
end
|
|
67
|
+
|
|
57
68
|
private
|
|
58
69
|
|
|
59
70
|
def resource_class?(object)
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'resource'
|
|
4
|
+
require_relative 'resource/system_properties'
|
|
5
|
+
require_relative 'resource/refresher'
|
|
6
|
+
|
|
7
|
+
module Contentful
|
|
8
|
+
module Management
|
|
9
|
+
# Resource class for TaxonomyConcept.
|
|
10
|
+
# https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept
|
|
11
|
+
class TaxonomyConcept
|
|
12
|
+
include Contentful::Management::Resource
|
|
13
|
+
include Contentful::Management::Resource::SystemProperties
|
|
14
|
+
include Contentful::Management::Resource::Refresher
|
|
15
|
+
|
|
16
|
+
property :uri, :string
|
|
17
|
+
property :prefLabel, :hash
|
|
18
|
+
property :altLabels, :hash
|
|
19
|
+
property :hiddenLabels, :hash
|
|
20
|
+
property :notations, :array
|
|
21
|
+
property :note, :hash
|
|
22
|
+
property :changeNote, :hash
|
|
23
|
+
property :definition, :hash
|
|
24
|
+
property :editorialNote, :hash
|
|
25
|
+
property :example, :hash
|
|
26
|
+
property :historyNote, :hash
|
|
27
|
+
property :scopeNote, :hash
|
|
28
|
+
property :broader, :array
|
|
29
|
+
property :related, :array
|
|
30
|
+
property :conceptSchemes, :array
|
|
31
|
+
|
|
32
|
+
# Finds a Taxonomy Concept by ID.
|
|
33
|
+
#
|
|
34
|
+
# @param [Contentful::Management::Client] client
|
|
35
|
+
# @param [String] organization_id
|
|
36
|
+
# @param [String] concept_id
|
|
37
|
+
#
|
|
38
|
+
# @return [Contentful::Management::TaxonomyConcept]
|
|
39
|
+
def self.find(client, organization_id, concept_id)
|
|
40
|
+
requester = ResourceRequester.new(client, self)
|
|
41
|
+
requester.find(
|
|
42
|
+
id: concept_id,
|
|
43
|
+
organization_id: organization_id
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.all(client, organization_id, query = {})
|
|
48
|
+
requester = ResourceRequester.new(client, self)
|
|
49
|
+
requester.all({ organization_id: organization_id }, query)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def self.total(client, organization_id)
|
|
53
|
+
response = client.get(
|
|
54
|
+
Request.new(
|
|
55
|
+
client,
|
|
56
|
+
build_endpoint(total: true, organization_id: organization_id)
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
response.object['total']
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def self.create(client, organization_id, attributes)
|
|
63
|
+
requester = ResourceRequester.new(client, self)
|
|
64
|
+
requester.create(
|
|
65
|
+
{
|
|
66
|
+
organization_id: organization_id,
|
|
67
|
+
id: attributes[:id]
|
|
68
|
+
}.compact,
|
|
69
|
+
attributes
|
|
70
|
+
)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# @private
|
|
74
|
+
def self.create_attributes(_client, attributes)
|
|
75
|
+
attributes
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def update(patch_operations)
|
|
79
|
+
requester = ResourceRequester.new(client, self.class)
|
|
80
|
+
requester.patch(
|
|
81
|
+
{
|
|
82
|
+
organization_id: sys[:organization].id,
|
|
83
|
+
id: id
|
|
84
|
+
},
|
|
85
|
+
patch_operations,
|
|
86
|
+
{
|
|
87
|
+
'Content-Type' => 'application/json-patch+json',
|
|
88
|
+
'X-Contentful-Version' => sys[:version].to_s
|
|
89
|
+
}
|
|
90
|
+
)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def destroy
|
|
94
|
+
requester = ResourceRequester.new(client, self.class)
|
|
95
|
+
requester.destroy(
|
|
96
|
+
{
|
|
97
|
+
organization_id: sys[:organization].id,
|
|
98
|
+
id: id
|
|
99
|
+
},
|
|
100
|
+
{},
|
|
101
|
+
{ 'X-contentful-version' => sys[:version].to_s }
|
|
102
|
+
)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def ancestors(query = {})
|
|
106
|
+
requester = ResourceRequester.new(client, self.class)
|
|
107
|
+
endpoint_options = {
|
|
108
|
+
organization_id: sys[:organization].id,
|
|
109
|
+
id: id,
|
|
110
|
+
ancestors: true
|
|
111
|
+
}
|
|
112
|
+
requester.all(endpoint_options, query)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def descendants(query = {})
|
|
116
|
+
requester = ResourceRequester.new(client, self.class)
|
|
117
|
+
endpoint_options = {
|
|
118
|
+
organization_id: sys[:organization].id,
|
|
119
|
+
id: id,
|
|
120
|
+
descendants: true
|
|
121
|
+
}
|
|
122
|
+
requester.all(endpoint_options, query)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# @private
|
|
126
|
+
def self.build_endpoint(endpoint_options = {})
|
|
127
|
+
organization_id = endpoint_options[:organization_id]
|
|
128
|
+
base_url = "organizations/#{organization_id}/taxonomy/concepts"
|
|
129
|
+
|
|
130
|
+
return "#{base_url}/total" if endpoint_options[:total]
|
|
131
|
+
|
|
132
|
+
if endpoint_options.key?(:id)
|
|
133
|
+
concept_url = "#{base_url}/#{endpoint_options[:id]}"
|
|
134
|
+
return "#{concept_url}/ancestors" if endpoint_options[:ancestors]
|
|
135
|
+
return "#{concept_url}/descendants" if endpoint_options[:descendants]
|
|
136
|
+
|
|
137
|
+
concept_url
|
|
138
|
+
else
|
|
139
|
+
base_url
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'resource'
|
|
4
|
+
require_relative 'resource/system_properties'
|
|
5
|
+
require_relative 'resource/refresher'
|
|
6
|
+
|
|
7
|
+
module Contentful
|
|
8
|
+
module Management
|
|
9
|
+
# Resource class for TaxonomyConceptScheme.
|
|
10
|
+
# https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept-scheme
|
|
11
|
+
class TaxonomyConceptScheme
|
|
12
|
+
include Contentful::Management::Resource
|
|
13
|
+
include Contentful::Management::Resource::SystemProperties
|
|
14
|
+
include Contentful::Management::Resource::Refresher
|
|
15
|
+
|
|
16
|
+
property :uri, :string
|
|
17
|
+
property :prefLabel, :hash
|
|
18
|
+
property :definition, :hash
|
|
19
|
+
property :topConcepts, :array
|
|
20
|
+
property :concepts, :array
|
|
21
|
+
property :totalConcepts, :integer
|
|
22
|
+
|
|
23
|
+
# Finds a Taxonomy Concept Scheme by ID.
|
|
24
|
+
#
|
|
25
|
+
# @param [Contentful::Management::Client] client
|
|
26
|
+
# @param [String] organization_id
|
|
27
|
+
# @param [String] concept_scheme_id
|
|
28
|
+
#
|
|
29
|
+
# @return [Contentful::Management::TaxonomyConceptScheme]
|
|
30
|
+
def self.find(client, organization_id, concept_scheme_id)
|
|
31
|
+
requester = ResourceRequester.new(client, self)
|
|
32
|
+
requester.find(
|
|
33
|
+
id: concept_scheme_id,
|
|
34
|
+
organization_id: organization_id
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.all(client, organization_id, query = {})
|
|
39
|
+
requester = ResourceRequester.new(client, self)
|
|
40
|
+
requester.all({ organization_id: organization_id }, query)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.total(client, organization_id)
|
|
44
|
+
response = client.get(
|
|
45
|
+
Request.new(
|
|
46
|
+
client,
|
|
47
|
+
build_endpoint(total: true, organization_id: organization_id)
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
response.object['total']
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.create(client, organization_id, attributes)
|
|
54
|
+
requester = ResourceRequester.new(client, self)
|
|
55
|
+
requester.create(
|
|
56
|
+
{ organization_id: organization_id },
|
|
57
|
+
attributes
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# @private
|
|
62
|
+
def self.create_attributes(_client, attributes)
|
|
63
|
+
attributes
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def update(patch_operations)
|
|
67
|
+
requester = ResourceRequester.new(client, self.class)
|
|
68
|
+
requester.patch(
|
|
69
|
+
{
|
|
70
|
+
organization_id: sys[:organization].id,
|
|
71
|
+
id: id
|
|
72
|
+
},
|
|
73
|
+
patch_operations,
|
|
74
|
+
{
|
|
75
|
+
'Content-Type' => 'application/json-patch+json',
|
|
76
|
+
'X-Contentful-Version' => sys[:version].to_s
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def destroy
|
|
82
|
+
requester = ResourceRequester.new(client, self.class)
|
|
83
|
+
requester.destroy(
|
|
84
|
+
{
|
|
85
|
+
organization_id: sys[:organization].id,
|
|
86
|
+
id: id
|
|
87
|
+
},
|
|
88
|
+
{},
|
|
89
|
+
{ 'X-Contentful-Version' => sys[:version].to_s }
|
|
90
|
+
)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# @private
|
|
94
|
+
def self.build_endpoint(endpoint_options = {})
|
|
95
|
+
organization_id = endpoint_options[:organization_id]
|
|
96
|
+
base_url = "organizations/#{organization_id}/taxonomy/concept-schemes"
|
|
97
|
+
|
|
98
|
+
return "#{base_url}/total" if endpoint_options[:total]
|
|
99
|
+
|
|
100
|
+
if endpoint_options.key?(:id)
|
|
101
|
+
"#{base_url}/#{endpoint_options[:id]}"
|
|
102
|
+
else
|
|
103
|
+
base_url
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|