{"id":21533527,"url":"https://github.com/waymondo/strapi-ruby","last_synced_at":"2025-04-10T00:44:42.750Z","repository":{"id":49361624,"uuid":"443849666","full_name":"waymondo/strapi-ruby","owner":"waymondo","description":"Simple Ruby classes for Strapi content types","archived":false,"fork":false,"pushed_at":"2023-07-03T16:13:31.000Z","size":76,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T00:44:35.405Z","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/waymondo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-02T19:14:00.000Z","updated_at":"2024-02-29T00:12:47.000Z","dependencies_parsed_at":"2024-11-24T02:33:02.363Z","dependency_job_id":null,"html_url":"https://github.com/waymondo/strapi-ruby","commit_stats":{"total_commits":27,"total_committers":2,"mean_commits":13.5,"dds":0.03703703703703709,"last_synced_commit":"5e33ef60c020b94fae10c9f380ca4d224dbed91f"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waymondo%2Fstrapi-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waymondo%2Fstrapi-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waymondo%2Fstrapi-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waymondo%2Fstrapi-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/waymondo","download_url":"https://codeload.github.com/waymondo/strapi-ruby/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137997,"owners_count":21053775,"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-11-24T02:32:51.808Z","updated_at":"2025-04-10T00:44:42.725Z","avatar_url":"https://github.com/waymondo.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Strapi\n\n[Strapi](https://strapi.io) is an Open source Node.js Headless CMS to easily build customizable\nAPIs. It’s great for quickly building your data layer alongside a UI to manage it.\n\nSay you (like me) like to quickly build sites and applications in Ruby and/or/on Rails. The goal of\nthe Strapi gem is to make it just as easy to define Ruby classes that represent and interact with\nyour Strapi content types as it is to define them within Strapi itself.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'strapi'\n```\n\nOr if you want to run the absolute latest, potentially unreleased version:\n\n``` ruby\ngem 'strapi', github: 'waymondo/strapi-ruby'\n```\n\nAnd then execute:\n\n    $ bundle install\n\n## Usage\n\nNote: this gem has only been tested with Strapi v4. It may work with previous versions of Strapi, but they\nremain untested at this time.\n\n### Configuration\n\nYou will first need to set an `ENV` variable for `STRAPI_HOST_URL`, `STRAPI_IDENTIFIER` and\n`STRAPI_PASSWORD`. This can be done with [`dotenv`](https://github.com/bkeepers/dotenv/), in an\ninitializer, or some other mechanism.\n\nIf using `dotev`, your `.env` file would contain:\n\n```\nSTRAPI_HOST_URL=http://localhost:1337\nSTRAPI_IDENTIFIER=admin@example.com\nSTRAPI_PASSWORD=password\n```\n\nThe `STRAPI_IDENTIFIER` and `STRAPI_PASSWORD` should be the login information for a user with a role\nthat grants access to your authenticated content. [Strapi Authenticated request\ndocumentation](https://docs.strapi.io/developer-docs/latest/guides/auth-request.html)\n\nUpon running the first method that interacts with the Strapi API, a JWT token will be fetched and\ncached.\n\n### Defining Content Type Classes\n\nIn Ruby, define some content type classes, i.e.:\n\n``` ruby\nclass Farm \u003c Strapi::ContentType\n  field :name\n  field :cows, content_type: 'Cow'\n  field :photo, content_type: 'Strapi::Media'\nend\n```\n\n``` ruby\nclass Cow \u003c Strapi::ContentType\n  field :name\n  field :farm, content_type: 'Farm'\nend\n```\n\nUsing the `field` class method will define getter and setter methods for the class objects. If you\nsupply a class name to the `content_type` option, it will transform it to an instance of that class\nwhen using the getter method. This works for both one-to-one and one-to-many relations:\n\n``` ruby\ncow.name # =\u003e \"Hershey\"\ncow.farm # =\u003e #\u003cFarm\u003e\nfarm.name # =\u003e \"McDonald’s\"\nfarm.cows # =\u003e [#\u003cCow\u003e, #\u003cCow\u003e]\n```\n\nIn keeping with ruby conventions, attribute keys returned from your Strapi API will be underscored,\nso if you have an attribute of `\"colorPattern\": \"jersey\"` in your JSON, your field definition should\nbe `field :color_pattern`.\n\n[`Strapi::Media`](https://github.com/waymondo/strapi-ruby/blob/main/lib/strapi/media.rb) is an\nincluded content type class to represent photos, videos, and files. Feel free to extend this class\nif you would like to add additional functionality or granularity.\n\n``` ruby\nfarm.photo # =\u003e #\u003cStrapi::Media\u003e\nfarm.photo.url # =\u003e \"http://localhost:1337/uploads/farm-1.jpg\"\n```\n\nBy default, `Strapi::ContentType` will infer it’s API plural id from the demodulized, dasherized,\npluralized name of the ruby class. For example, it would assume a class of `FarmWorker` would have a\nStrapi plural ID of `farm-workers`. If you would like to customize this, you can set it in the class\ndefinition:\n\n``` ruby\nclass FarmWorker\n  plural_id 'farmers'\nend\n```\n\nStrapi default timestamps fields (`created_at`, `updated_at`, `published_at`) are automatically converted\ninto `DateTime` objects and do not need to be added with `field` declarations.\n\n### Fetching Entries\n\n`Strapi::ContentType` provides some predictable methods for retrieving entries from your Strapi API:\n\n``` ruby\nCow.all # =\u003e [#\u003cCow\u003e, #\u003cCow\u003e, #\u003cCow\u003e]\ncow = Cow.find(1)\ncow.id # =\u003e 1\n```\n\nBoth `.all` and `.find` accept a hash of options that map to Strapi’s allowed [API\nparameters](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest-api.html). No\nparameter options are included by default, so if you want to eagerly load related content types for\nexample, you’ll need to specify that with the `populate` option:\n\n``` ruby\ncows = Cow.all(populate: '*')\ncows.first.farm.name # =\u003e \"McDonald’s\"\nfarm = Farm.find(1, populate: ['cows'])\nfarm.cows.first.name # =\u003e \"Hershey\"\n```\n\nThe class method `.where` also exists, which is the same implementation as `.all`, except a hash of\nAPI parameters is required.\n\n``` ruby\ncows = Cow.where(filters: { name: { '$eq': 'Hershey' } })\n```\n\n### Pagination\nIn order to paginate results, you can have to provide the Strapi's [API pagination parameters](https://docs.strapi.io/dev-docs/api/rest/sort-pagination#pagination), it will return an\n`Strapi::CollectionContentType` object with the following convenience methods:\n\n```ruby\nfarms = Farm.all(pagination: { page: 1, pageSize: 10 })\n\n# Collection's methods\nfarms.size # =\u003e 10 # or count\nfarms.has_next_page? # =\u003e true\nfarms.first # =\u003e #\u003cFarm\u003e\n\n# Pagination's methods\nfarms.pagination.page # =\u003e 1\nfarms.pagination.page_size # =\u003e 10\nfarms.pagination.page_count # =\u003e 5\nfarms.pagination.total # =\u003e 45\n```\n\n### Creating, Updating, Deleting\n\nYou can create and update entries by calling `.save` on them:\n\n``` ruby\ncow = Cow.new(name: 'Hershey')\ncow.id # =\u003e nil\ncow.save # =\u003e performs POST request\ncow.id # =\u003e 1\ncow = Cow.find(1)\ncow.name = 'Bessie'\ncow.save # =\u003e performs PUT request\n```\n\nYou can also use `create` class method to more concisely create entries:\n\n``` ruby\ncow = Cow.create(name: 'Bessie')\ncow.id # =\u003e 1\n```\n\nYou can delete entries by calling `.delete` on them:\n\n``` ruby\ncow = Cow.find(1)\ncow.delete # =\u003e performs DELETE request\ncow = Cow.find(1) # =\u003e raises Strapi::Error\n```\n\n### Error Handling\n\nAny non successful Strapi request will raise a\n[Strapi::Error](https://github.com/waymondo/strapi-ruby/blob/main/lib/strapi/error.rb) with the API\nresponse’s status, message, and payload, which you can rescue and handle accordingly:\n\n``` ruby\ndef show\n  cow = Cow.find(123)\n  render :cow, cow: cow\nrescue Strapi::Error =\u003e e\n  render :error, message: e.message\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run\nthe tests. You can also run `bin/console` for an interactive prompt that will allow you to\nexperiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new\nversion, update the version number in `version.rb`, and then run `bundle exec rake release`, which\nwill create a git tag for the version, push git commits and the created tag, and push the `.gem`\nfile to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/waymondo/strapi-ruby.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaymondo%2Fstrapi-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaymondo%2Fstrapi-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaymondo%2Fstrapi-ruby/lists"}