class Contentful::Management::Environment

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

Public Class Methods

build_endpoint(endpoint_options) click to toggle source

@private

# File lib/contentful/management/environment.rb, line 20
def self.build_endpoint(endpoint_options)
  space_id = endpoint_options.fetch(:space_id)
  environment_id = endpoint_options.fetch(:resource_id, endpoint_options.fetch(:environment_id, nil))

  endpoint = "spaces/#{space_id}/environments"
  endpoint = "#{endpoint}/#{environment_id}" if environment_id
  endpoint
end
create(client, space_id, attributes = {}) click to toggle source

Creates an environment.

@param [Contentful::Management::Client] client @param [String] space_id @param [Hash] attributes @see _ README for full attribute list for each resource.

@return [Contentful::Management::Environment]

Calls superclass method
# File lib/contentful/management/environment.rb, line 37
def self.create(client, space_id, attributes = {})
  super(client, space_id, nil, attributes)
end
create_attributes(_client, attributes) click to toggle source

@private

# File lib/contentful/management/environment.rb, line 53
def self.create_attributes(_client, attributes)
  return {} if attributes.nil? || attributes.empty?

  {
    'name' => attributes[:name] || attributes['name']
  }
end
create_headers(_client, attributes, _instance = nil) click to toggle source

@private

# File lib/contentful/management/environment.rb, line 62
def self.create_headers(_client, attributes, _instance = nil)
  return {} unless attributes[:source_environment_id] || attributes['source_environment_id']

  {
    'X-Contentful-Source-Environment' => attributes[:source_environment_id] || attributes['source_environment_id']
  }
end
find(client, space_id, environment_id) click to toggle source

Finds an environment by ID.

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

@return [Contentful::Management::Environment]

Calls superclass method
# File lib/contentful/management/environment.rb, line 48
def self.find(client, space_id, environment_id)
  super(client, space_id, nil, environment_id)
end

Public Instance Methods

assets() click to toggle source

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

@return [Contentful::Management::EnvironmentAssetMethodsFactory]

# File lib/contentful/management/environment.rb, line 84
def assets
  EnvironmentAssetMethodsFactory.new(self)
end
content_types() click to toggle source

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

@return [Contentful::Management::EnvironmentContentTypeMethodsFactory]

# File lib/contentful/management/environment.rb, line 93
def content_types
  EnvironmentContentTypeMethodsFactory.new(self)
end
default_locale() click to toggle source

Retrieves Default Locale for current Environment and leaves it cached

@return [String]

# File lib/contentful/management/environment.rb, line 132
def default_locale
  self.found_locale ||= find_locale
end
editor_interfaces() click to toggle source

Allows manipulation of editor interfaces in context of the current environment Allows listing of editor interfaces for the current environment. @see _ README for details.

@return [Contentful::Management::EnvironmentEditorInterfaceMethodsFactory]

# File lib/contentful/management/environment.rb, line 120
def editor_interfaces
  EnvironmentEditorInterfaceMethodsFactory.new(self)
end
entries() click to toggle source

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

@return [Contentful::Management::EnvironmentEntryMethodsFactory]

# File lib/contentful/management/environment.rb, line 75
def entries
  EnvironmentEntryMethodsFactory.new(self)
end
environment_id() click to toggle source

Gets the environment ID

# File lib/contentful/management/environment.rb, line 125
def environment_id
  id
end
find_locale() click to toggle source

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

@return [String]

# File lib/contentful/management/environment.rb, line 140
def find_locale
  locale = locales.all.detect(&:default)
  return locale.code if locale

  default_locale
end
locales() click to toggle source

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

@return [Contentful::Management::EnvironmentLocaleMethodsFactory]

# File lib/contentful/management/environment.rb, line 102
def locales
  EnvironmentLocaleMethodsFactory.new(self)
end
refresh_find() click to toggle source

@private

# File lib/contentful/management/environment.rb, line 148
def refresh_find
  self.class.find(client, space.id, id)
end
ui_extensions() click to toggle source

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

@return [Contentful::Management::EnvironmentUIExtensionMethodsFactory]

# File lib/contentful/management/environment.rb, line 111
def ui_extensions
  EnvironmentUIExtensionMethodsFactory.new(self)
end

Protected Instance Methods

query_attributes(attributes) click to toggle source
# File lib/contentful/management/environment.rb, line 154
def query_attributes(attributes)
  {
    name: name
  }.merge(attributes)
end