From f8844e18b4281219eb5ae03dac13d671866330f1 Mon Sep 17 00:00:00 2001 From: Tzu-Yin Hong Date: Mon, 2 Aug 2021 22:04:43 +0800 Subject: [PATCH 1/5] document: write a little document --- README.md | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/README.md b/README.md index daa8b7d..776b9a5 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,74 @@ See [README](./nodejs) +## Quick Start + +### Install +``` +$ npm -i @hackmd/api +``` + +### Login and Create a note + +- Copy following into `index.js` + +``` +const { default: API } = require('@hackmd/api') + +const api = new API() + +api.login('your account', 'your password').then(() => { + api.newNote(`# Untitle Add By API`) +}) +``` + +- execute it by `node index.js` + +### Create a note from an example note + +``` +const { default: API, ExportType } = require('@hackmd/api') + +const api = new API() + +api.login('your account', 'your password').then(() => { + api.exportString(process.env.EXAMPLE_NOTE, ExportType.MD).then((res) => { + api.newNote(ejs.render(res)) + }) +}) +``` + +## API Reference + +### API class + +`notice: There are not all the functions. I just write the functions which I am interested in` + +- constructor(config: [APIOptions](#APIOptions)) +- login(email: string, password: string): Promise - method to login +- logout(): Promise - method to logout +- newNote(body: string, options?: [NewNoteOption](#NewNoteOption)): Promise - method to add a new note + - body: string - the content you want to add in the new note, for example: `# api test` +- exportString(noteId: string, type: ExportType): Promise = method to export a note + - noteId: string - the id in the url. If your url of the example note is `https://hackmd.io/XXXOOO`, your noteId is `XXXOOO` + - type: [ExportType](#ExportType) + +#### APIOptions + +- serverUrl: string - optional, the url of the server, for example: `https://hackmd.io` +- cookiePath: string - optional, the path where the cookies save in +- enterprise: boolean - optional, I don't know what it is + +#### NewNoteOption +- team: string - optional, the team id in the url + +#### ExportType + +- PDF: 0 - export to pdf +- SLIDE: 1 - I don't know what it is +- MD: 2 - export to markdown +- HTML: 3 - export to html + ## LICENSE MIT From 06d51fdb619c503fdd82c8474c9e0192e21c0d5f Mon Sep 17 00:00:00 2001 From: Tzu-Yin Hong Date: Mon, 2 Aug 2021 22:06:20 +0800 Subject: [PATCH 2/5] document: fix the wrong example --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 776b9a5..2cccfe4 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,8 @@ const { default: API, ExportType } = require('@hackmd/api') const api = new API() api.login('your account', 'your password').then(() => { - api.exportString(process.env.EXAMPLE_NOTE, ExportType.MD).then((res) => { - api.newNote(ejs.render(res)) + api.exportString('your note id', ExportType.MD).then((res) => { + api.newNote(res) }) }) ``` From e3dc2304e372aab60c9b1833e02083fa3213916a Mon Sep 17 00:00:00 2001 From: Tzu-Yin Hong Date: Mon, 2 Aug 2021 22:07:13 +0800 Subject: [PATCH 3/5] document: beautify example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2cccfe4..e4193ac 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ const api = new API() api.login('your account', 'your password').then(() => { api.exportString('your note id', ExportType.MD).then((res) => { api.newNote(res) - }) + }) }) ``` From d798f11bff6328ce0db65702a4020da8a2c18031 Mon Sep 17 00:00:00 2001 From: Tzu-Yin Hong Date: Mon, 2 Aug 2021 22:11:25 +0800 Subject: [PATCH 4/5] document: fix the api reference --- README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e4193ac..fca116e 100644 --- a/README.md +++ b/README.md @@ -47,12 +47,16 @@ api.login('your account', 'your password').then(() => { `notice: There are not all the functions. I just write the functions which I am interested in` -- constructor(config: [APIOptions](#APIOptions)) -- login(email: string, password: string): Promise - method to login -- logout(): Promise - method to logout -- newNote(body: string, options?: [NewNoteOption](#NewNoteOption)): Promise - method to add a new note +- `constructor(config?: APIOptions)` + - config: optional, [APIOptions](#APIOptions) +- `login(email: string, password: string): Promise` - method to login + - email: string + - password: string +- `logout(): Promise` - method to logout +- `newNote(body: string, options?: NewNoteOption): Promise` - method to add a new note - body: string - the content you want to add in the new note, for example: `# api test` -- exportString(noteId: string, type: ExportType): Promise = method to export a note + - options: optional, [NewNoteOption](#NewNoteOption) +- `exportString(noteId: string, type: ExportType): Promise` = method to export a note - noteId: string - the id in the url. If your url of the example note is `https://hackmd.io/XXXOOO`, your noteId is `XXXOOO` - type: [ExportType](#ExportType) From aa636de6fa32b0187a40dd0121ed8257de1d9129 Mon Sep 17 00:00:00 2001 From: Tzu-Yin Hong Date: Mon, 2 Aug 2021 22:12:28 +0800 Subject: [PATCH 5/5] document: fix a symbol --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fca116e..b707665 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ api.login('your account', 'your password').then(() => { - `newNote(body: string, options?: NewNoteOption): Promise` - method to add a new note - body: string - the content you want to add in the new note, for example: `# api test` - options: optional, [NewNoteOption](#NewNoteOption) -- `exportString(noteId: string, type: ExportType): Promise` = method to export a note +- `exportString(noteId: string, type: ExportType): Promise` - method to export a note - noteId: string - the id in the url. If your url of the example note is `https://hackmd.io/XXXOOO`, your noteId is `XXXOOO` - type: [ExportType](#ExportType)