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 collapse

Attributes included from Resource::SystemProperties

#sys

Attributes included from Resource

#client, #properties, #raw_object, #request

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resource::Refresher

#reload

Methods included from Resource

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

Instance Attribute Details

#found_localeObject

Returns the value of attribute found_locale.



32
33
34
# File 'lib/contentful/management/space.rb', line 32

def found_locale
  @found_locale
end

Class Method Details

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

Gets all Spaces



45
46
47
# File 'lib/contentful/management/space.rb', line 45

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:



84
85
86
# File 'lib/contentful/management/space.rb', line 84

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:



55
56
57
# File 'lib/contentful/management/space.rb', line 55

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.


139
140
141
# File 'lib/contentful/management/space.rb', line 139

def api_keys
  SpaceApiKeyMethodsFactory.new(self)
end

#assetsContentful::Management::SpaceAssetMethodsFactory

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

Returns:

  • (Contentful::Management::SpaceAssetMethodsFactory)

See Also:

  • README for details.


175
176
177
# File 'lib/contentful/management/space.rb', line 175

def assets
  SpaceAssetMethodsFactory.new(self)
end

#content_typesContentful::Management::SpaceContentTypeMethodsFactory

Allows manipulation of content types in context of the current space Allows listing all content types of space, creating new and finding one by id.

Returns:

  • (Contentful::Management::SpaceContentTypeMethodsFactory)

See Also:

  • README for details.


130
131
132
# File 'lib/contentful/management/space.rb', line 130

def content_types
  SpaceContentTypeMethodsFactory.new(self)
end

#default_localeString

Retrieves Default Locale for current Space and leaves it cached

Returns:

  • (String)


200
201
202
# File 'lib/contentful/management/space.rb', line 200

def default_locale
  self.found_locale ||= find_locale
end

#destroytrue, Contentful::Management::Error

Destroys a space.

Returns:



121
122
123
# File 'lib/contentful/management/space.rb', line 121

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

#editor_interfacesContentful::Management::SpaceEditorInterfaceMethodsFactory

Allows manipulation of editor interfaces in context of the current space Allows listing all editor interfaces of space, creating new and finding one by id.

Returns:

  • (Contentful::Management::SpaceEditorInterfaceMethodsFactory)

See Also:

  • README for details.


166
167
168
# File 'lib/contentful/management/space.rb', line 166

def editor_interfaces
  SpaceEditorInterfaceMethodsFactory.new(self)
end

#entriesContentful::Management::SpaceEntryMethodsFactory

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

Returns:

  • (Contentful::Management::SpaceEntryMethodsFactory)

See Also:

  • README for details.


184
185
186
# File 'lib/contentful/management/space.rb', line 184

def entries
  SpaceEntryMethodsFactory.new(self)
end

#find_localeString

Finds Default Locale Code for current Space This request makes an API call to the Locale endpoint

Returns:

  • (String)


208
209
210
211
212
# File 'lib/contentful/management/space.rb', line 208

def find_locale
  locale = locales.all.detect(&:default)
  return locale.code unless locale.nil?
  @default_locale
end

#localesContentful::Management::SpaceLocaleMethodsFactory

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

Returns:

  • (Contentful::Management::SpaceLocaleMethodsFactory)

See Also:

  • README for details.


148
149
150
# File 'lib/contentful/management/space.rb', line 148

def locales
  SpaceLocaleMethodsFactory.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.


157
158
159
# File 'lib/contentful/management/space.rb', line 157

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.


109
110
111
112
113
114
115
116
# File 'lib/contentful/management/space.rb', line 109

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

#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:



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

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.


193
194
195
# File 'lib/contentful/management/space.rb', line 193

def webhooks
  SpaceWebhookMethodsFactory.new(self)
end