Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Add methods to get followers and followings
Browse files Browse the repository at this point in the history
  • Loading branch information
seia-soto committed Feb 13, 2021
1 parent 719630f commit 01c3c03
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 1 deletion.
51 changes: 51 additions & 0 deletions src/api/getFollowers.js
Original file line number Diff line number Diff line change
@@ -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
}
]
}
73 changes: 73 additions & 0 deletions src/api/getFollowings.js
Original file line number Diff line number Diff line change
@@ -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
}
]
}
6 changes: 5 additions & 1 deletion src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -83,5 +85,7 @@ export {
addTopic,
removeTopic,
updateNotifications,
updateBio
updateBio,
getFollowers,
getFollowings
}

0 comments on commit 01c3c03

Please sign in to comment.