Awesome
Client library for the Disqus API and Real-Time comments. :sparkles:
Install
$ npm install --save neo-disqus
Usage
const Disqus = require('neo-disqus')
const client = new Disqus({
access_token: '',
api_key: '',
api_secret: ''
})
const params = { forum: 'jaidefinichon', limit: 2 }
// Callback
client.get('forums/listThreads', params, (err, posts) => {
console.log(err, posts)
})
// Promise
client.get('forums/listThreads', params).then(posts => {
console.log(posts)
})
REST API
You simply need to pass the endpoint and parameters to one of convenience methods. Take a look at the documentation site to reference available endpoints.
// Callback
client.get(path, params, callback)
client.post(path, params, callback)
// Promise
client.get(path, params).then().catch()
client.post(path, params).then().catch()
Example, get list of trending threads:
client.get('trends/listThreads', (error, trending) => {
console.log(trending)
})
Real Time
The stream
method return instance of WebSocket.
Example, streaming comments:
const params = { forum: 'jaidefinichon', limit: 1 }
client.get('forums/listThreads', params, (e, lastThreads) => {
if (e) return console.error(e)
const id = lastThreads.response[0].id
const stream = client.stream(`thread/${id}`)
stream.on('open', () => { console.log('connected') })
stream.on('message', (message) => {
message = JSON.parse(message)
console.log(message)
})
})
License
MIT