class Contentful::Management::Space

Resource class for Space. @see _ www.contentful.com/developers/documentation/content-management-api/#resources-spaces

Public Class Methods

all(client, query = {}) click to toggle source

Gets all Spaces

@param [Contentful::Management::Client] client

@return [Contentful::Management::Array<Contentful::Management::Space>]

# File lib/contentful/management/space.rb, line 42
def self.all(client, query = {})
  ClientSpaceMethodsFactory.new(client).all(query)
end
build_endpoint(endpoint_options) click to toggle source

@private

# File lib/contentful/management/space.rb, line 31
def self.build_endpoint(endpoint_options)
  return "spaces/#{endpoint_options[:space_id]}" if endpoint_options.key?(:space_id)

  'spaces'
end
create(client, attributes) click to toggle source

Create a space.

@param [Contentful::Management::Client] client @param [Hash] attributes @option attributes [String] :name @option attributes [String] :default_locale @option attributes [String] :organization_id Required if user has more than one organization

@return [Contentful::Management::Space]

# File lib/contentful/management/space.rb, line 76
def self.create(client, attributes)
  ResourceRequester.new(client, self).create({}, attributes)
end
create_attributes(client, attributes) click to toggle source

@private

# File lib/contentful/management/space.rb, line 57
def self.create_attributes(client, attributes)
  default_locale = attributes[:default_locale] || client.default_locale
  { 'name' => attributes.fetch(:name), defaultLocale: default_locale }
end
create_headers(_client, attributes) click to toggle source

@private

# File lib/contentful/management/space.rb, line 63
def self.create_headers(_client, attributes)
  { organization_id: attributes[:organization_id] }
end
find(client, space_id) click to toggle source

Gets a specific space.

@param [Contentful::Management::Client] client @param [String] space_id

@return [Contentful::Management::Space]

# File lib/contentful/management/space.rb, line 52
def self.find(client, space_id)
  ClientSpaceMethodsFactory.new(client).find(space_id)
end

Public Instance Methods

api_keys() click to toggle source

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 _ README for details.

@return [Contentful::Management::SpaceApiKeyMethodsFactory]

# File lib/contentful/management/space.rb, line 131
def api_keys
  SpaceApiKeyMethodsFactory.new(self)
end
destroy() click to toggle source

Destroys a space.

@return [true, Contentful::Management::Error] success

# File lib/contentful/management/space.rb, line 113
def destroy
  ResourceRequester.new(client, self.class).destroy(space_id: id)
end
environments() click to toggle source

Allows manipulation of environments in context of the current space Allows listing all environments of space, creating new and finding one by ID. @see _ README for details.

@return [Contentful::Management::SpaceEnvironmentMethodsFactory]

# File lib/contentful/management/space.rb, line 122
def environments
  SpaceEnvironmentMethodsFactory.new(self)
end
preview_api_keys() click to toggle source

Allows manipulation of preview api keys in context of the current space Allows listing all api keys of space and finding one by ID. @see _ README for details.

@return [Contentful::Management::SpacePreviewApiKeyMethodsFactory]

# File lib/contentful/management/space.rb, line 140
def preview_api_keys
  SpacePreviewApiKeyMethodsFactory.new(self)
end
roles() click to toggle source

Allows manipulation of roles in context of the current space Allows listing all roles of space, creating new and finding one by ID. @see _ README for details.

@return [Contentful::Management::SpaceRoleMethodsFactory]

# File lib/contentful/management/space.rb, line 158
def roles
  SpaceRoleMethodsFactory.new(self)
end
save() click to toggle source

If a space is new, an object gets created in the Contentful, otherwise the existing space gets updated. @see _ README for details.

@return [Contentful::Management::Space]

# File lib/contentful/management/space.rb, line 101
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_memberships() click to toggle source

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. @see _ README for details.

@return [Contentful::Management::SpaceSpaceMembershipMethodsFactory]

# File lib/contentful/management/space.rb, line 149
def space_memberships
  SpaceSpaceMembershipMethodsFactory.new(self)
end
update(attributes) click to toggle source

Updates a space.

@param [Hash] attributes @option attributes [String] :name @option attributes [String] :organization_id Required if user has more than one organization

@return [Contentful::Management::Space]

# File lib/contentful/management/space.rb, line 87
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
users() click to toggle source

Allows viewing of users in context of the current space Allows listing all users of space, and finding one by ID. @see _ README for details.

@return [Contentful::Management::SpaceUserMethodsFactory]

# File lib/contentful/management/space.rb, line 167
def users
  SpaceUserMethodsFactory.new(self)
end
webhooks() click to toggle source

Allows manipulation of webhooks in context of the current space Allows listing all webhooks for space and finding one by ID. @see _ README for details.

@return [Contentful::Management::SpaceWebhookMethodsFactory]

# File lib/contentful/management/space.rb, line 176
def webhooks
  SpaceWebhookMethodsFactory.new(self)
end

Protected Instance Methods

query_attributes(attributes) click to toggle source
# File lib/contentful/management/space.rb, line 182
def query_attributes(attributes)
  {
    name: name
  }.merge(attributes)
end
refresh_find() click to toggle source
# File lib/contentful/management/space.rb, line 188
def refresh_find
  self.class.find(client, id)
end