{"id":13878588,"url":"https://github.com/contentstack/contentstack-ruby","last_synced_at":"2026-04-06T11:03:38.054Z","repository":{"id":36970075,"uuid":"76430863","full_name":"contentstack/contentstack-ruby","owner":"contentstack","description":"Ruby SDK for Contentstack's Content Delivery API","archived":false,"fork":false,"pushed_at":"2026-03-03T08:26:32.000Z","size":152,"stargazers_count":5,"open_issues_count":2,"forks_count":6,"subscribers_count":11,"default_branch":"master","last_synced_at":"2026-03-19T02:55:19.906Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/contentstack.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2016-12-14T06:18:31.000Z","updated_at":"2026-03-03T08:26:36.000Z","dependencies_parsed_at":"2026-01-02T18:08:17.956Z","dependency_job_id":null,"html_url":"https://github.com/contentstack/contentstack-ruby","commit_stats":{"total_commits":95,"total_committers":12,"mean_commits":7.916666666666667,"dds":0.7684210526315789,"last_synced_commit":"157dad2a137dea208324f3f7b1f4402527db54e7"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/contentstack/contentstack-ruby","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contentstack%2Fcontentstack-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contentstack%2Fcontentstack-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contentstack%2Fcontentstack-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contentstack%2Fcontentstack-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/contentstack","download_url":"https://codeload.github.com/contentstack/contentstack-ruby/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/contentstack%2Fcontentstack-ruby/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31469746,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-06T08:36:52.050Z","status":"ssl_error","status_checked_at":"2026-04-06T08:36:51.267Z","response_time":112,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-08-06T08:01:53.985Z","updated_at":"2026-04-06T11:03:38.042Z","avatar_url":"https://github.com/contentstack.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# **Ruby SDK for Contentstack**\n\nContentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/). \n\nContentstack provides Ruby SDK to build application on top of Ruby on Rails. Given below is the detailed guide and helpful resources to get started with our Ruby SDK.\n\n## **Prerequisite**\n\nYou need ruby v2.0 or later installed to use the Contentstack Ruby SDK.\n\n## **Setup and Installation**\n\nAdd the following code to your application's Gemfile and bundle:\n\n    gem 'contentstack'\n\nOr you can run this command in your terminal (you might need administrator privileges to perform this installation):\n\n    gem install contentstack\n\nTo start using the SDK in your application, you will need to initialize the stack by providing the values for the keys given in the code snippet below.\n```ruby\n    # with default region\n    client = Contentstack::Client.new(\"api_key\", \"delivery_token\", \"enviroment_name\")\n    \n    # with specific region\n    client = Contentstack::Client.new(\"api_key\", \"delivery_token\", \"enviroment_name\",{\"region\": Contentstack::Region::EU})\n    \n    # with custom host\n    client = Contentstack::Client.new(\"api_key\", \"delivery_token\", \"enviroment_name\",{\"host\": \"https://custom-cdn.contentstack.com\"})\n```\n\n## **Key Concepts for using Contentstack**\n\n### **Stack**\n\nA stack is like a container that holds the content of your app. Learn more about [stacks](https://www.contentstack.com/docs/guide/stack).\n\n### **Content Type**\n\nContent type lets you define the structure or blueprint of a page or a section of your digital property. It is a form-like page that gives Content Managers an interface to input and upload content. [Read more](https://www.contentstack.com/docs/guide/content-types). \n\n### **Entry**\n\nAn entry is the actual piece of content created using one of the defined content types. Learn more about [Entries](https://www.contentstack.com/docs/guide/content-management#working-with-entries). \n\n### **Asset**\n\nAssets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded to Contentstack. These files can be used in multiple entries. Read more about [Assets](https://www.contentstack.com/docs/guide/content-management#working-with-assets). \n\n### **Environment**\n\nA publishing environment corresponds to one or more deployment servers or a content delivery destination where the entries need to be published. Learn how to work with [Environments](https://www.contentstack.com/docs/guide/environments). \n\n## **Contentstack Ruby SDK: 5-minute Quickstart**\n\n### **Initializing your SDK**\n\nTo initialize the SDK, you need to provide values for the keys given in the snippet below:\n```ruby\n@stack = Contentstack::Client.new(\"api_key\", \"delivery_token\", \"enviroment_name\")\n```\n\nTo get the API credentials mentioned above, log in to your Contentstack account and then in your top panel navigation, go to Settings \u003e Stack to view the API Key and Access Token.\n\n### **Querying content from your stack**\n\nTo fetch all entries of of a content type, use the query given below:\n```ruby\n@entry = stack.content_type(\u003c\u003cCONTENT_TYPE_UID\u003e\u003e).query();\n```\n\nTo fetch a specific entry from a content type, use the following query:\n```ruby\n@entry = stack.content_type(\u003c\u003cCONTENT_TYPE_UID\u003e\u003e).entry(\u003c\u003cENTRY_UID\u003e\u003e);\n```\n\n### Get Multiple Entries\nTo retrieve multiple entries of a content type, specify the content type UID. You can also specify search parameters to filter results:\n```ruby\n@query = @stack.content_type('blog').query\n@entries = @query.where('title', 'welcome')\n                .include_schema\n                .include_count\n                .fetch\nputs \"Total Entries -- #{@entries.count}\"\n@entries.each{|entry| puts \"#{entry.get('title')}\" }\n```\n\nTo retrieve localized versions of entries, you can use the query attribute:\n```ruby\nentry = @stack.content_type('content_type_uid').query.locale('locale_code').fetch()\n```\n\u003e Note: Currently, the above query works in case of retrieving localized versions of multiple entries only.\n\n## **Advanced Queries**\n\nYou can query for content types, entries, assets and more using our Ruby API Reference. \n\n[Ruby API Reference Doc](http://www.rubydoc.info/gems/contentstack)\n\n### Paginating Responses\nIn a single instance, the [Get Multiple Entries](https://www.contentstack.com/docs/developers/ruby/get-started-with-ruby-sdk/#get-multiple-entries) query will retrieve only the first 100 items of the specified content type. You can paginate and retrieve the rest of the items in batches using the [skip](https://www.rubydoc.info/gems/contentstack/Contentstack/Query#skip-instance_method) and [limit](https://www.rubydoc.info/gems/contentstack/Contentstack/Query#limit-instance_method) parameters in subsequent requests.\n\n```ruby\n@stack = Contentstack::Client.new(\"api_key\", \"delivery_token\", \"environment\")\n@entries = @stack.content_type('category').query\n                .limit(20)\n                .skip(50)\n                .fetch\n```\n\n\u003e Note: Currently, the Ruby SDK does not support multiple content types referencing in a single query. For more information on how to query entries and assets, refer the Queries section of our Content Delivery API documentation.\n\n## **Working with Images**\n\nWe have introduced Image Delivery APIs that let you retrieve images and then manipulate and optimize them for your digital properties. It lets you perform a host of other actions such as crop, trim, resize, rotate, overlay, and so on. \n\nFor example, if you want to crop an image (with width as 300 and height as 400), you simply need to append query parameters at the end of the image URL, such as, https://images.contentstack.io/v3/download?crop=300,400. There are several more parameters that you can use for your images. \n\n[Read Image Delivery API documentation](https://www.contentstack.com/docs/developers/apis/image-delivery-api/). \n\n\n## **Using the Sync API with Ruby SDK**\n\nThe Sync API takes care of syncing your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates. Contentstack’s Ruby SDK supports Sync API, which you can use to build powerful apps. Read through to understand how to use the Sync API with Contentstack Ruby SDK.\n[Read Sync API documentation](https://www.contentstack.com/docs/platforms/ruby#using-the-sync-api-with-ruby-sdk).\n\n### Initial sync\n\nThe Initial Sync process performs a complete sync of your app data. It returns all the published entries and assets of the specified stack in response.\n\nTo start the Initial Sync process, use the syncStack method.\n\n```ruby\n@sync_result = @stack.sync({init: true})\n# @sync_result.items: contains sync data\n# @sync_result.pagination_token: for fetching the next batch of entries using pagination token\n# @sync_result.sync_token: for performing subsequent sync after initial sync\n```\n\nThe response also contains a sync token, which you need to store, since this token is used to get subsequent delta updates later, as shown in the Subsequent Sync section below.\n\nYou can also fetch custom results in initial sync by using advanced sync queries.\n\n### Sync pagination\n\nIf the result of the initial sync (or subsequent sync) contains more than 100 records, the response would be paginated. It provides pagination token in the response. You will need to use this token to get the next batch of data.\n\n```ruby \n@sync_result = @stack.sync({pagination_token : \"\u003cpagination_token\u003e\"})\n# @sync_result.items: contains sync data\n# @sync_result.pagination_token: For fetching the next batch of entries using pagination token\n# @sync_result.sync_token: For performing subsequent sync after initial sync\n```\n\n### Subsequent sync\n\nYou can use the sync token (that you receive after initial sync) to get the updated content next time. The sync token fetches only the content that was added after your last sync, and the details of the content that was deleted or updated.\n\n```ruby\n@sync_result = @stack.sync({sync_token : \"\u003csync_token\u003e\"})\n# @sync_result.items: contains sync data\n# @sync_result.pagination_token: For fetching the next batch of entries using pagination token\n# @sync_result.sync_token: For performing subsequent sync after initial sync\n```\n\n### Advanced sync queries\n\nYou can use advanced sync queries to fetch custom results while performing initial sync. \n[Read advanced sync queries documentation](https://www.contentstack.com/docs/guide/synchronization/using-the-sync-api-with-ruby-sdk#advanced-sync-queries)\n\n\n```ruby\n@sync_result = @stack.sync({init : true, locale: \"\u003clocale\u003e\" content_type_uid: \"\u003ccontent_type_uid\u003e\"})\n# @sync_result.items: contains sync data\n# @sync_result.pagination_token: For fetching the next batch of entries using pagination token\n# @sync_result.sync_token: For performing subsequent sync after initial sync\n```\n## **Helpful Links**\n\n* [Contentstack Website](https://www.contentstack.com)\n\n* [Official Documentation](http://contentstack.com/docs)\n\n* [Content Delivery API Docs](https://contentstack.com/docs/apis/content-delivery-api/)\n\n## **The MIT License (MIT)**\n\nCopyright © 2012-2026 [Contentstack](https://www.contentstack.com). All Rights Reserved\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcontentstack%2Fcontentstack-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcontentstack%2Fcontentstack-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcontentstack%2Fcontentstack-ruby/lists"}