Git Product home page Git Product logo

discourse-api-js's Introduction

Discourse API

Usage

Add the library and your custom code before your </body>:

<script src="js/discourse-api.js"></script>
<script src="js/discourse-custom.js"></script>

Then create an empty file js/discourse-custom.js with the basic info:

var baseURL = 'https://discourse.mozilla-community.org';

Examples

Get latests posts in a category
client = new DiscourseApi(baseURL);
var category = 'mozillians';

client.category(category, function(response) {
// We need to wait until the remote response is back
	if (response) {
		// Your code here  
	}
});

The response variable will include the category object with all information such as:

response.topic_list.topics.length // Number of topics retrieved
response.topic_list.topics[0] // Object with the first topic
response.topic_list.topics[0].slug
response.topic_list.topics[0].id
response.topic_list.topics[0].title
response.topic_list.topics[0].created_at
response.topic_list.topics[0].views
response.topic_list.topics[0].like_count
Get a specific topic
client = new DiscourseApi(baseURL);
var topic = '56';

client.topic(topic, function(response) {
	// We need to wait until the remote response is back
	if (response) {
		// Your code here  
	}
});

The response variable will include the topic object with all information such as:

response.title
response.slug
response.id
response.posts_count // Number of messages, including the first one
response.created_at
response.post_stream.posts[0] // Object with the first message info
response.post_stream.posts[0].username
response.post_stream.posts[0].name
response.post_stream.posts[0].views
response.post_stream.posts[0].like_count
response.post_stream.posts[0].avatar_template
response.post_stream.posts[0].cooked // Message content in HTML

Check example.html and js/discourse-custom.js for a simple example.

There is an advanced example in index.html and js/discourse-blog.js on how to present all topics in a category and their content as a blog.

discourse-api-js's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.