From d5157cc96570ce206395d953bda2e008fd0d6395 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Wed, 18 Mar 2020 22:40:38 +0900
Subject: [PATCH] Fix getRelationship interface to get one account
---
.../typescript/src/mastodon/authorization.ts | 2 +-
example/typescript/src/mastodon/relationship.ts | 17 +++++++++++++++++
src/mastodon.ts | 8 ++++----
src/megalodon.ts | 4 ++--
src/misskey.ts | 6 +++---
5 files changed, 27 insertions(+), 10 deletions(-)
create mode 100644 example/typescript/src/mastodon/relationship.ts
diff --git a/example/typescript/src/mastodon/authorization.ts b/example/typescript/src/mastodon/authorization.ts
index 81ce8024d..57553dd4a 100644
--- a/example/typescript/src/mastodon/authorization.ts
+++ b/example/typescript/src/mastodon/authorization.ts
@@ -7,7 +7,7 @@ const rl: readline.ReadLine = readline.createInterface({
})
const SCOPES: Array = ['read', 'write', 'follow']
-const BASE_URL: string = 'https://mstdn.maud.io'
+const BASE_URL: string = 'https://mastodon.social'
let clientId: string
let clientSecret: string
diff --git a/example/typescript/src/mastodon/relationship.ts b/example/typescript/src/mastodon/relationship.ts
new file mode 100644
index 000000000..c19507781
--- /dev/null
+++ b/example/typescript/src/mastodon/relationship.ts
@@ -0,0 +1,17 @@
+import generator from 'megalodon'
+
+declare var process: {
+ env: {
+ MASTODON_ACCESS_TOKEN: string
+ }
+}
+
+const BASE_URL: string = 'https://mastodon.social'
+
+const access_token: string = process.env.MASTODON_ACCESS_TOKEN
+
+const client = generator('mastodon', BASE_URL, access_token)
+
+client.getRelationship('1').then(res => {
+ console.log(res.data)
+})
diff --git a/src/mastodon.ts b/src/mastodon.ts
index 937316ff6..590bd1a63 100644
--- a/src/mastodon.ts
+++ b/src/mastodon.ts
@@ -502,14 +502,14 @@ export default class Mastodon implements MegalodonInterface {
})
}
- public async getRelationship(ids: Array): Promise> {
+ public async getRelationship(id: string): Promise> {
return this.client
- .get('/api/v1/accounts/relationships', {
- id: ids
+ .get>('/api/v1/accounts/relationships', {
+ id: [id]
})
.then(res => {
return Object.assign(res, {
- data: MastodonAPI.Converter.relationship(res.data)
+ data: MastodonAPI.Converter.relationship(res.data[0])
})
})
}
diff --git a/src/megalodon.ts b/src/megalodon.ts
index 05c8062b5..f7022f00c 100644
--- a/src/megalodon.ts
+++ b/src/megalodon.ts
@@ -310,10 +310,10 @@ export interface MegalodonInterface {
/**
* GET /api/v1/accounts/relationships
*
- * @param ids Array of account IDs.
+ * @param id The account ID.
* @return Relationship
*/
- getRelationship(ids: Array): Promise>
+ getRelationship(id: string): Promise>
/**
* GET /api/v1/accounts/search
*
diff --git a/src/misskey.ts b/src/misskey.ts
index 81c131380..98b37a1b3 100644
--- a/src/misskey.ts
+++ b/src/misskey.ts
@@ -552,12 +552,12 @@ export default class Misskey implements MegalodonInterface {
/**
* POST /api/users/relation
*
- * @param ids Array of the accountID, for example `['1sdfag']`. Only the first element is used.
+ * @param id The accountID, for example `'1sdfag'`
*/
- public async getRelationship(ids: Array): Promise> {
+ public async getRelationship(id: string): Promise> {
return this.client
.post('/api/users/relation', {
- userId: ids[0]
+ userId: id
})
.then(res => {
return Object.assign(res, {