The Discourse API gem allows you to consume the Discourse API
This api lets you access some data from https://mycollegeforums.com
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 a few endpoints available:
client = DiscourseApi::Client.new("https://mycollegeforums.com")
client.api_key = "10fd9bbfe588cd47a33e7f4a2c81902a9c11ceeb92ff55823179b564d96607ac"
client.api_username = "piyush"
client.ssl(...) #=> specify SSL connection settings if needed
# Topic endpoints
client.latest_topics #=> Gets a list of the latest topics
client.hot_topics #=> Gets a list of hot topics
client.new_topics #=> Gets a list of new topics
client.topics_by("sam") #=> Gets a list of topics created by user "sam"
client.topic(57) #=> Gets the topic with id 57
# Search endpoint
client.search("sandbox") #=> Gets a list of topics that match "sandbox"
# Categories endpoint
client.categories #=> Gets a list of categories
client.category_latest_topics(category_slug: "lounge") #=> Gets a list of latest topics in a category
# SSO endpoint
client.sync_sso( #=> Synchronizes the SSO record
sso_secret: "discourse_sso_rocks",
name: "Test Name",
username: "test_name",
email: "name@example.com",
external_id: "2"
)
# Private messages
client.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 user
title: "Confidential: Hello World!",
raw: "This is the raw markdown for my private message",
target_usernames: "user1,user2"
)
- 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/