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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +15 -0
- data/README.md +209 -41
- data/contentful-management.gemspec +1 -1
- data/lib/contentful/management/asset.rb +1 -1
- data/lib/contentful/management/client.rb +155 -31
- data/lib/contentful/management/client_organization_methods_factory.rb +23 -0
- data/lib/contentful/management/client_personal_access_tokens_methods_factory.rb +27 -0
- data/lib/contentful/management/client_snapshot_methods_factory.rb +16 -6
- data/lib/contentful/management/client_space_membership_methods_factory.rb +15 -0
- data/lib/contentful/management/client_ui_extension_methods_factory.rb +15 -0
- data/lib/contentful/management/client_user_methods_factory.rb +27 -0
- data/lib/contentful/management/client_webhook_call_methods_factory.rb +30 -0
- data/lib/contentful/management/client_webhook_health_methods_factory.rb +27 -0
- data/lib/contentful/management/content_type.rb +10 -0
- data/lib/contentful/management/content_type_snapshot_methods_factory.rb +35 -0
- data/lib/contentful/management/editor_interface.rb +1 -1
- data/lib/contentful/management/organization.rb +20 -0
- data/lib/contentful/management/personal_access_token.rb +45 -0
- data/lib/contentful/management/request.rb +0 -1
- data/lib/contentful/management/resource.rb +4 -2
- data/lib/contentful/management/resource_builder.rb +15 -0
- data/lib/contentful/management/snapshot.rb +31 -20
- data/lib/contentful/management/space.rb +32 -10
- data/lib/contentful/management/space_membership.rb +43 -0
- data/lib/contentful/management/space_space_membership_methods_factory.rb +15 -0
- data/lib/contentful/management/space_ui_extension_methods_factory.rb +15 -0
- data/lib/contentful/management/ui_extension.rb +106 -0
- data/lib/contentful/management/user.rb +28 -0
- data/lib/contentful/management/version.rb +1 -1
- data/lib/contentful/management/webhook.rb +20 -0
- data/lib/contentful/management/webhook_call.rb +77 -0
- data/lib/contentful/management/webhook_health.rb +79 -0
- data/lib/contentful/management/webhook_webhook_call_methods_factory.rb +30 -0
- data/lib/contentful/management/webhook_webhook_health_methods_factory.rb +28 -0
- data/spec/fixtures/vcr_cassettes/get_request.yml +34 -17
- data/spec/fixtures/vcr_cassettes/organization/all.yml +100 -0
- data/spec/fixtures/vcr_cassettes/personal_access_token/all.yml +101 -0
- data/spec/fixtures/vcr_cassettes/personal_access_token/create.yml +94 -0
- data/spec/fixtures/vcr_cassettes/personal_access_token/find.yml +91 -0
- data/spec/fixtures/vcr_cassettes/personal_access_token/find_not_found.yml +88 -0
- data/spec/fixtures/vcr_cassettes/personal_access_token/revoke.yml +179 -0
- data/spec/fixtures/vcr_cassettes/snapshot/ct_all.yml +207 -0
- data/spec/fixtures/vcr_cassettes/snapshot/ct_find.yml +198 -0
- data/spec/fixtures/vcr_cassettes/snapshot/ct_find_not_found.yml +94 -0
- data/spec/fixtures/vcr_cassettes/space/all_disabled_cache.yml +428 -0
- data/spec/fixtures/vcr_cassettes/space/disabled_cache.yml +120 -0
- data/spec/fixtures/vcr_cassettes/space_memberships/all.yml +190 -0
- data/spec/fixtures/vcr_cassettes/space_memberships/create.yml +143 -0
- data/spec/fixtures/vcr_cassettes/space_memberships/delete.yml +322 -0
- data/spec/fixtures/vcr_cassettes/space_memberships/find.yml +141 -0
- data/spec/fixtures/vcr_cassettes/ui_extension/all.yml +1020 -0
- data/spec/fixtures/vcr_cassettes/ui_extension/create.yml +133 -0
- data/spec/fixtures/vcr_cassettes/ui_extension/delete.yml +291 -0
- data/spec/fixtures/vcr_cassettes/ui_extension/find.yml +126 -0
- data/spec/fixtures/vcr_cassettes/user/find.yml +96 -0
- data/spec/fixtures/vcr_cassettes/webhook_call/all.yml +151 -0
- data/spec/fixtures/vcr_cassettes/webhook_call/find.yml +88 -0
- data/spec/fixtures/vcr_cassettes/webhook_call/find_not_found.yml +93 -0
- data/spec/fixtures/vcr_cassettes/webhook_health/find.yml +111 -0
- data/spec/lib/contentful/management/client_spec.rb +25 -26
- data/spec/lib/contentful/management/entry_spec.rb +48 -48
- data/spec/lib/contentful/management/organization_spec.rb +33 -0
- data/spec/lib/contentful/management/personal_access_token_spec.rb +85 -0
- data/spec/lib/contentful/management/snapshot_spec.rb +134 -47
- data/spec/lib/contentful/management/space_membership_spec.rb +147 -0
- data/spec/lib/contentful/management/space_spec.rb +35 -1
- data/spec/lib/contentful/management/ui_extension_spec.rb +276 -0
- data/spec/lib/contentful/management/user_spec.rb +52 -0
- data/spec/lib/contentful/management/webhook_calls_spec.rb +69 -0
- data/spec/lib/contentful/management/webhook_health_spec.rb +51 -0
- metadata +88 -8
- data/lib/contentful/management/http_client.rb +0 -89
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative 'resource'
|
2
|
+
|
3
|
+
module Contentful
|
4
|
+
module Management
|
5
|
+
# Resource class for Space Membership.
|
6
|
+
class SpaceMembership
|
7
|
+
include Contentful::Management::Resource
|
8
|
+
include Contentful::Management::Resource::SystemProperties
|
9
|
+
include Contentful::Management::Resource::Refresher
|
10
|
+
|
11
|
+
property :admin, :boolean
|
12
|
+
property :roles, :array
|
13
|
+
property :user, Link
|
14
|
+
|
15
|
+
# Returns the list of roles for this membership.
|
16
|
+
def roles
|
17
|
+
(properties[:roles] || []).map { |r| r.is_a?(Link) ? r : Link.new(r, nil, client) }
|
18
|
+
end
|
19
|
+
|
20
|
+
# @private
|
21
|
+
def self.clean_roles(roles)
|
22
|
+
roles.map { |r| r.is_a?(Link) ? r.raw_object : r }
|
23
|
+
end
|
24
|
+
|
25
|
+
# @private
|
26
|
+
def self.create_attributes(_client, attributes)
|
27
|
+
{
|
28
|
+
'admin' => attributes['admin'] || attributes.fetch(:admin),
|
29
|
+
'roles' => clean_roles(attributes['roles'] || attributes.fetch(:roles)),
|
30
|
+
'email' => attributes['email'] || attributes.fetch(:email)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
# @private
|
35
|
+
def query_attributes(attributes)
|
36
|
+
{
|
37
|
+
'admin' => attributes['admin'] || attributes[:admin],
|
38
|
+
'roles' => self.class.clean_roles(attributes['roles'] || attributes[:roles])
|
39
|
+
}.reject { |_k, v| v.nil? }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative 'space_association_methods_factory'
|
2
|
+
|
3
|
+
module Contentful
|
4
|
+
module Management
|
5
|
+
# Wrapper for Space Membership API for usage from within Space
|
6
|
+
# @private
|
7
|
+
class SpaceSpaceMembershipMethodsFactory
|
8
|
+
include Contentful::Management::SpaceAssociationMethodsFactory
|
9
|
+
|
10
|
+
def new(*)
|
11
|
+
fail 'Not supported'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative 'space_association_methods_factory'
|
2
|
+
|
3
|
+
module Contentful
|
4
|
+
module Management
|
5
|
+
# Wrapper for UI Extension API for usage from within Space
|
6
|
+
# @private
|
7
|
+
class SpaceUIExtensionMethodsFactory
|
8
|
+
include Contentful::Management::SpaceAssociationMethodsFactory
|
9
|
+
|
10
|
+
def new(*)
|
11
|
+
fail 'Not supported'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require_relative 'resource'
|
2
|
+
|
3
|
+
module Contentful
|
4
|
+
module Management
|
5
|
+
# Resource class for UIExtension.
|
6
|
+
# @see _ https://www.contentful.com/developers/docs/references/content-management-api/#/reference/ui-extensions
|
7
|
+
class UIExtension
|
8
|
+
include Contentful::Management::Resource
|
9
|
+
include Contentful::Management::Resource::SystemProperties
|
10
|
+
include Contentful::Management::Resource::Refresher
|
11
|
+
|
12
|
+
property :extension, :hash
|
13
|
+
|
14
|
+
# @private
|
15
|
+
def self.endpoint
|
16
|
+
'extensions'
|
17
|
+
end
|
18
|
+
|
19
|
+
# @private
|
20
|
+
def self.create_attributes(_client, attributes)
|
21
|
+
extension = attributes['extension'] || attributes[:extension]
|
22
|
+
|
23
|
+
fail 'Invalid UI Extension attributes' unless valid_extension(extension)
|
24
|
+
|
25
|
+
{ 'extension' => extension }
|
26
|
+
end
|
27
|
+
|
28
|
+
# @private
|
29
|
+
def self.valid_extension(extension)
|
30
|
+
return false unless extension.key?('name')
|
31
|
+
return false unless extension.key?('fieldTypes') && extension['fieldTypes'].is_a?(::Array)
|
32
|
+
return false unless extension.key?('src') || extension.key?('srcdoc')
|
33
|
+
return false if extension.key?('sidebar') && ![false, true].include?(extension['sidebar'])
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
# If an extension is a new object gets created in the Contentful, otherwise the existing extension gets updated.
|
38
|
+
# @see _ https://github.com/contentful/contentful-management.rb for details.
|
39
|
+
#
|
40
|
+
# @return [Contentful::Management::UIExtension]
|
41
|
+
def save
|
42
|
+
self.class.valid_extension(extension)
|
43
|
+
if id
|
44
|
+
update(extension: extension)
|
45
|
+
else
|
46
|
+
new_instance = self.class.create(client, sys[:space].id, extension: extension)
|
47
|
+
refresh_data(new_instance)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns extension name
|
52
|
+
# @return [String] name
|
53
|
+
def name
|
54
|
+
extension['name']
|
55
|
+
end
|
56
|
+
|
57
|
+
# Sets extension name
|
58
|
+
# @param [String] value
|
59
|
+
def name=(value)
|
60
|
+
extension['name'] = value
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns extension field types
|
64
|
+
# @return [Array<String>] field types
|
65
|
+
def field_types
|
66
|
+
extension['fieldTypes']
|
67
|
+
end
|
68
|
+
|
69
|
+
# Sets extension field types
|
70
|
+
# @param [Array<String>] values
|
71
|
+
def field_types=(values)
|
72
|
+
extension['fieldTypes'] = values
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns extension source URL or data
|
76
|
+
# @return [String] source URL or data
|
77
|
+
def source
|
78
|
+
extension['src'] || extension['srcdoc']
|
79
|
+
end
|
80
|
+
|
81
|
+
# Sets extension source
|
82
|
+
# @param [String] value URL or data
|
83
|
+
def source=(value)
|
84
|
+
if value.start_with?('http')
|
85
|
+
extension['src'] = value
|
86
|
+
extension.delete('srcdoc')
|
87
|
+
else
|
88
|
+
extension['srcdoc'] = value
|
89
|
+
extension.delete('src')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Returns if extension is on sidebar
|
94
|
+
# @return [Boolean] sidebar
|
95
|
+
def sidebar
|
96
|
+
extension['sidebar']
|
97
|
+
end
|
98
|
+
|
99
|
+
# Sets if extension is on sidebar
|
100
|
+
# @param [Boolean] value
|
101
|
+
def sidebar=(value)
|
102
|
+
extension['sidebar'] = value
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'resource'
|
2
|
+
|
3
|
+
module Contentful
|
4
|
+
module Management
|
5
|
+
# Resource class for User.
|
6
|
+
# @see _ https://www.contentful.com/developers/docs/references/content-management-api/#/reference/users
|
7
|
+
class User
|
8
|
+
include Contentful::Management::Resource
|
9
|
+
include Contentful::Management::Resource::SystemProperties
|
10
|
+
include Contentful::Management::Resource::Refresher
|
11
|
+
|
12
|
+
property :firstName, :string
|
13
|
+
property :lastName, :string
|
14
|
+
property :avatarUrl, :string
|
15
|
+
property :email, :string
|
16
|
+
property :activated, :boolean
|
17
|
+
property :signInCount, :integer
|
18
|
+
property :confirmed, :boolean
|
19
|
+
|
20
|
+
# @private
|
21
|
+
def self.build_endpoint(endpoint_options)
|
22
|
+
endpoint = '/users'
|
23
|
+
endpoint = "#{endpoint}/#{endpoint_options[:resource_id]}" if endpoint_options[:resource_id]
|
24
|
+
endpoint
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require_relative 'resource'
|
2
|
+
require_relative 'webhook_webhook_call_methods_factory'
|
3
|
+
require_relative 'webhook_webhook_health_methods_factory'
|
2
4
|
|
3
5
|
module Contentful
|
4
6
|
module Management
|
@@ -25,6 +27,24 @@ module Contentful
|
|
25
27
|
attributes.select { |key, _value| [:httpBasicUsername, :httpBasicPassword, :url, :name, :headers, :topics].include? key }
|
26
28
|
end
|
27
29
|
|
30
|
+
# Allows manipulation of webhook call details in context of the current webhook
|
31
|
+
# Allows listing all webhook call details for the webhook and finding one by ID.
|
32
|
+
# @see _ README for details.
|
33
|
+
#
|
34
|
+
# @return [Contentful::Management::WebhookWebhookCallMethodsFactory]
|
35
|
+
def webhook_calls
|
36
|
+
WebhookWebhookCallMethodsFactory.new(self)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Allows manipulation of webhook health details in context of the current webhook
|
40
|
+
# Allows listing webhook health details for the webhook.
|
41
|
+
# @see _ README for details.
|
42
|
+
#
|
43
|
+
# @return [Contentful::Management::WebhookWebhookHealthMethodsFactory]
|
44
|
+
def webhook_health
|
45
|
+
WebhookWebhookHealthMethodsFactory.new(self)
|
46
|
+
end
|
47
|
+
|
28
48
|
protected
|
29
49
|
|
30
50
|
def query_attributes(attributes)
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require_relative 'resource'
|
2
|
+
|
3
|
+
module Contentful
|
4
|
+
module Management
|
5
|
+
# Resource class for WebhookCall.
|
6
|
+
# @see _ https://www.contentful.com/developers/docs/references/content-management-api/#/reference/webhook-calls
|
7
|
+
class WebhookCall
|
8
|
+
include Contentful::Management::Resource
|
9
|
+
include Contentful::Management::Resource::SystemProperties
|
10
|
+
include Contentful::Management::Resource::Refresher
|
11
|
+
|
12
|
+
property :statusCode, :integer
|
13
|
+
property :errors, :array
|
14
|
+
property :eventType, :string
|
15
|
+
property :url, :array
|
16
|
+
property :requestAt, :date
|
17
|
+
property :responseAt, :date
|
18
|
+
property :response, :hash
|
19
|
+
property :request, :hash
|
20
|
+
|
21
|
+
# Gets all webhook call details for a webhook.
|
22
|
+
#
|
23
|
+
# @param [Contentful::Management::Client] client
|
24
|
+
# @param [String] space_id
|
25
|
+
# @param [String] webhook_id
|
26
|
+
#
|
27
|
+
# @return [Contentful::Management::Array<Contentful::Management::WebhookCall>]
|
28
|
+
def self.all(client, space_id, webhook_id)
|
29
|
+
ClientWebhookCallMethodsFactory.new(client).all(space_id, webhook_id)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Gets a webhook's call details by ID
|
33
|
+
#
|
34
|
+
# @param [Contentful::Management::Client] client
|
35
|
+
# @param [String] space_id
|
36
|
+
# @param [String] webhook_id
|
37
|
+
# @param [String] call_id
|
38
|
+
#
|
39
|
+
# @return [Contentful::Management::WebhookCall]
|
40
|
+
def self.find(client, space_id, webhook_id, call_id)
|
41
|
+
ClientWebhookCallMethodsFactory.new(client).find(space_id, webhook_id, call_id)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Not supported
|
45
|
+
def self.create(*)
|
46
|
+
fail 'Not supported'
|
47
|
+
end
|
48
|
+
|
49
|
+
# @private
|
50
|
+
def self.endpoint
|
51
|
+
'webhooks'
|
52
|
+
end
|
53
|
+
|
54
|
+
# @private
|
55
|
+
def self.build_endpoint(endpoint_options)
|
56
|
+
space_id = endpoint_options.fetch(:space_id)
|
57
|
+
webhook_id = endpoint_options.fetch(:webhook_id)
|
58
|
+
call_id = endpoint_options.fetch(:call_id, nil)
|
59
|
+
|
60
|
+
endpoint = "spaces/#{space_id}/webhooks/#{webhook_id}/calls"
|
61
|
+
endpoint = "#{endpoint}/#{call_id}" unless call_id.nil?
|
62
|
+
|
63
|
+
endpoint
|
64
|
+
end
|
65
|
+
|
66
|
+
# Not supported
|
67
|
+
def destroy
|
68
|
+
fail 'Not supported'
|
69
|
+
end
|
70
|
+
|
71
|
+
# Not supported
|
72
|
+
def update(*)
|
73
|
+
fail 'Not supported'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require_relative 'resource'
|
2
|
+
|
3
|
+
module Contentful
|
4
|
+
module Management
|
5
|
+
# Resource class for WebhookHealth.
|
6
|
+
# @see _ https://www.contentful.com/developers/docs/references/content-management-api/#/reference/webhook-calls/webhook-health
|
7
|
+
class WebhookHealth
|
8
|
+
include Contentful::Management::Resource
|
9
|
+
include Contentful::Management::Resource::SystemProperties
|
10
|
+
include Contentful::Management::Resource::Refresher
|
11
|
+
|
12
|
+
property :calls, :hash
|
13
|
+
|
14
|
+
# Gets a webhook's health details by ID
|
15
|
+
#
|
16
|
+
# @param [Contentful::Management::Client] client
|
17
|
+
# @param [String] space_id
|
18
|
+
# @param [String] webhook_id
|
19
|
+
#
|
20
|
+
# @return [Contentful::Management::WebhookHealth]
|
21
|
+
def self.find(client, space_id, webhook_id)
|
22
|
+
ClientWebhookHealthMethodsFactory.new(client).find(space_id, webhook_id)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Not supported
|
26
|
+
def self.create(*)
|
27
|
+
fail 'Not supported'
|
28
|
+
end
|
29
|
+
|
30
|
+
# Not supported
|
31
|
+
def self.all(*)
|
32
|
+
fail 'Not supported'
|
33
|
+
end
|
34
|
+
|
35
|
+
# @private
|
36
|
+
def self.endpoint
|
37
|
+
'webhooks'
|
38
|
+
end
|
39
|
+
|
40
|
+
# @private
|
41
|
+
def self.build_endpoint(endpoint_options)
|
42
|
+
space_id = endpoint_options.fetch(:space_id)
|
43
|
+
webhook_id = endpoint_options.fetch(:webhook_id)
|
44
|
+
|
45
|
+
"spaces/#{space_id}/webhooks/#{webhook_id}/health"
|
46
|
+
end
|
47
|
+
|
48
|
+
# Not supported
|
49
|
+
def destroy
|
50
|
+
fail 'Not supported'
|
51
|
+
end
|
52
|
+
|
53
|
+
# Not supported
|
54
|
+
def update(*)
|
55
|
+
fail 'Not supported'
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns the total calls made by the webhook.
|
59
|
+
def total
|
60
|
+
calls['total']
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns the amount of healthy calls made by the webhook.
|
64
|
+
def healthy
|
65
|
+
calls['healthy']
|
66
|
+
end
|
67
|
+
|
68
|
+
# Returns wether or not there was an error on the webhook calls on the last 30 days.
|
69
|
+
def errors?
|
70
|
+
total != healthy
|
71
|
+
end
|
72
|
+
|
73
|
+
# Returns whether or not all the webhook calls on the last 30 days were successful.
|
74
|
+
def healthy?
|
75
|
+
total == healthy
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative 'resource_requester'
|
2
|
+
|
3
|
+
module Contentful
|
4
|
+
module Management
|
5
|
+
# Wrapper for webhook call detail manipulation for a specific webhook.
|
6
|
+
# @private
|
7
|
+
class WebhookWebhookCallMethodsFactory
|
8
|
+
attr_reader :webhook
|
9
|
+
|
10
|
+
# @private
|
11
|
+
def initialize(webhook)
|
12
|
+
@webhook = webhook
|
13
|
+
end
|
14
|
+
|
15
|
+
# Gets all webhook call details for a specific webhook.
|
16
|
+
#
|
17
|
+
# @return [Contentful::Management::Array<Contentful::Management::WebhookCall>]
|
18
|
+
def all(_params = {})
|
19
|
+
WebhookCall.all(webhook.client, webhook.space.id, webhook.id)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Gets a webhook call detail for a specific webhook by ID.
|
23
|
+
#
|
24
|
+
# @return [Contentful::Management::WebhookCall]
|
25
|
+
def find(call_id)
|
26
|
+
WebhookCall.find(webhook.client, webhook.space.id, webhook.id, call_id)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|