Class: Contentful::Management::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/contentful/management/client.rb

Overview

Client for interacting with the Contentful Management API

See Also:

  • https://www.contentful.com/developers/docs/references/content-management-api/

Constant Summary collapse

DEFAULT_CONFIGURATION =

Default configuration for Contentful::Management::Client

{
  api_url: 'api.contentful.com',
  uploads_url: 'upload.contentful.com',
  api_version: '1',
  secure: true,
  default_locale: 'en-US',
  gzip_encoded: false,
  logger: false,
  log_level: Logger::INFO,
  raise_errors: false,
  dynamic_entries: {},
  disable_content_type_caching: false,
  proxy_host: nil,
  proxy_port: nil,
  proxy_username: nil,
  proxy_password: nil,
  max_rate_limit_retries: 1,
  max_rate_limit_wait: 60,
  application_name: nil,
  application_version: nil,
  integration_name: nil,
  integration_version: nil
}.freeze
RATE_LIMIT_RESET_HEADER_KEY =

Rate Limit Reset Header Key

'x-contentful-ratelimit-reset'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token = nil, configuration = {}) ⇒ Client

Returns a new instance of Client.

Parameters:

  • access_token (String) (defaults to: nil)
  • configuration (Hash) (defaults to: {})

Options Hash (configuration):

  • :api_url (String)
  • :api_version (String)
  • :default_locale (String)
  • :gzip_encoded (Boolean)
  • :logger (false, ::Logger)
  • :log_level (::Logger::DEBUG, ::Logger::INFO, ::Logger::WARN, ::Logger::ERROR)
  • :raise_errors (Boolean)
  • :dynamic_entries (::Array<String>)
  • :disable_content_type_caching (Boolean)
  • :proxy_host (String)
  • :proxy_port (Fixnum)
  • :proxy_username (String)
  • :proxy_username (String)
  • :application_name (String)
  • :application_version (String)
  • :integration_name (String)
  • :integration_version (String)


94
95
96
97
98
99
100
101
# File 'lib/contentful/management/client.rb', line 94

def initialize(access_token = nil, configuration = {})
  @configuration = default_configuration.merge(configuration)
  setup_logger
  @access_token = access_token
  @dynamic_entry_cache = {}
  Thread.current[:client] = self
  update_all_dynamic_entry_cache!
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



44
45
46
# File 'lib/contentful/management/client.rb', line 44

def access_token
  @access_token
end

#configurationObject (readonly)

Returns the value of attribute configuration.



44
45
46
# File 'lib/contentful/management/client.rb', line 44

def configuration
  @configuration
end

#content_type_idObject

Returns the value of attribute content_type_id.



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

def content_type_id
  @content_type_id
end

#dynamic_entry_cacheObject

Returns the value of attribute dynamic_entry_cache.



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

def dynamic_entry_cache
  @dynamic_entry_cache
end

#loggerObject (readonly)

Returns the value of attribute logger.



44
45
46
# File 'lib/contentful/management/client.rb', line 44

def logger
  @logger
end

#organization_idObject

Returns the value of attribute organization_id.



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

def organization_id
  @organization_id
end

#versionObject

Returns the value of attribute version.



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

def version
  @version
end

Instance Method Details

#api_keys(space_id) ⇒ Contentful::Management::ClientApiKeyMethodsFactory

Allows manipulation of api keys in context of the current client Allows listing all api keys for client, creating new and finding one by ID.

Returns:

  • (Contentful::Management::ClientApiKeyMethodsFactory)

See Also:

  • README for details.


169
170
171
# File 'lib/contentful/management/client.rb', line 169

def api_keys(space_id)
  ClientApiKeyMethodsFactory.new(self, space_id)
end

#assets(space_id, environment_id) ⇒ Contentful::Management::ClientAssetMethodsFactory

Allows manipulation of assets in context of the current client Allows listing all assets for client, creating new and finding one by ID.

Returns:

  • (Contentful::Management::ClientAssetMethodsFactory)

See Also:

  • README for details.


196
197
198
# File 'lib/contentful/management/client.rb', line 196

def assets(space_id, environment_id)
  ClientAssetMethodsFactory.new(self, space_id, environment_id)
end

#content_type_snapshots(space_id, environment_id) ⇒ Contentful::Management::ClientSnapshotMethodsFactory

Allows manipulation of content type snapshots in context of the current client Allows listing all content type snapshots for client and finding one by ID.

Returns:

  • (Contentful::Management::ClientSnapshotMethodsFactory)

See Also:

  • README for details.


322
323
324
# File 'lib/contentful/management/client.rb', line 322

def content_type_snapshots(space_id, environment_id)
  ClientSnapshotMethodsFactory.new(self, space_id, environment_id, 'content_types')
end

#content_types(space_id, environment_id) ⇒ Contentful::Management::ClientContentTypeMethodsFactory

Allows manipulation of content types in context of the current client Allows listing all content types for client, creating new and finding one by ID.

Returns:

  • (Contentful::Management::ClientContentTypeMethodsFactory)

See Also:

  • README for details.


214
215
216
# File 'lib/contentful/management/client.rb', line 214

def content_types(space_id, environment_id)
  ClientContentTypeMethodsFactory.new(self, space_id, environment_id)
end

#editor_interfaces(space_id, environment_id, content_type_id) ⇒ Contentful::Management::ClientEditorInterfaceMethodsFactory

Allows manipulation of editor interfaces in context of the current client Allows listing all editor interfaces for client and finding one by content type.

Returns:

  • (Contentful::Management::ClientEditorInterfaceMethodsFactory)

See Also:

  • README for details.


259
260
261
# File 'lib/contentful/management/client.rb', line 259

def editor_interfaces(space_id, environment_id, content_type_id)
  ClientEditorInterfaceMethodsFactory.new(self, space_id, environment_id, content_type_id)
end

#entries(space_id, environment_id) ⇒ Contentful::Management::ClientEntryMethodsFactory

Allows manipulation of entries in context of the current client Allows listing all entries for client, creating new and finding one by ID.

Returns:

  • (Contentful::Management::ClientEntryMethodsFactory)

See Also:

  • README for details.


223
224
225
# File 'lib/contentful/management/client.rb', line 223

def entries(space_id, environment_id)
  ClientEntryMethodsFactory.new(self, space_id, environment_id)
end

#entry_snapshots(space_id, environment_id) ⇒ Contentful::Management::ClientSnapshotMethodsFactory

Allows manipulation of entry snapshots in context of the current client Allows listing all entry snapshots for client and finding one by ID.

Returns:

  • (Contentful::Management::ClientSnapshotMethodsFactory)

See Also:

  • README for details.


313
314
315
# File 'lib/contentful/management/client.rb', line 313

def entry_snapshots(space_id, environment_id)
  ClientSnapshotMethodsFactory.new(self, space_id, environment_id, 'entries')
end

#environments(space_id) ⇒ Contentful::Management::ClientEnvironmentMethodsFactory

Allows manipulation of environments in context of the current client Allows listing all environments for client, creating new and finding one by ID.

Returns:

  • (Contentful::Management::ClientEnvironmentMethodsFactory)

See Also:

  • README for details.


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

def environments(space_id)
  ClientEnvironmentMethodsFactory.new(self, space_id)
end

#http_send(type, url, params, headers, proxy) ⇒ HTTP::Response

HTTP Helper Abtracts the Proxy/No-Proxy logic

Parameters:

  • type (Symbol)
  • url (String)
  • params (Hash)
  • headers (Hash)
  • proxy (Hash)

Returns:

  • (HTTP::Response)


505
506
507
508
509
# File 'lib/contentful/management/client.rb', line 505

def http_send(type, url, params, headers, proxy)
  return proxy_send(type, url, params, headers, proxy) unless proxy[:host].nil?

  HTTP[headers].public_send(type, url, params)
end

#locales(space_id, environment_id) ⇒ Contentful::Management::ClientLocaleMethodsFactory

Allows manipulation of locales in context of the current client Allows listing all locales for client, creating new and finding one by ID.

Returns:

  • (Contentful::Management::ClientLocaleMethodsFactory)

See Also:

  • README for details.


232
233
234
# File 'lib/contentful/management/client.rb', line 232

def locales(space_id, environment_id)
  ClientLocaleMethodsFactory.new(self, space_id, environment_id)
end

#organization_periodic_usages(organization_id) ⇒ Contentful::Management::ClientOrganizationPeriodicUsageMethodsFactory

Allows listing all usage periods for organization grouped by organization.

Returns:

  • (Contentful::Management::ClientOrganizationPeriodicUsageMethodsFactory)

See Also:

  • README for details.


143
144
145
# File 'lib/contentful/management/client.rb', line 143

def organization_periodic_usages(organization_id)
  ClientOrganizationPeriodicUsageMethodsFactory.new(self, organization_id)
end

#organizationsContentful::Management::ClientOrganizationMethodsFactory

Allows viewing of organizations in context of the current client Allows listing all organizations for client.

Returns:

  • (Contentful::Management::ClientOrganizationMethodsFactory)

See Also:

  • README for details.


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

def organizations
  ClientOrganizationMethodsFactory.new(self)
end

#personal_access_tokensContentful::Management::ClientPersonalAccessTokenMethodsFactory

Allows manipulation of personal access tokens in context of the current client Allows listing all personal access tokens for client, creating new and finding one by ID.

Returns:

  • (Contentful::Management::ClientPersonalAccessTokenMethodsFactory)

See Also:

  • README for details.


187
188
189
# File 'lib/contentful/management/client.rb', line 187

def personal_access_tokens
  ClientPersonalAccessTokenMethodsFactory.new(self)
end

#preview_api_keys(space_id) ⇒ Contentful::Management::ClientPreviewApiKeyMethodsFactory

Allows manipulation of api keys in context of the current client Allows listing all preview api keys for client and finding one by ID.

Returns:

  • (Contentful::Management::ClientPreviewApiKeyMethodsFactory)

See Also:

  • README for details.


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

def preview_api_keys(space_id)
  ClientPreviewApiKeyMethodsFactory.new(self, space_id)
end

#proxy_send(type, url, params, headers, proxy) ⇒ HTTP::Response

Proxy Helper

Parameters:

  • type (Symbol)
  • url (String)
  • params (Hash)
  • headers (Hash)
  • proxy (Hash)

Returns:

  • (HTTP::Response)


486
487
488
489
490
491
492
493
# File 'lib/contentful/management/client.rb', line 486

def proxy_send(type, url, params, headers, proxy)
  HTTP[headers].via(
    proxy[:host],
    proxy[:port],
    proxy[:username],
    proxy[:password]
  ).public_send(type, url, params)
end

#roles(space_id) ⇒ Contentful::Management::ClientRoleMethodsFactory

Allows manipulation of roles in context of the current client Allows listing all roles for client, creating new and finding one by ID.

Returns:

  • (Contentful::Management::ClientRoleMethodsFactory)

See Also:

  • README for details.


241
242
243
# File 'lib/contentful/management/client.rb', line 241

def roles(space_id)
  ClientRoleMethodsFactory.new(self, space_id)
end

#snapshots(space_id, environment_id, resource_type = 'entries') ⇒ Contentful::Management::ClientSnapshotMethodsFactory

Allows manipulation of snapshots in context of the current client Allows listing all snapshots for client and finding one by ID.

Returns:

  • (Contentful::Management::ClientSnapshotMethodsFactory)

See Also:

  • README for details.


304
305
306
# File 'lib/contentful/management/client.rb', line 304

def snapshots(space_id, environment_id, resource_type = 'entries')
  ClientSnapshotMethodsFactory.new(self, space_id, environment_id, resource_type)
end

#space_memberships(space_id) ⇒ Contentful::Management::ClientSpaceMembershipMethodsFactory

Allows manipulation of space memberships in context of the current client Allows listing all space memberships for client, creating new and finding one by ID.

Returns:

  • (Contentful::Management::ClientSpaceMembershipMethodsFactory)

See Also:

  • README for details.


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

def space_memberships(space_id)
  ClientSpaceMembershipMethodsFactory.new(self, space_id)
end

#space_periodic_usages(organization_id) ⇒ Contentful::Management::ClientSpacePeriodicUsageMethodsFactory

Allows listing all usage periods for organization grouped by space.

Returns:

  • (Contentful::Management::ClientSpacePeriodicUsageMethodsFactory)

See Also:

  • README for details.


151
152
153
# File 'lib/contentful/management/client.rb', line 151

def space_periodic_usages(organization_id)
  ClientSpacePeriodicUsageMethodsFactory.new(self, organization_id)
end

#spacesContentful::Management::ClientSpaceMethodsFactory

Allows manipulation of spaces in context of the current client Allows listing all spaces for client, creating new and finding one by ID.

Returns:

  • (Contentful::Management::ClientSpaceMethodsFactory)

See Also:

  • README for details.


108
109
110
# File 'lib/contentful/management/client.rb', line 108

def spaces
  ClientSpaceMethodsFactory.new(self)
end

#tags(space_id, environment_id) ⇒ Contentful::Management::ClientTagMethodsFactory

Allows manipulation of tags in context of the current client Allows listing all tags for client, creating new and finding one by ID.

Returns:

  • (Contentful::Management::ClientTagMethodsFactory)

See Also:

  • README for details.


205
206
207
# File 'lib/contentful/management/client.rb', line 205

def tags(space_id, environment_id)
  ClientTagMethodsFactory.new(self, space_id, environment_id)
end

#ui_extensions(space_id, environment_id) ⇒ Contentful::Management::ClientUIExtensionMethodsFactory

Allows manipulation of UI extensions in context of the current client Allows listing all UI extensions for client, creating new and finding one by ID.

Returns:

  • (Contentful::Management::ClientUIExtensionMethodsFactory)

See Also:

  • README for details.


250
251
252
# File 'lib/contentful/management/client.rb', line 250

def ui_extensions(space_id, environment_id)
  ClientUIExtensionMethodsFactory.new(self, space_id, environment_id)
end

#uploads(space_id) ⇒ Contentful::Management::ClientUploadMethodsFactory

Allows manipulation of uploads in context of the current client Allows creating new and finding uploads by ID.

Returns:

  • (Contentful::Management::ClientUploadMethodsFactory)

See Also:

  • README for details.


295
296
297
# File 'lib/contentful/management/client.rb', line 295

def uploads(space_id)
  ClientUploadMethodsFactory.new(self, space_id)
end

#usersContentful::Management::ClientUserMethodsFactory

Allows viewing of users in context of the current client Allows listing all users for client.

Returns:

  • (Contentful::Management::ClientUserMethodsFactory)

See Also:

  • README for details.


160
161
162
# File 'lib/contentful/management/client.rb', line 160

def users
  ClientUserMethodsFactory.new(self)
end

#webhook_calls(space_id, webhook_id) ⇒ Contentful::Management::ClientWebhookCallMethodsFactory

Allows manipulation of webhook calls in context of the current client Allows listing all webhook call details for client and finding one by ID.

Returns:

  • (Contentful::Management::ClientWebhookCallMethodsFactory)

See Also:

  • README for details.


277
278
279
# File 'lib/contentful/management/client.rb', line 277

def webhook_calls(space_id, webhook_id)
  ClientWebhookCallMethodsFactory.new(self, space_id, webhook_id)
end

#webhook_health(space_id) ⇒ Contentful::Management::ClientWebhookHealthMethodsFactory

Allows manipulation of webhook health in context of the current client Allows listing all webhook health details for client and finding one by ID.

Returns:

  • (Contentful::Management::ClientWebhookHealthMethodsFactory)

See Also:

  • README for details.


286
287
288
# File 'lib/contentful/management/client.rb', line 286

def webhook_health(space_id)
  ClientWebhookHealthMethodsFactory.new(self, space_id)
end

#webhooks(space_id) ⇒ Contentful::Management::ClientWebhookMethodsFactory

Allows manipulation of webhooks in context of the current client Allows listing all webhooks for client, creating new and finding one by ID.

Returns:

  • (Contentful::Management::ClientWebhookMethodsFactory)

See Also:

  • README for details.


268
269
270
# File 'lib/contentful/management/client.rb', line 268

def webhooks(space_id)
  ClientWebhookMethodsFactory.new(self, space_id)
end