From c6d331f35ee3a9a0c83cce5c15090e11a2d80842 Mon Sep 17 00:00:00 2001 From: Luna Date: Wed, 6 Sep 2023 16:37:43 +0200 Subject: [PATCH] fix npm stuff --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 8 ++++---- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b94b6e8..773ae8b 100644 --- a/README.md +++ b/README.md @@ -22,5 +22,54 @@ npm install lunify.js yarn add lunify.js ``` +## Example +```ts +import fastify from 'fastify'; + +import Lunify from '../src/lib'; // fix path +import { Scopes } from '../src/interfaces/oauth'; // fix path +import { OauthTokenManager } from '../src/lib/oauth/TokenManager'; // fix path +import { UserManager } from '../src/lib/user'; // fix path + +const app = fastify(); +const api = new Lunify({ + oAuth: { + clientId: '', + clientSecret: '', + redirectUri: 'http://10.0.0.50:7654/callback' + } +}); + +app.get('/login', (req, res) => { + const url = api.oauth.generateUrl([Scopes.Streaming, Scopes.UserModifyPlaybackState, Scopes.UserReadPlaybackState]); + res.redirect(url); +}); + +let access: OauthTokenManager | undefined; + +app.get('/callback', async (req, res) => { + const code = (req.query as Record).code || null; + const state = (req.query as Record).state || null; + const error = (req.query as Record).error || null; + + if (error) return error; + if (!state) return 'INVALID_STATE'; + + access = await api.oauth.fetchToken(code); + + return 'OK'; +}); + +app.put('/play', (req, res) => { + const track = (req.query as Record).track?.split('/track/')?.[1]; + if (!track) return 'INVALID_TRACK'; + + const user = new UserManager(api, access); + user.player.play(track); + + return 'OK'; +}); +``` + ## Documentation Read the code or use your IDEs intellisense :) \ No newline at end of file diff --git a/package.json b/package.json index c3fce0e..3356734 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { - "name": "dlist.js", - "description": "An typescript API wrapper for the discordlist.gg api.", + "name": "lunify.js", + "description": "A basic api wrapper for the spotify api covering the oauth routes.", "version": "0.0.1", "main": "dist/src/lib/index.js", "types": "dist/src/lib/index.d.js", "files": [ - "/dist" + "/dist/src" ], "license": "GPL-3.0 license", "author": "Luna (http://lunish.nl/luna/)", @@ -25,4 +25,4 @@ "fastify": "^4.22.2", "typescript": "^4.7.2" } -} \ No newline at end of file +}