Skip to content

Commit

Permalink
fix npm stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna-devv committed Sep 6, 2023
1 parent a436782 commit c6d331f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>).code || null;
const state = (req.query as Record<string, string>).state || null;
const error = (req.query as Record<string, string>).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<string, string>).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 :)
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> (http://lunish.nl/luna/)",
Expand All @@ -25,4 +25,4 @@
"fastify": "^4.22.2",
"typescript": "^4.7.2"
}
}
}

0 comments on commit c6d331f

Please sign in to comment.