SkillAgentSearch skills...

Contentful.rb

Ruby client for the Contentful Content Delivery API

Install / Use

/learn @contentful/Contentful.rb
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

header

<p align="center"> <a href="https://www.contentful.com/slack/"> <img src="https://img.shields.io/badge/-Join%20Community%20Slack-2AB27B.svg?logo=slack&maxAge=31557600" alt="Join Contentful Community Slack"> </a> &nbsp; <a href="https://www.contentfulcommunity.com/"> <img src="https://img.shields.io/badge/-Join%20Community%20Forum-3AB2E6.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MiA1OSI+CiAgPHBhdGggZmlsbD0iI0Y4RTQxOCIgZD0iTTE4IDQxYTE2IDE2IDAgMCAxIDAtMjMgNiA2IDAgMCAwLTktOSAyOSAyOSAwIDAgMCAwIDQxIDYgNiAwIDEgMCA5LTkiIG1hc2s9InVybCgjYikiLz4KICA8cGF0aCBmaWxsPSIjNTZBRUQyIiBkPSJNMTggMThhMTYgMTYgMCAwIDEgMjMgMCA2IDYgMCAxIDAgOS05QTI5IDI5IDAgMCAwIDkgOWE2IDYgMCAwIDAgOSA5Ii8+CiAgPHBhdGggZmlsbD0iI0UwNTM0RSIgZD0iTTQxIDQxYTE2IDE2IDAgMCAxLTIzIDAgNiA2IDAgMSAwLTkgOSAyOSAyOSAwIDAgMCA0MSAwIDYgNiAwIDAgMC05LTkiLz4KICA8cGF0aCBmaWxsPSIjMUQ3OEE0IiBkPSJNMTggMThhNiA2IDAgMSAxLTktOSA2IDYgMCAwIDEgOSA5Ii8+CiAgPHBhdGggZmlsbD0iI0JFNDMzQiIgZD0iTTE4IDUwYTYgNiAwIDEgMS05LTkgNiA2IDAgMCAxIDkgOSIvPgo8L3N2Zz4K&maxAge=31557600" alt="Join Contentful Community Forum"> </a> </p>

contentful.rb - Contentful Ruby Delivery Library

Gem Version

Ruby library for the Contentful Content Delivery API and Content Preview API. It helps you to easily access your Content stored in Contentful with your Ruby applications.

<p align="center"> <img src="https://img.shields.io/badge/Status-Maintained-green.svg" alt="This repository is actively maintained" /> &nbsp; <a href="LICENSE.txt"> <img src="https://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License" /> </a> &nbsp; <a href="https://github.com/contentful/contentful.rb/actions/workflows/ci.yml"> <img src="https://github.com/contentful/contentful.rb/actions/workflows/ci.yml/badge.svg" alt="CI"> </a> </p> <p align="center"> <a href="https://rubygems.org/gems/contentful"> <img src="https://img.shields.io/gem/v/contentful.svg" alt="RubyGems version"> </a> &nbsp; <a href="https://rubygems.org/gems/contentful"> <img src="https://img.shields.io/gem/dt/contentful.svg" alt="RubyGems downloads"> </a> </p>

What is Contentful?

Contentful provides content infrastructure for digital teams to power 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 their products faster.

<details> <summary>Table of contents</summary> <!-- TOC --> <!-- /TOC --> </details>

Core Features

Getting started

In order to get started with the Contentful Ruby library you'll need not only to install it, but also to get credentials which will allow you to have access to your content in Contentful.

Installation

Add to your Gemfile and bundle:

gem 'contentful'

Or install it directly from your console:

gem i contentful

Your first request

The following code snippet is the most basic one you can use to get some content from Contentful with this library:

require 'contentful'

client = Contentful::Client.new(
  space: 'cfexampleapi',  # This is the space ID. A space is like a project folder in Contentful terms
  access_token: 'b4c0n73n7fu1'  # This is the access token for this space. Normally you get both ID and the token in the Contentful web app
)

# This API call will request an entry with the specified ID from the space defined at the top, using a space-specific access token.
entry = client.entry('nyancat')

Using this library with the Preview API

This library can also be used with the Preview API. In order to do so, you need to use the Preview API Access token, available on the same page where you get the Delivery API token, and specify the host of the preview API, such as:

require 'contentful'

client = Contentful::Client.new(
  space: 'cfexampleapi',
  access_token: 'b4c0n73n7fu1',
  api_url: 'preview.contentful.com'
)

You can query for entries, assets, etc. very similar as described in the Delivery API Documentation. Please note, that all methods of the Ruby client library are snake_cased, instead of JavaScript's camelCase:

Authentication

To get your own content from Contentful, an app should authenticate with an OAuth bearer token.

You can create API keys using the Contentful web interface. Go to the app, open the space that you want to access (top left corner lists all the spaces), and navigate to the APIs area. Open the API Keys section and create your first token. Done.

Don't forget to also get your Space ID.

For more information, check the Contentful REST API reference on Authentication.

Documentation & References

To help you get the most out of this library, we've prepared all available client configuration options, reference documentation, tutorials and other examples that will help you learn and understand how to use this library.

Configuration

The client constructor supports several options you may set to achieve the expected behavior:

client = Contentful::Client.new(
  # ... your options here ...
)
<table> <thead> <tr> <th>Name</th> <th>Default</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code>access_token</code></td> <td></td> <td><strong>Required</strong>. Your access token.</td> </tr> <tr> <td><code>space</code></td> <td></td> <td><strong>Required</strong>. Your space ID.</td> </tr> <tr> <td><code>environment</code></td> <td>'master'</td> <td>Your environment ID.</td> </tr> <tr> <td><code>api_url</code></td> <td><code>'cdn.contentful.com'</code></td> <td>Set the host used to build the request URIs.</td> </tr> <tr> <td><code>default_locale</code></td> <td><code>'en-US'</code></td> <td>Defines default locale for the client.</td> </tr> <tr> <td><code>secure</code></td> <td><code>true</code></td> <td>Defines whether to use HTTPS or HTTP. By default we use HTTPS.</td> </tr> <tr> <td><code>authentication_mechanism</code></td> <td><code>:header</code></td> <td>Sets the authentication mechanisms, valid options are <code>:header</code> or <code>:query_string</code></td> </tr>
View on GitHub
GitHub Stars137
CategoryContent
Updated3d ago
Forks65

Languages

Ruby

Security Score

95/100

Audited on Mar 31, 2026

No findings