From 01c3c0318a352fb65b07cc5fa8d8505cf95c90f3 Mon Sep 17 00:00:00 2001 From: Seia-Soto Date: Sun, 14 Feb 2021 04:47:55 +0900 Subject: [PATCH] Add methods to get followers and followings --- src/api/getFollowers.js | 51 ++++++++++++++++++++++++++++ src/api/getFollowings.js | 73 ++++++++++++++++++++++++++++++++++++++++ src/api/index.js | 6 +++- 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 src/api/getFollowers.js create mode 100644 src/api/getFollowings.js diff --git a/src/api/getFollowers.js b/src/api/getFollowers.js new file mode 100644 index 0000000..ff117fc --- /dev/null +++ b/src/api/getFollowers.js @@ -0,0 +1,51 @@ +import agent from '../structures/agent' + +const getFollowers = async (profile, opts) => { // NOTE: opts = Number | Object; + 'use strict' + + if (typeof opts === 'number') { + opts = { + userId: opts + } + } + + opts = opts || {} + + const response = await agent( + '/get_followers', + { + query: { + user_id: opts.userId || -1, + page_size: opts.size || 50, + page: opts.page || 1 + } + }, + { + ...profile, + userId: '(null)' + } + ) + const data = await response.json() + + return data +} + +export default getFollowers + +export const specification = { + count: Number, + next: Number, + previous: Number, + success: Boolean, + users: [ + { + bio: String, + last_active_minutes: Number, + name: String, + photo_url: String, + twitter: String, + user_id: Number, + username: String + } + ] +} diff --git a/src/api/getFollowings.js b/src/api/getFollowings.js new file mode 100644 index 0000000..995d0dc --- /dev/null +++ b/src/api/getFollowings.js @@ -0,0 +1,73 @@ +import agent from '../structures/agent' + +const getFollowings = async (profile, opts) => { // NOTE: opts = Number | Object; + 'use strict' + + if (typeof opts === 'number') { + opts = { + userId: opts + } + } + + opts = opts || {} + + const response = await agent( + '/get_followings', + { + query: { + user_id: opts.userId || -1, + page_size: opts.size || 50, + page: opts.page || 1 + } + }, + { + ...profile, + userId: '(null)' + } + ) + const data = await response.json() + + return data +} + +export default getFollowings + +export const specification = { + clubs: [ + { + club_id: Number, + description: String, + enable_private: Boolean, + is_admin: Number, // Numeric-bool + is_community: Boolean, + is_follow_allowed: Boolean, + is_membership_private: Boolean, + name: String, + num_followers: Number, + num_members: Number, + num_online: Number, + photo_url: String, + rules: [ + { + desc: String, + title: String + } + ] + } + ], + count: Number, + next: Number, + previous: Number, + success: Boolean, + users: [ + { + bio: String, + last_active_minutes: Number, + name: String, + photo_url: String, + twitter: String, + user_id: Number, + username: String + } + ] +} diff --git a/src/api/index.js b/src/api/index.js index d227085..53fb017 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -38,6 +38,8 @@ import addTopic from './addTopic' import removeTopic from './removeTopic' import updateNotifications from './updateNotifications' import updateBio from './updateBio' +import getFollowers from './getFollowers' +import getFollowings from './getFollowings' // NOTE: Externals import getStatic from './getStatic' @@ -83,5 +85,7 @@ export { addTopic, removeTopic, updateNotifications, - updateBio + updateBio, + getFollowers, + getFollowings }