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.



28
29
30
# File 'lib/contentful/management/space.rb', line 28

def found_locale
  @found_locale
end

Class Method Details

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

Gets all Spaces



41
42
43
# File 'lib/contentful/management/space.rb', line 41

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

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

Create a space.

Options Hash (attributes):

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

    Required if user has more than one organization



80
81
82
# File 'lib/contentful/management/space.rb', line 80

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

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

Gets a specific space.



51
52
53
# File 'lib/contentful/management/space.rb', line 51

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.

See Also:

  • README for details.


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

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.

See Also:

  • README for details.


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

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.

See Also:

  • README for details.


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

def content_types
  SpaceContentTypeMethodsFactory.new(self)
end

#default_localeString

Retrieves Default Locale for current Space and leaves it cached



178
179
180
# File 'lib/contentful/management/space.rb', line 178

def default_locale
  self.found_locale ||= find_locale
end

#destroytrue, Contentful::Management::Error

Destroys a space.



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

def destroy
  ResourceRequester.new(client, self.class).destroy(space_id: id)
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.

See Also:

  • README for details.


162
163
164
# File 'lib/contentful/management/space.rb', line 162

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



186
187
188
189
190
# File 'lib/contentful/management/space.rb', line 186

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.

See Also:

  • README for details.


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

def locales
  SpaceLocaleMethodsFactory.new(self)
end

#saveContentful::Management::Space

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

See Also:

  • README for details.


105
106
107
108
109
110
111
112
# File 'lib/contentful/management/space.rb', line 105

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.

Options Hash (attributes):

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

    Required if user has more than one organization



91
92
93
94
95
96
97
98
99
# File 'lib/contentful/management/space.rb', line 91

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.

See Also:

  • README for details.


171
172
173
# File 'lib/contentful/management/space.rb', line 171

def webhooks
  SpaceWebhookMethodsFactory.new(self)
end