{"id":15022407,"url":"https://github.com/contentful/contentful-management.rb","last_synced_at":"2025-05-16T11:03:46.219Z","repository":{"id":16812520,"uuid":"19571553","full_name":"contentful/contentful-management.rb","owner":"contentful","description":"Ruby client for the Contentful Content Management API","archived":false,"fork":false,"pushed_at":"2025-04-07T20:01:18.000Z","size":1342,"stargazers_count":34,"open_issues_count":21,"forks_count":32,"subscribers_count":32,"default_branch":"master","last_synced_at":"2025-05-06T12:13:04.417Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.contentful.com/developers/documentation/content-management-api/","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/contentful.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-05-08T11:50:59.000Z","updated_at":"2025-01-27T06:32:11.000Z","dependencies_parsed_at":"2023-02-11T03:30:42.800Z","dependency_job_id":"be26847f-de82-4f95-8f30-81897c450f3f","html_url":"https://github.com/contentful/contentful-management.rb","commit_stats":{"total_commits":314,"total_committers":37,"mean_commits":8.486486486486486,"dds":0.6050955414012739,"last_synced_commit":"da4ea355e14f88e1646611201ba4cb8404804e61"},"previous_names":[],"tags_count":70,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contentful%2Fcontentful-management.rb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contentful%2Fcontentful-management.rb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contentful%2Fcontentful-management.rb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contentful%2Fcontentful-management.rb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/contentful","download_url":"https://codeload.github.com/contentful/contentful-management.rb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254518383,"owners_count":22084374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T19:57:54.648Z","updated_at":"2025-05-16T11:03:46.201Z","avatar_url":"https://github.com/contentful.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Contentful::Management\n[![Gem Version](https://badge.fury.io/rb/contentful-management.svg)](http://badge.fury.io/rb/contentful-management) [![CircleCI](https://circleci.com/gh/contentful/contentful-management.rb/tree/master.svg?style=svg)](https://app.circleci.com/pipelines/github/contentful/contentful-management.rb?branch=master)\n\nRuby client for the Contentful Content Management API.\n\n[Contentful](https://www.contentful.com) provides a content infrastructure for digital teams to power content in websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship digital products faster.\n\n## Setup\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'contentful-management'\n```\n\n## Usage\n\n### Examples\nSome examples can be found in the `examples/` directory or you take a look at this [extended example script](https://github.com/contentful/cma_import_script).\n\n### Client\n\nAt the beginning the API client instance should be created for each thread that is going to be used in your application:\n\n```ruby\nrequire 'contentful/management'\n\nclient = Contentful::Management::Client.new('access_token')\n```\n\nThe access token can easily be created through the [management api documentation](https://www.contentful.com/developers/documentation/content-management-api/#getting-started).\n\n### Spaces\n\nRetrieving all spaces:\n\n```ruby\nspaces = client.spaces.all\n```\n\nRetrieving one space by ID:\n\n```ruby\nblog_space = client.spaces.find('blog_space_id')\n```\n\nDestroying a space:\n\n```ruby\nblog_space.destroy\n```\n\nCreating a space:\n\n```ruby\nblog_space = client.spaces.new\nblog_space.name = 'Blog Space'\nblog_space.save\n```\n\nor\n\n```ruby\nblog_space = client.spaces.create(name: 'Blog Space')\n```\n\nor in the context of the organization (if you have multiple organizations within your account):\n\n```ruby\nblog_space = client.spaces.create(name: 'Blog Space', organization_id: 'organization_id')\n```\n\nIf you want to create a default locale different from `en-US`:\n```ruby\nblog_space = client.spaces.create(name: 'Blog Space', default_locale: 'de-DE')\n```\n\nUpdating a space:\n\n```ruby\nblog_space.update(name: 'New Blog Space')\n```\n\nor\n\n```ruby\nblog_space.name = 'New Blog Space'\nblog_space.save\n```\n\n### Environments\n\nRetrieving all environments:\n\n```ruby\nenvironments = client.environments('space_id').all\n```\n\nOr if you already have a fetched space:\n\n```ruby\nenvironments = space.environments.all\n```\n\nRetrieving one environment by ID:\n\n```ruby\nenvironment = client.environments('space_id').find('master')\n```\n\nDestroying a environment:\n\n```ruby\nenvironment.destroy\n```\n\nCreating an environment:\n\n```ruby\nenvironment = client.environments('space_id').new\nenvironment.id = 'dev'\nenvironment.name = 'Development'\nenvironment.save\n```\n\nor\n\n```ruby\nenvironment = client.environments(space_id).create(id: 'dev', name: 'Development')\n```\n\nCreating an evironment with a different source:\n\n```ruby\nenvironment = client.environments(space_id).create(id: 'dev', name: 'Development', source_environment_id: 'other_environment')\n```\n\nUpdating a environment:\n\n```ruby\nenvironment.update(name: 'New Blog environment')\n```\n\nor\n\n```ruby\nenvironment.name = 'Dev'\nenvironment.save\n```\n\n### Assets\n\nRetrieving all assets from the environment:\n\n```ruby\nblog_post_assets = environment.assets.all\n```\n\nRetrieving an asset by id:\n\n```ruby\nblog_post_asset = environment.assets.find('asset_id')\n```\n\nCreating a file:\n\n```ruby\nimage_file = Contentful::Management::File.new\nimage_file.properties[:contentType] = 'image/jpeg'\nimage_file.properties[:fileName] = 'example.jpg'\nimage_file.properties[:upload] = 'http://www.example.com/example.jpg'\n```\n\nCreating an asset:\n\n```ruby\nmy_image_asset = environment.assets.create(title: 'My Image', description: 'My Image Description', file: image_file)\n```\n\nor an asset with multiple locales\n\n```ruby\nmy_image_localized_asset = environment.assets.new\nmy_image_localized_asset.title_with_locales= {'en-US' =\u003e 'title', 'pl' =\u003e 'pl title'}\nmy_image_localized_asset.description_with_locales= {'en-US' =\u003e 'description', 'pl' =\u003e 'pl description'}\nen_file = Contentful::Management::File.new\nen_file.properties[:contentType] = 'image/jpeg'\nen_file.properties[:fileName] = 'pic1.jpg'\nen_file.properties[:upload] = 'http://www.example.com/pic1.jpg'\npl_file = Contentful::Management::File.new\npl_file.properties[:contentType] = 'image/jpeg'\npl_file.properties[:fileName] = 'pic2.jpg'\npl_file.properties[:upload] = 'http://www.example.com/pic2.jpg'\nasset.file_with_locales= {'en-US' =\u003e en_file, 'pl' =\u003e pl_file}\nasset.save\n```\n\nProcess an asset file after create:\n```ruby\nasset.process_file\n```\n\nUpdating an asset:\n\n- default locale\n\n```ruby\nmy_image_asset.update(title: 'My Image', description: 'My Image Description', file: image_file)\n```\n\n- another locale (we can switch locales for the object, so then all fields are in context of selected locale)\n\n```ruby\nmy_image_asset.locale = 'nl'\nmy_image_asset.update(title: 'NL Title', description: 'NL Description', file: nl_image)\n```\n\n- field with multiple locales\n\n```ruby\nmy_image_asset.title_with_locales = {'en-US' =\u003e 'US Title', 'nl' =\u003e 'NL Title'}\nmy_image_asset.save\n```\n\nDestroying an asset:\n\n```ruby\nmy_image_asset.destroy\n```\n\nArchiving or unarchiving an asset:\n\n```ruby\nmy_image_asset.archive\nmy_image_asset.unarchive\n```\n\nChecking if an asset is archived:\n\n```ruby\nmy_image_asset.archived?\n```\n\nPublishing or unpublishing an asset:\n\n```ruby\nmy_image_asset.publish\nmy_image_asset.unpublish\n```\n\nChecking if an asset is published:\n\n```ruby\nmy_image_asset.published?\n```\n\nChecking if has been updated from last published version:\n\n```ruby\nmy_image_asset.updated?\n```\n\n### File Uploads\n\nCreating an upload from a file path:\n\n```ruby\nupload = client.uploads('space_id').create('/path/to/file.md')\n```\n\nAlternatively, create it from an `::IO` object:\n\n```ruby\nFile.open('/path/to/file.md', 'rb') do |file|\n  upload = client.uploads('space_id').create(file)\nend\n```\n\nFinding an upload:\n\n```ruby\nupload = client.uploads('space_id').find('upload_id')\n```\n\nDeleting an upload:\n\n```ruby\nupload.destroy\n```\n\nAssociating an upload with an asset:\n\n```ruby\n# We find or create an upload:\nupload = client.uploads('space_id').find('upload_id')\n\n# We create a File object with the associated upload:\nfile = Contentful::Management::File.new\nfile.properties[:contentType] = 'text/plain'\nfile.properties[:fileName] = 'file.md'\nfile.properties[:uploadFrom] = upload.to_link_json  # We create the Link from the upload.\n\n# We create an asset with the associated file:\nasset = client.assets('space_id', 'environment_id').create(title: 'My Upload', file: file)\nasset.process_file  # We process the file, to generate an URL for our upload.\n```\n\n### Entries\n\nRetrieving all entries from the environment:\n\n```ruby\nentries = environment.entries.all\n```\n\nRetrieving all entries from the environment with given content type:\n\n```ruby\nentries = environment.entries.all(content_type: content_type.id)\n```\n\nor\n\n```ruby\nentries = content_type.entries.all\n```\n\nRetrieving an entry by ID:\n\n```ruby\nentry = environment.entries.find('entry_id')\n```\n\nRetrieving entries by any other field value:\n\n```ruby\nentries = environment.entries.all(content_type: content_type.id, 'fields.fieldName' =\u003e 'value')\n```\n\nNote: all [search parameters](https://www.contentful.com/developers/docs/references/content-management-api/#/reference/search-parameters) are supported.\n\nCreating a location:\n\n```ruby\nlocation = Location.new\nlocation.lat = 22.44\nlocation.lon = 33.33\n```\n\nCreating an entry:\n- with a default locale\n\n```ruby\nmy_entry = blog_post_content_type.entries.create(post_title: 'Title', assets_array_field: [image_asset_1, ...], entries_array_field: [entry_1, ...], location_field: location)\n```\n\n- with multiple locales\n\n```ruby\nmy_entry = blog_post_content_type.entries.new\nmy_entry.post_title_with_locales = {'en-US' =\u003e 'EN Title', 'pl' =\u003e 'PL Title'}\nmy_entry.save\n```\n\nUpdating an entry:\n- with a default locale\n\n```ruby\nmy_entry.update(params)\n```\n\n- with another locale\n```ruby\nentry.locale = 'nl'\nentry.update(params)\n```\n\n- with multiple locales\n\n```ruby\nmy_entry.post_title_with_locales = {'en-US' =\u003e 'EN Title', 'pl' =\u003e 'PL Title'}\nmy_entry.save\n```\n\nDestroying an entry:\n\n```ruby\nmy_entry.destroy\n```\n\nArchiving or unarchiving the entry:\n\n```ruby\nmy_entry.archive\nmy_entry.unarchive\n```\n\nChecking if the entry is archived:\n\n```ruby\nmy_entry.archived?\n```\n\nPublishing or unpublishing the entry:\n\n```ruby\nmy_entry.publish\nmy_entry.unpublish\n```\n\nChecking if the entry is published:\n\n```ruby\nmy_entry.published?\n```\n\nChecking if the entry has been updated from last publish:\n\n```ruby\nmy_entry.updated?\n```\n\n\u003e Entries created with *empty fields*, will not return those fields in the response. Therefore, entries that don't have cache enabled, will need to\n\u003e make an extra request to fetch the content type and fill the missing fields.\n\u003e To allow for content type caching:\n\u003e   * Enable [content type cache](#content-type-cache) at client instantiation time\n\u003e   * Query entries through `environment.entries.find` instead of `Entry.find(environment_id, entry_id)`\n\n### Content Types\n\nRetrieving all content types from a environment:\n\n```ruby\nblog_post_content_types = environment.content_types.all\n```\n\nRetrieving all published content types from a environment:\n\n```ruby\nblog_post_content_types = environment.content_types.all_published\n```\n\nRetrieving one content type by ID from a environment:\n\n```ruby\nblog_post_content_type = environment.content_types.find(id)\n```\n\nCreating a field for a content type:\n\n```ruby\ntitle_field = Contentful::Management::Field.new\ntitle_field.id = 'blog_post_title'\ntitle_field.name = 'Post Title'\ntitle_field.type = 'Text'\nblog_post_content_type.fields.add(field)\n```\n\nor\n\n```ruby\nblog_post_content_type.fields.create(id: 'title_field_id', name: 'Post Title', type: 'Text')\n```\n- if the field_id exists, the related field will be updated.\n\nor the field of link type:\n```ruby\nblog_post_content_type.fields.create(id: 'my_entry_link_field', name: 'My Entry Link Field', type: 'Link', link_type: 'Entry')\n```\n\nor the field of ResourceLink type:\n```ruby\nblog_post_content_type.fields.create(\n  id: 'my_resource_link_id',\n  name: 'My Resource Link',\n  type: 'ResourceLink',\n  localized: true,\n  disabled: false,\n  omitted: false,\n  allowed_resources: [\n    {\n      type: 'Contentful:Entry',\n      source: 'crn:contentful:::content:spaces/space_id',\n      contentTypes: [\"foo\", \"bar\"]\n    }\n  ]\n)\n```\n\nor the field of an array type:\n```ruby\nitems = Contentful::Management::Field.new\nitems.type = 'Link'\nitems.link_type = 'Entry'\nblog_post_content_type.fields.create(id: 'my_array_field', name: 'My Array Field', type: 'Array', items: items)\n```\n\nDeleting a field from the content type:\n\n```ruby\nblog_post_content_type.fields.destroy(title_field_id)\n```\n\nCreating a content type:\n\n```ruby\nenvironment.content_types.create(name: 'Post', fields: [title_field, body_field])\n```\n\nor\n\n```ruby\nblog_post_content_type = environment.content_types.new\nblog_post_content_type.name = 'Post'\nblog_post_content_type.fields = [title_field, body_field]\nblog_post_content_type.save\n```\n\nDestroying a content type:\n\n```ruby\nblog_post_content_type.destroy\n```\n\nActivating or deactivating a content type:\n\n```ruby\nblog_post_content_type.activate\nblog_post_content_type.deactivate\n```\n\nChecking if a content type is active:\n\n```ruby\nblog_post_content_type.active?\n```\n\nUpdating a content type:\n\n```ruby\nblog_post_content_type.update(name: 'Post', description: 'Post Description', fields: [title_field])\n```\n\n### Validations\n\n#### in\n\nTakes an array of values and validates that the field value is in this array.\n\n```ruby\nvalidation_in = Contentful::Management::Validation.new\nvalidation_in.in = ['foo', 'bar', 'baz']\nblog_post_content_type.fields.create(id: 'valid', name: 'Testing IN', type: 'Text', validations: [validation_in])\n```\n\n#### size\n\nTakes optional min and max parameters and validates the size of the array (number of objects in it).\n\n```ruby\nvalidation_size = Contentful::Management::Validation.new\nvalidation_size.size = { min: 10, max: 15 }\nblog_post_content_type.fields.create(id: 'valid', name: 'Test SIZE', type: 'Text', validations: [validation_size])\n```\n\n#### range\n\nTakes optional min and max parameters and validates the range of a value.\n\n```ruby\nvalidation_range = Contentful::Management::Validation.new\nvalidation_range.range = { min: 100, max: 150 }\nblog_post_content_type.fields.create(id: 'valid', name: 'Range', type: 'Text', validations: [validation_range])\n```\n\n#### regex\n\nTakes a string that reflects a JS regex and flags, validates against a string. See [JS Reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) for the parameters.\n\n```ruby\nvalidation_regexp = Contentful::Management::Validation.new\nvalidation_regexp.regexp = {pattern: '^such', flags: 'im'}\nblog_post_content_type.fields.create(id: 'valid', name: 'Regex', type: 'Text', validations: [validation_regexp])\n```\n\n#### linkContentType\n\nTakes an array of content type ids and validates that the link points to an entry of that content type.\n\n```ruby\nvalidation_link_content_type = Contentful::Management::Validation.new\nvalidation_link_content_type.link_content_type =  ['post_content_type_id']\nblog_post_content_type.fields.create(id: 'entry', name: 'Test linkContentType', type: 'Entry', validations: [validation_link_content_type])\n```\n\n#### linkMimetypeGroup\n\nTakes a MimeType group name and validates that the link points to an asset of this group.\n\n```ruby\nvalidation_link_mimetype_group = Contentful::Management::Validation.new\nvalidation_link_mimetype_group.link_mimetype_group = 'image'\ncontent_type.fields.create(id: 'asset', validations: [validation_link_mimetype_group])\n```\n\n#### present\n\nValidates that a value is present.\n\n```ruby\nvalidation_present = Contentful::Management::Validation.new\nvalidation_present.present = true\ncontent_type.fields.create(id: 'number', validations: [validation_present])\n```\n\n#### linkField\n\nValidates that the property is a link (must not be a valid link, just that it looks like one).\n\n```ruby\nvalidation_link_field = Contentful::Management::Validation.new\nvalidation_link_field.link_field  = true\ncontent_type.fields.create(id: 'entry', validations: [validation_link_field])\n```\n\n### Locales\n\nRetrieving all locales from the environment:\n\n```ruby\nblog_post_locales = environment.locales.all\n```\n\nRetrieving one locale by ID from the environment:\n\n```ruby\nblog_post_locale = environment.locales.find(locale_id)\n```\n\nCreating a locale:\n\n```ruby\nenvironment.locales.create(name: 'German', code: 'de-DE')\n```\n\nCreating a locale with fallback:\n\n```ruby\nenvironment.locales.create(name: 'German', code: 'de-DE', fallback_code: 'en-US')\n```\n\nUpdating a locale:\n\n```ruby\nblog_post_locale.update(name: 'German', code: 'de-DE')\n```\n\nUpdating a locale with fallback:\n\n```ruby\nblog_post_locale.update(name: 'German', code: 'de-DE', fallback_code: 'en-US')\n```\n\nDestroying a locale:\n\n```ruby\nblog_post_locale.destroy\n```\n\n### Tags\n\nRetrieving all tags from the environment:\n\n```ruby\ntags = environment.tags.all\n```\n\nRetrieving one tag by ID from the environment:\n\n```ruby\ntag = environment.tags.find(tag_id)\n```\n\nCreating a tag:\n\n```ruby\nenvironment.tags.create(name: 'tag name', id: 'tagID')\n```\n\nUpdating a tag:\n\n```ruby\ntag.update(name: 'new name')\n```\n\nDestroying a tag:\n\n```ruby\ntag.destroy\n```\n\nTagging an entry:\n\n```ruby\nentry.update(_metadata: {\"tags\": [{ \"sys\": { \"type\": \"Link\", \"linkType\": \"Tag\", \"id\": \"fooTag\" } }]})\n```\n\nTagging an asset:\n\n```ruby\nasset.update(_metadata: {\"tags\": [{ \"sys\": { \"type\": \"Link\", \"linkType\": \"Tag\", \"id\": \"fooTag\" } }]})\n```\n\n### Roles\n\nRetrieving all roles from the space:\n\n```ruby\nblog_post_roles = blog_space.roles.all\n```\n\nRetrieving one role by ID from the space:\n\n```ruby\nblog_post_role = blog_space.role.find(role_id)\n```\n\nCreating a role:\n\n```ruby\nrole_attributes = {\n  name: 'My Role',\n  description: 'foobar role',\n  permissions: {\n    'ContentDelivery': 'all',\n    'ContentModel': ['read'],\n    'Settings': []\n  },\n  policies: [\n    {\n      effect: 'allow',\n      actions: 'all',\n      constraint: {\n        and: [\n          {\n            equals: [\n              { doc: 'sys.type' },\n              'Entry'\n            ]\n          },\n          {\n            equals: [\n              { doc: 'sys.type' },\n              'Asset'\n            ]\n          }\n        ]\n      }\n    }\n  ]\n}\nblog_space.roles.create(role_attributes)\n```\n\nUpdating a role:\n\n```ruby\nblog_post_role.update(name: 'Some Other Role') # Can change any attribute here\n```\n\nDestroying a role:\n\n```ruby\nblog_post_role.destroy\n```\n\n### Webhooks\n\nRetrieving all webhooks from the space:\n\n```ruby\nwebhooks = blog_space.webhooks.all\n```\nRetrieving one webhook by ID from the space:\n\n```ruby\nblog_post_webhook = blog_space.webhooks.find(webhook_id)\n```\n\nCreating a webhook:\n\n```ruby\nblog_space.webhooks.create(\n  name: 'My Webhook',\n  url: 'https://www.example.com',\n  httpBasicUsername: 'username',\n  httpBasicPassword: 'password'\n)\n```\n\nUpdating a webhook:\n\n```ruby\nblog_post_webhook.update(url: 'https://www.newlink.com')\n```\n\nDestroying a webhook:\n\n```ruby\nblog_post_webhook.destroy\n```\n\nCreating a webhook with custom headers and custom topics:\n\n```ruby\nblog_space.webhooks.create(\n  name: 'Entry Save Only',\n  url: 'https://www.example.com',\n  topics: [ 'Entry.save' ],\n  headers: [\n    {\n      key: 'X-My-Custom-Header',\n      value: 'Some Value'\n    }\n  ]\n)\n```\n\n#### Webhook Calls\n\nRetrieving all webhook call details from a webhook:\n\n```ruby\nall_call_details = my_webhook.webhook_calls.all\n```\nRetrieving one webhook call detail by ID from a webhook:\n\n```ruby\ncall_details = my_webhook.webhook_calls.find(call_id)\n```\n\n#### Webhook Health\n\nRetrieving webhook health details from a webhook:\n\n```ruby\nhealth_details = my_webhook.webhook_health.find\n```\n\n### Space Memberships\n\nRetrieving all space memberships from the space:\n\n```ruby\nmemberships = blog_space.space_memberships.all\n```\nRetrieving one space membership by ID from the space:\n\n```ruby\nblog_post_membership = blog_space.space_memberships.find(membership_id)\n```\n\nCreating a space membership:\n\n```ruby\nblog_space.space_memberships.create(\n  admin: false,\n  roles: [\n    {\n      'sys' =\u003e {\n        'type' =\u003e 'Link',\n        'linkType' =\u003e 'Role',\n        'id' =\u003e 'my_role_id'\n      }\n    }\n  ],\n  email: 'foobar@example.com'\n)\n```\n\nUpdating a space membership:\n\n```ruby\nblog_post_membership.update(admin: true)\n```\n\nDestroying a space membership:\n\n```ruby\nblog_post_membership.destroy\n```\n\n### Organizations\n\nRetrieving all organization details:\n\n```ruby\norganizations = client.organizations.all\n```\n\n### Usage\n\n*Note*: This feature is available only to Commited v2 customers.\n\n#### Organization Periodic Usage\n\nRetrieving all API Usage statistics for an Organization during a given usage period, broken down by organization for all APIs:\n\n```ruby\n# Optionally, you can pass the metric, start and end date filters\nusage = client.organization_periodic_usages('organization_id').all\n\n# For example only CDA and CMA metrics from yesterday onwards\nusage = client.organization_periodic_usages('organization_id').all('metric[in]': ['cda', 'cma'], startDate: (Date.today - 1).iso8601)\n```\n\nAlternatively, if you have an already fetched organization:\n\n```ruby\n# Breaking down CMA usage by space, for a given period.\nusage = organization.periodic_usages.all\n```\n\n#### Space Periodic Usage\n\nRetrieving all API Usage statistics for an Organization during a given usage period, broken down by space for all APIs:\n\n```ruby\n# Optionally, you can pass the metric, start and end date filters\nusage = client.space_periodic_usages('organization_id').all\n\n# For example only CDA and CMA metrics from yesterday onwards\nusage = client.space_periodic_usages('organization_id').all('metric[in]': ['cda', 'cma'], startDate: (Date.today - 1).iso8601)\n```\n\nAlternatively, if you have an already fetched organization:\n\n```ruby\n# Breaking down CMA usage by space, for a given period.\nusage = organization.space_periodic_usages.all\n```\n\n### Users\n\nRetrieving current user details:\n\n```ruby\nuser = client.users.me\n```\n\nRetrieving all users in organization:\n\n```ruby\nuser = organization.users.all\n```\n\nRetrieving one user by ID from an organization:\n\n```ruby\nuser = organization.users.find('user_id')\n```\n\nRetrieving all users in a space:\n\n```ruby\nuser = blog_space.users.all\n```\n\nRetrieving one user by ID from the space:\n\n```ruby\nuser = blog_space.users.find('user_id')\n```\n\n### UI Extensions\n\nRetrieving all UI extensions from the environment:\n\n```ruby\nextensions = environment.ui_extensions.all\n```\nRetrieving one UI extension by ID from the environment:\n\n```ruby\nblog_post_extension = environment.ui_extensions.find(extension_id)\n```\n\nCreating a UI extension:\n\n```ruby\nenvironment.ui_extensions.create(\n  extension: {\n    'name' =\u003e 'My extension',\n    'src' =\u003e 'https://www.example.com',\n    'fieldTypes' =\u003e [{\"type\": \"Symbol\"}],\n    'sidebar' =\u003e false\n  }\n)\n```\n\nDestroying a UI extension:\n\n```ruby\nblog_post_extension.destroy\n```\n\n### API Keys\n\nRetrieving all API keys from the space:\n\n```ruby\nblog_post_api_keys = blog_space.api_keys.all\n```\n\nRetrieving one API key by ID from the space:\n\n```ruby\nblog_post_api_key = blog_space.api_keys.find(api_key_id)\n```\n\nCreating an API key:\n\n```ruby\nblog_space.api_keys.create(name: 'foobar key', description: 'key for foobar mobile app')\n```\n\nCreating an API key with multiple environments:\n\n```ruby\nblog_space.api_keys.create(\n  name: 'foobar key - multiple environments',\n  description: 'key for foobar app',\n  environments: [\n    {\n      sys: {\n        type: 'Link',\n        linkType: 'Environment',\n        id: 'master'\n      }\n    },\n    {\n      sys: {\n        type: 'Link',\n        linkType: 'Environment',\n        id: 'staging'\n      }\n    }\n  ]\n)\n```\n\n### Preview API Keys\n\nRetrieving all Preview API keys from the space:\n\n```ruby\nblog_post_preview_api_keys = blog_space.preview_api_keys.all\n```\n\nRetrieving one Preview API key by ID from the space:\n\n```ruby\nblog_post_preview_api_key = blog_space.preview_api_keys.find(api_key_id)\n```\n\nIf you already have an API key fetched, you can retrieve the Preview API key from it:\n\n```ruby\nblog_post_preview_api_key = blog_post_api_key.preview_api_key\n```\n\n### Personal Access Tokens\n\nRetrieving all personal access tokens:\n\n```ruby\ntokens = client.personal_access_tokens.all\n```\n\nRetrieving one personal access token by ID:\n\n```ruby\ntoken = client.personal_access_tokens.find(token_id)\n```\n\nCreating a personal access token:\n\n```ruby\nclient.personal_access_tokens.create(name: 'foobar key', scopes: ['content_management_manage'])\n```\n\nRevoking a personal access token:\n\n```ruby\ntoken.revoke\n```\n\n### Editor Interface\n\nRetrieving editor interface for a content type:\n\n```ruby\nblog_post_editor_interface = blog_post_content_type.editor_interface.default\n```\n\nYou can call the EditorInterface API from any level within the content model hierarchy, take into account that you'll need to\npass the IDs of the levels below it.\n\n\u003e Hierarchy is as follows:\n\u003e `No Object -\u003e Environment -\u003e ContentType -\u003e EditorInterface`\n\n### Entry Snapshots\n\nRetrieving all snapshots for a given entry:\n\n```ruby\nsnapshots = entry.snapshots.all\n```\n\nRetrieving a snapshot for a given entry:\n\n```ruby\nsnapshot = entry.snapshots.find('some_snapshot_id')\n```\n\n### Entry references\n\nRetrieving entry references:\n\n```ruby\nreferences = entry.references(include: 1)\n```\n\n### Content Type Snapshots\n\nRetrieving all snapshots for a given content type:\n\n```ruby\nsnapshots = content_type.snapshots.all\n```\n\nRetrieving a snapshot for a given content type:\n\n```ruby\nsnapshot = content_type.snapshots.find('some_snapshot_id')\n```\n\n### Pagination\n\n```ruby\nenvironment.entries.all(limit: 5).next_page\nenvironment.assets.all(limit: 5).next_page\nenvironment.entries.all(limit: 5).next_page\n```\n\n### Logging\n\nLogging is disabled by default, it can be enabled by setting a logger instance and a logging severity.\n\n```ruby\nclient = Contentful::Management::Client.new('access_token', logger: logger_instance, log_level: Logger::DEBUG)\n```\n\n\nExample loggers:\n\n```ruby\nRails.logger\nLogger.new('logfile.log')\n```\n\n\nThe default severity is set to INFO and logs only the request attributes (headers, parameters and url). Setting it to DEBUG will also log the raw JSON response.\n\n### Raise Errors\n\nIf `:raise_errors` is set to true, an Exception will be raised in case of an error. The default is false, in this case a ```Contentful::Management::Error``` object will be returned.\n\n```ruby\nclient = Contentful::Management::Client.new('access_token', raise_errors: true)\n```\n\n### Content Type Cache\n\nThis allows for fetching content types for your environment at client instantiation time, which prevents extra requests per entry.\nTo enable this, in your client instantiation do:\n\n```ruby\nclient = Contentful::Management::Client.new(token, dynamic_entries: {'my_space_id' =\u003e 'my_environment_id'})\n```\n\nYou can enable the cache for as many environments as you want. If no environment is added, content types will be fetched upon environment find.\n\nTo completely disable this feature, upon client instantiation do:\n\n```ruby\nclient = Contentful::Management::Client.new(token, disable_content_type_caching: true)\n```\n\n### Proxy Support\n\nThis allows for using the CMA SDK through a proxy, for this, your proxy must support HTTPS and your server must have a valid signed certificate.\n\nTo enable this, in your client instantiation do:\n\n\n```ruby\nPROXY_HOST = 'localhost'\nPROXY_PORT = 8888\n\n# Just host/port\nclient = Contributing::Management::Client.new(\n  token,\n  proxy_host: PROXY_HOST,\n  proxy_port: PROXY_PORT\n)\n\n# With username/password\nclient = Contributing::Management::Client.new(\n  token,\n  proxy_host: PROXY_HOST,\n  proxy_port: PROXY_PORT,\n  proxy_username: 'YOUR_USERNAME',\n  proxy_password: 'YOUR_PASSWORD'\n)\n```\n\n# Rate limit management\n\nWith the following configuration options you can handle how rate limits are handled within your applications.\n\n## :max_rate_limit_retries\n\nTo increase or decrease the retry attempts after a 429 Rate Limit error. Default value is 1. Using 0 will disable retry behaviour.\nEach retry will be attempted after the value (in seconds) of the `X-Contentful-RateLimit-Reset` header, which contains the amount of seconds until the next\nnon rate limited request is available, has passed. This is blocking per execution thread.\n\n## :max_rate_limit_wait\n\nMaximum time to wait for next available request (in seconds). Default value is 60 seconds. Keep in mind that if you hit the houly rate limit maximum, you\ncan have up to 60 minutes of blocked requests. It is set to a default of 60 seconds in order to avoid blocking processes for too long, as rate limit retry behaviour\nis blocking per execution thread.\n\n## Contributing\n\n1. Fork it ( https://github.com/[my-github-username]/contentful-management/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcontentful%2Fcontentful-management.rb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcontentful%2Fcontentful-management.rb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcontentful%2Fcontentful-management.rb/lists"}