All Projects → workshoptech → discourse-js

workshoptech / discourse-js

Licence: MIT license
JavaScript wrapper around the Discourse API

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to discourse-js

pinboard.net
Fully featured API wrapper for pinboard.in
Stars: ✭ 21 (+31.25%)
Mutual labels:  api-wrapper
discourse-calendar
Adds the ability to create a dynamic calendar in the first post of a topic.
Stars: ✭ 45 (+181.25%)
Mutual labels:  discourse
mojang
A wrapper for the Mojang API and Minecraft website
Stars: ✭ 19 (+18.75%)
Mutual labels:  api-wrapper
autopilot-api
A third-party JavaScript wrapper for Autopilot's REST API.
Stars: ✭ 14 (-12.5%)
Mutual labels:  api-wrapper
pagespeedParseR
pagespeedParseR is an R wrapper for Google Pagespeed Insights API, that also enables convenient parsing
Stars: ✭ 20 (+25%)
Mutual labels:  api-wrapper
discourse-mozilla-theme
Theme used on discourse.mozilla.org
Stars: ✭ 23 (+43.75%)
Mutual labels:  discourse
DiscEval
Discourse Based Evaluation of Language Understanding
Stars: ✭ 18 (+12.5%)
Mutual labels:  discourse
py-flexpoolapi
🐍 Pythonic wrapper for Flexpool Public API
Stars: ✭ 14 (-12.5%)
Mutual labels:  api-wrapper
cryptox
Common API wrapper for multiple crypto currency exchanges
Stars: ✭ 50 (+212.5%)
Mutual labels:  api-wrapper
pyArtifact
Pythonic wrapper around Valve's Artifact API
Stars: ✭ 25 (+56.25%)
Mutual labels:  api-wrapper
clash-api
Ruby wrapper for the Clash of Clans API
Stars: ✭ 14 (-12.5%)
Mutual labels:  api-wrapper
open route service
An encapsulation made around openrouteservice API for Dart and Flutter projects. Made for easy generation of Routes and Directions on Maps, Isochrones, Time-Distance Matrix, Pelias Geocoding, POIs, Elevation and routing Optimizations using their amazing API.
Stars: ✭ 20 (+25%)
Mutual labels:  api-wrapper
tplink-smartplug-api
TP-Link HS1xx smart plug API wrapper.
Stars: ✭ 48 (+200%)
Mutual labels:  api-wrapper
PowerSchool-API
A Node.js library for interacting with the PowerSchool SIS API.
Stars: ✭ 21 (+31.25%)
Mutual labels:  api-wrapper
cbapi-python
Carbon Black API - Python language bindings
Stars: ✭ 140 (+775%)
Mutual labels:  api-wrapper
drip-php
An object-oriented PHP wrapper for Drip's API
Stars: ✭ 22 (+37.5%)
Mutual labels:  api-wrapper
covidtrackerapiwrapper
CovidSharp is a crossplatform C# API wrapper for the Coronavirus tracking API (https://github.com/ExpDev07/coronavirus-tracker-api)
Stars: ✭ 11 (-31.25%)
Mutual labels:  api-wrapper
discourse-telegram-notifications
A plugin for Discourse which allows users to receive their notifications by telegram message
Stars: ✭ 20 (+25%)
Mutual labels:  discourse
nanoleaf-aurora
A java wrapper for the Nanoleaf Aurora API
Stars: ✭ 19 (+18.75%)
Mutual labels:  api-wrapper
mixin bot
A simple API wrapper for Mixin Network in Ruby
Stars: ✭ 12 (-25%)
Mutual labels:  api-wrapper

NPM Version

Contents

Installation

$ npm i discourse-js

Quick Start

import Discourse from 'discourse-js';

const userApiKey = '<user-api-key-from-discourse>';
const apiUsername = '<user-username-from-discourse>';
const baseUrl = '<your-discourse-url>' || 'http://localhost:3000';

const discourse = new Discourse();
discourse.config({ userApiKey, apiUsername, baseUrl })

discourse.posts
  .create({
    topic_id: 11, // optional (required for creating a new post on a topic.)
    raw: 'Hello World',
    imageUri: imageUri, // optional to create a post/topic with an image.
  })
  .then(res => console.log(res))
  .catch(err => console.log(err));

API

Categories

Get Category

discourse.categories
  .getCategory({ cat_id: 'category-id' })
  .then(res => console.log(res))
  .catch(err => console.log(err));

Get Sub-Category

discourse.getSubcategory
  .getCategory({ cat_id: 'category-id', subcat_id: 'subcategory-id' })
  .then(res => console.log(res))
  .catch(err => console.log(err));

Groups

Get Group Members

discourse.groups
  .getMembers({ group_name: 'group-name' })
  .then(res => console.log(res))
  .catch(err => console.log(err));

Messages

Todo


Notifications

Todo


Posts

Create a Post

discourse.posts
  .create({
    topic_id: 11, // optional (required for creating a new post on a topic.)
    raw: 'Hello World',
    imageUri: imageUri, // optional to create a post/topic with an image.
  })
  .then(res => console.log(res))
  .catch(err => console.log(err));

Like a Post

discourse.posts
  .like({ id: 72 })
  .then(res => console.log(res))
  .catch(err => console.log(err));

Unlike a Post

discourse.posts
  .unlike({ id: 72 })
  .then(res => console.log(res))
  .catch(err => console.log(err));

Note: You can only unlike a post within 5 - 10 minutes after you have liked it. Think of unlike more so like an undo.

See this post here and here for information around the undocumented time limit on unliking a liked post.

Reply to a Post

discourse.posts
  .reply({
    topic_id: 72,
    raw: 'Hello World',
    reply_to_post_number: 14,
  })
  .then(res => console.log(res))
  .catch(err => console.log(err));

Topics

Get a Topic

discourse.topics
  .getTopic({ id })
  .then(res => console.log(res)}
  .catch(err => console.log(err))

Topics have a chunk size of 20, which mean you will only get 20 posts back in one get. This can cause weird problems with nested replies and long threads. You can override this by passing print: true. Note this sets the chunk size to 1000. See API: Getting all posts in a topic

discourse.topics
  .getTopic({
    id,
    print: true
  })
  .then(res => console.log(res)}
  .catch(err => console.log(err))

Delete a Topic

  discourse.topics
    .deleteTopic({ id })
    .then(res => console.log(res)} // Note: delete returns nothing.
    .catch(err => console.log(err))

Users

Get a single User

discourse.users
  .getUser({ username })
  .then(res => console.log(res)}
  .catch(err => console.log(err))

Local Development

This is if you are developing the discourse-js API locally on your machine.

# Clone the repo
$ git clone [email protected]:theworkshop/discourse-js.git
$ cd discourse-js
$ pwd|pbcopy # Copies the current working directory /path/to/discourse-js/
# cd into the directory you want to test locally.
$ npm install /path/to/discourse-js/

Why not just use npm link?:

For speed and productivity. Symlinks do not work with React Native 💩📲.

Read more about npm link and why we do this here.

You will also need a Discourse server running. This can be local or running in the cloud.

Publishing a new Version

Bump the version of the package:

yarn version --patch/--minor/--major

Our preversion, version, and postversion will run, create a new tag in git and push it to our remote repository. The updated package will then be published on npm.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].