A simple Ruby wrapper for the Ghost Content API.
The Ghost Content API documentation can be found here.
Add spooky to your Gemfile:
gem "spooky"And then run:
$ bundle
To get started, a Ghost client needs to be initialized using the API URL of your Ghost installation and its content API key.
A client can be created by running the below with your credentials:
client = Spooky::Client.new(api_url: "https://blog.yourdomain.com", api_key: "abc123")Spooky also has ENV variable support out of the box. You can set your credentials by setting the below ENV variables:
| Attribute | ENV variable |
|---|---|
| api_url | GHOST_API_URL |
| api_key | GHOST_CONTENT_API_KEY |
If they above are set then all you have to do to initialize a client is:
client = Spooky::Client.newSpooky operates primarily on posts. Methods that return a collection also return a pagination object, if there is one.
posts, pagination = client.postsReturns an array of Spooky::Posts and a pagination meta hash.
posts, pagination = client.posts(tags: true, authors: true)Returns an array of Spooky::Posts with Spooky::Tags and Spooky::Authors where appropriate and a pagination meta hash.
post = client.post_by(id: 'abc123')post = client.post_by(slug: 'this-is-a-slug')Both return a Spooky::Post.
Filtering accepts simple hashes as conditions or NQL strings for more complex filters.
featured_posts, pagination = client.posts(filter: { featured: true })welcome_posts, pagination = client.posts(filter: "title:Welcome")You can exclude a post using NQL operators, note the -:
posts_without_welcome, pagination = client.posts(tags: true, filter: "title:-Welcome")If applicable, Spooky will return the pagination meta hash directly from Ghost. It looks like this:
{
"page" => 1,
"limit" => 3,
"pages" => 3,
"total" => 7,
"next" => 2,
"prev" => nil
}After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Create an issue with your comments or request or open a pull request with your change and accompanying tests. This project adheres to the included Code of Conduct, see CODE_OF_CONDUCT.
The gem is available as open source under the terms of the MIT License.
This gem was originally developed by infinityrobot.