From 6c938905f96bed2e8ff6fa248f32986b0deb8fee Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 16 May 2021 18:27:21 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=84=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 19 ++++++++++++++++++- test-d/api.ts | 24 ++++++++++++++++-------- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index cc802ad40d..85ab52f0dd 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,24 @@ coming soon # Usage ## API request -todo +都度インスタンスやトークンを指定する場合 +``` ts +import * as Misskey from 'misskey-js'; + +const meta = await Misskey.api.request('https://misskey.test', 'meta', { detail: true }, 'TOKEN'); +``` + +最初にインスタンスやトークンを指定し、以後のリクエストでその情報を使いまわす場合 +``` ts +import * as Misskey from 'misskey-js'; + +const cli = new Misskey.api.APIClient({ + origin: 'https://misskey.test' +}); +cli.i = { token: 'TOKEN' }; + +const meta = await cli.request('meta', { detail: true }); +``` ## Streaming todo diff --git a/test-d/api.ts b/test-d/api.ts index 32357c2a3b..a8870cdbac 100644 --- a/test-d/api.ts +++ b/test-d/api.ts @@ -1,14 +1,22 @@ -/** - * Unit testing TypeScript types. - * with https://github.com/SamVerschueren/tsd - */ - import { expectType } from 'tsd'; import * as Misskey from '../src'; describe('API', () => { - test('returns node that has sprcified type', async () => { - const res = await Misskey.api.request('https://misskey.test', 'meta', { detail: true }, 'TOKEN'); - expectType(res); + describe('request', () => { + test('success', async () => { + const res = await Misskey.api.request('https://misskey.test', 'meta', { detail: true }, 'TOKEN'); + expectType(res); + }); + }); + + describe('APIClient', () => { + test('success', async () => { + const cli = new Misskey.api.APIClient({ + origin: 'https://misskey.test' + }); + cli.i = { token: 'TOKEN' }; + const res = await cli.request('meta', { detail: true }); + expectType(res); + }); }); });