Skip to content

chyroc/v2ex-nodejs-sdk

Repository files navigation

V2EX NodeJS SDK

NodeJS(TypeScript) SDK For V2EX(https://www.v2ex.com)

Install

npm i --save @chyroc/v2ex-api

Usage

New Client

get token from https://www.v2ex.com/settings/tokens

import V2EX from "@chyroc/v2ex-api";

const token = process.env.V2EX_TOKEN || ''
const client = new V2EX({token, timeout: 10000})

Get Notifications

const getNotifications = async (client: V2EX) => {
  const {notifications, total} = await client.getNotifications({page: 1})
  console.log('notifications:', notifications)
  console.log('total:', total)
}

Delete Notification

const deleteNotification = async (client: V2EX) => {
  await client.deleteNotification({notificationID: 1})
}

Get Profile

const getProfile = async (client: V2EX) => {
  const profile = await client.getProfile()
  console.log('profile', profile)
}

Get Token

const getToken = async (client: V2EX) => {
  const token = await client.getToken()
  console.log('token', token)
}

Create Token

const createToken = async (client: V2EX) => {
  const token = await client.createToken({
    scope: TokenScope.everything,
    expiration: TokenExpiration.D30,
  })
  console.log('token', token)
}

Get Node

const getNode = async (client: V2EX) => {
  const node = await client.getNode({nodeName: 'python'})
  console.log('node', node)
}

Get Topic By Node

const getTopicByNode = async (client: V2EX) => {
  const topics = await client.getTopicByNode({nodeName: 'python', page: 2})
  console.log('topics', topics)
}

Get Topic

const getTopic = async (client: V2EX) => {
  const topic = await client.getTopic({topicID: 1})
  console.log('topic', topic)
}

Get Topic Reply

const getTopicReply = async (client: V2EX) => {
  const topicReply = await client.getTopicReply({topicID: 1, page: 2})
  console.log('topicReply', topicReply)
}

Get Plane

const getPlanes = async (client: V2EX) => {
  const plane = await client.getPlanes()
  console.log('plane', plane)
}