- Notifications
You must be signed in to change notification settings - Fork168
discourse/discourse_api
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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:
$ bundle
Or install it yourself as:
$ gem install discourse_api
Over time this project intends to have a full Discourse API. At the moment there are only afew endpoints available:
client=DiscourseApi::Client.new("http://try.discourse.org")client.api_key="YOUR_API_KEY"client.api_username="YOUR_USERNAME"client.ssl(...)#=> specify SSL connection settings if needed# Topic endpointsclient.latest_topics#=> Gets a list of the latest topicsclient.new_topics#=> Gets a list of new topicsclient.topics_by("sam")#=> Gets a list of topics created by user "sam"client.topic(57)#=> Gets the topic with id 57# Search endpointclient.search("sandbox")#=> Gets a list of topics that match "sandbox"# Categories endpointclient.categories#=> Gets a list of categoriesclient.category_latest_topics(category_slug:"lounge")#=> Gets a list of latest topics in a category# SSO endpointclient.sync_sso(#=> Synchronizes the SSO recordsso_secret:"discourse_sso_rocks",name:"Test Name",username:"test_name",email:"name@example.com",external_id:"2",custom_fields:{field_1:'potato'})# Private messagesclient.private_messages("test_user")#=> Gets a list of private messages received by "test_user"client.sent_private_messages("test_user")#=> Gets a list of private messages sent by "test_user"client.create_private_message(#=> Creates a private messages by api_username usertitle:"Confidential: Hello World!",raw:"This is the raw markdown for my private message",target_usernames:"user1,user2")
You can handle some basic errors by rescuing from certain error classes and inspecting the response object passed to those errors:
beginclient.create_group({name:'NO'})rescueDiscourseApi::UnprocessableEntity=>error# `body` is something like `{ errors: ["Name must be at least 3 characters"] }`# This outputs "Name must be at least 3 characters"putserror.response.body['errors'].firstend
Check outlib/discourse_api/error.rb andlib/discourse_api/client.rb'shandle_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"}
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
- Install discourse locally
- Inside of your discourse directory, run:
bundle exec rake db:api_test_seed
- Start discourse:
bundle exec rails s
- Install bundler in the discourse_api directory, run
gem install bundler
- Inside of your discourse_api directory, run:
bundle exec rspec spec/
About
Ruby API for Discourse
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.