Skip to content

Commit

Permalink
Merge pull request #4 from XzavierDunn/fix/request-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
XzavierDunn authored Sep 22, 2023
2 parents b56eb75 + 477260e commit 301f020
Show file tree
Hide file tree
Showing 92 changed files with 2,478 additions and 2,727 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let client: Client = await Client.create_client({
redirect_uri: "...",
});

let album = await client.albums.get_album({ id: "" });
let album = await client.albums.get_album("");
if (album.result) {
let details = {
name: album.result.name,
Expand Down
75 changes: 74 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,76 @@
spotify_wrapper / [Exports](modules.md)
spotify-wrapper-ts / [Exports](modules.md)

[![npm version](https://badge.fury.io/js/spotify-wrapper-ts.svg)](https://badge.fury.io/js/spotify-wrapper-ts)

# [Spotify Web API](https://developer.spotify.com/documentation/web-api) Wrapper

## Usage/Examples

```typescript
let client: Client = await Client.create_client({
client_id: "...",
client_secret: "...",
redirect_uri: "...",
});

let album = await client.albums.get_album("");
if (album.result) {
let details = {
name: album.result.name,
artists: album.result.artists.map((artist) => artist.name),
release_date: album.result.release_date,
};
}

let tracks = await client.tracks.get_several_tracks([""]);
if (tracks.result) {
console.log(tracks.result.tracks.map((track) => track.id));
console.log(tracks.result.tracks.map((track) => track.name));
console.log(tracks.result.tracks.map((track) => track.album.name));
}
```

### User credentials can be supplied with the add_user_info method

_This allows endpoints that require [user permissions](https://developer.spotify.com/documentation/web-api/concepts/scopes) to be hit._

Currently all user authentication must be handled separately, there are no methods to help handle this.

```typescript
let ClientInfo = z.object({
access_token: z.string().optional(),
token_type: z.string().optional(),
expires_in: z.number().optional(),
refresh_token: z.string().optional(),
scope: z.string().optional(),
});

let user_credentials: ClientInfo = {
access_token: "...",
refresh_token: "...",
};

client.add_user_info(user_credentials);

let user_profile = await client.users.get_current_users_profile();
if (user_profile.result) {
console.log(user_profile.result.id);
console.log(user_profile.result.display_name);
}
```

## Documentation

[Documentation](./docs/modules.md)

## Roadmap

- Implement request_user_authorization util

- Improve error handling and return missing scopes

- Clean up request util functions

- Test util functions

- Test client methods
Loading

0 comments on commit 301f020

Please sign in to comment.