Ruby API for Discourse
The Discourse API gem allows you to consume the Discourse API
Add this line to your application's Gemfile:
gem 'discourse_api'And then execute:
$ bundleOr install it yourself as:
$ gem install discourse_apiOver time this project intends to have a full Discourse API. At the moment there are only a few endpoints available:
…You can handle some basic errors by rescuing from certain error classes and inspecting the response object passed to those errors:
begin
client.create_group({ name: 'NO' })
rescue DiscourseApi::UnprocessableEntity => error
# `body` is something like `{ errors: ["Name must be at least 3 characters"] }`
# This outputs "Name must be at least 3 characters"
puts error.response.body['errors'].first
endCheck out lib/discourse_api/error.rb and lib/discourse_api/client.rb's handle_error method for the types of errors raised by the API.
If your forum has a basic HTTP authentication enabled, set user and password:
client.basic_auth = {
user: "test",
password: "secret"
}git checkout -b my-new-feature)git commit -am 'Add some feature')git push origin my-new-feature)bundle exec rake db:api_test_seedbundle exec rails sgem install bundlerbundle exec rspec spec/No open issues yet, or sync has not completed.