class Contentful::Management::ApiKey

Resource class for ApiKey. @see _ www.contentful.com/developers/docs/references/content-management-api/#/reference/api-keys

Public Class Methods

create(client, space_id, attributes = {}) click to toggle source

Creates an API Key.

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

@return [Contentful::Management::ApiKey]

Calls superclass method
# File lib/contentful/management/api_key.rb, line 36
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/api_key.rb, line 20
def self.create_attributes(_client, attributes)
  {
    'name' => attributes.fetch(:name),
    'description' => attributes.fetch(:description, nil),
    'environments' => attributes.fetch(:environments, []) # Will default to master if empty
  }
end
find(client, space_id, api_key_id) click to toggle source

Finds an API Key by ID.

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

@return [Contentful::Management::ApiKey]

Calls superclass method
# File lib/contentful/management/api_key.rb, line 47
def self.find(client, space_id, api_key_id)
  super(client, space_id, nil, api_key_id)
end

Public Instance Methods

environments() click to toggle source

Returns the environment links associated to this Api Key

# File lib/contentful/management/api_key.rb, line 52
def environments
  properties[:environments].map { |environment| Link.new(environment, nil, client) }
end
preview_api_key() click to toggle source

Finds the Preview API Key associated to this API Key

@return [Contentful::Management::PreviewApiKey]

# File lib/contentful/management/api_key.rb, line 59
def preview_api_key
  client.preview_api_keys(space.id).find(properties[:preview_api_key].id)
end

Protected Instance Methods

query_attributes(attributes) click to toggle source
# File lib/contentful/management/api_key.rb, line 65
def query_attributes(attributes)
  self.class.create_attributes(
    nil,
    {
      name: name,
      description: description,
      environments: environments
    }.merge(attributes)
  )
end