Class: Contentful::Management::Space

Inherits:
Object
  • Object
show all
Includes:
Resource, Resource::Refresher, Resource::SystemProperties
Defined in:
lib/contentful/management/space.rb

Overview

Resource class for Space.

See Also:

  • https://www.contentful.com/developers/documentation/content-management-api/#resources-spaces

Instance Attribute Summary

Attributes included from Resource::SystemProperties

#sys

Attributes included from Resource

#client, #default_locale, #properties, #raw_object, #request

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resource::Refresher

#reload

Methods included from Resource

#array?, #environment_id, #fields, #nested_locale_fields?, #resource?, #sys

Class Method Details

.all(client) ⇒ Contentful::Management::Array<Contentful::Management::Space>

Gets all Spaces



37
38
39
# File 'lib/contentful/management/space.rb', line 37

def self.all(client)
  ClientSpaceMethodsFactory.new(client).all
end

.create(client, attributes) ⇒ Contentful::Management::Space

Create a space.

Parameters:

Options Hash (attributes):

  • :name (String)
  • :default_locale (String)
  • :organization_id (String)

    Required if user has more than one organization

Returns:



71
72
73
# File 'lib/contentful/management/space.rb', line 71

def self.create(client, attributes)
  ResourceRequester.new(client, self).create({}, attributes)
end

.find(client, space_id) ⇒ Contentful::Management::Space

Gets a specific space.

Parameters:

Returns:



47
48
49
# File 'lib/contentful/management/space.rb', line 47

def self.find(client, space_id)
  ClientSpaceMethodsFactory.new(client).find(space_id)
end

Instance Method Details

#api_keysContentful::Management::SpaceApiKeyMethodsFactory

Allows manipulation of api keys in context of the current space Allows listing all api keys of space, creating new and finding one by ID.

Returns:

  • (Contentful::Management::SpaceApiKeyMethodsFactory)

See Also:

  • README for details.


126
127
128
# File 'lib/contentful/management/space.rb', line 126

def api_keys
  SpaceApiKeyMethodsFactory.new(self)
end

#destroytrue, Contentful::Management::Error

Destroys a space.

Returns:



108
109
110
# File 'lib/contentful/management/space.rb', line 108

def destroy
  ResourceRequester.new(client, self.class).destroy(space_id: id)
end

#environmentsContentful::Management::SpaceEnvironmentMethodsFactory

Allows manipulation of environments in context of the current space Allows listing all environments of space, creating new and finding one by ID.

Returns:

  • (Contentful::Management::SpaceEnvironmentMethodsFactory)

See Also:

  • README for details.


117
118
119
# File 'lib/contentful/management/space.rb', line 117

def environments
  SpaceEnvironmentMethodsFactory.new(self)
end

#rolesContentful::Management::SpaceRoleMethodsFactory

Allows manipulation of roles in context of the current space Allows listing all roles of space, creating new and finding one by ID.

Returns:

  • (Contentful::Management::SpaceRoleMethodsFactory)

See Also:

  • README for details.


144
145
146
# File 'lib/contentful/management/space.rb', line 144

def roles
  SpaceRoleMethodsFactory.new(self)
end

#saveContentful::Management::Space

If a space is new, an object gets created in the Contentful, otherwise the existing space gets updated.

Returns:

See Also:

  • README for details.


96
97
98
99
100
101
102
103
# File 'lib/contentful/management/space.rb', line 96

def save
  if id
    update(name: name, organization_id: organization)
  else
    new_instance = self.class.create(client, name: name, organization_id: organization)
    refresh_data(new_instance)
  end
end

#space_membershipsContentful::Management::SpaceSpaceMembershipMethodsFactory

Allows manipulation of space memberships in context of the current space Allows listing all space memberships of space, creating new and finding one by ID.

Returns:

  • (Contentful::Management::SpaceSpaceMembershipMethodsFactory)

See Also:

  • README for details.


135
136
137
# File 'lib/contentful/management/space.rb', line 135

def space_memberships
  SpaceSpaceMembershipMethodsFactory.new(self)
end

#update(attributes) ⇒ Contentful::Management::Space

Updates a space.

Parameters:

  • attributes (Hash)

Options Hash (attributes):

  • :name (String)
  • :organization_id (String)

    Required if user has more than one organization

Returns:



82
83
84
85
86
87
88
89
90
# File 'lib/contentful/management/space.rb', line 82

def update(attributes)
  ResourceRequester.new(client, self.class).update(
    self,
    { space_id: id },
    { 'name' => attributes.fetch(:name) },
    version: sys[:version],
    organization_id: attributes[:organization_id]
  )
end

#webhooksContentful::Management::SpaceWebhookMethodsFactory

Allows manipulation of webhooks in context of the current space Allows listing all webhooks for space and finding one by ID.

Returns:

  • (Contentful::Management::SpaceWebhookMethodsFactory)

See Also:

  • README for details.


153
154
155
# File 'lib/contentful/management/space.rb', line 153

def webhooks
  SpaceWebhookMethodsFactory.new(self)
end