GhostRb
GhostRb is a simple REST API client to interact with a given Ghost blog. As of now, it supports Client Authentication, which means it can only query public data.
Installation
Add this line to your application’s Gemfile:
gem 'ghost_rb'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ghost_rb
Usage
Client
To create a new client:
client = GhostRb::Client.new('URL', 'CLIENT_ID', 'CLIENT_SECRET')
Note: If parameters are not specified for resources retrieval, the default values, as specified by Ghost API, are used.
Posts
To access posts from the blog, first create a controller:
ctrl = GhostRb::Controllers::PostsController.new(client) # using previous defined client var
A handier way to get the controller is:
ctrl = client.posts
Single post by id
post = client.posts.find_by(id: 'lhafdkaalkdfha')
Single post by slug
post = client.posts.find_by(slug: 'welcome-to-ghost')
Get all post by setting the limit
posts = client.posts.limit('all').all
Using where
ctrl = client.posts
posts = posts.where(include: 'tags, author', limit: 5).all
Tags
Similarly for tags, you can create directly the controller or call it from the client instance.
ctrl = GhostRb::Controllers::TagsController.new(client)
# or
ctrl = client.tags
All tags
tags = client.tags.limit('all').all
Documentation
The documentation lives at the github pages. For the nitty gritty details of the implementation go to http://www.rubydoc.info/gems/ghost_rb.
You can also go check this post where I have provided an analysis of the implementation.
Development
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.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/renehernandez/ghost_rb.
License
The gem is available as open source under the terms of the MIT License.