Skip to content

Commit

Permalink
Merge branch 'master' into fix-spotify-precision
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho authored Mar 1, 2024
2 parents 1ddea72 + 6bff51c commit 7215f9f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.13.2

- add codeVerifier for oauth flow
- add method to expand spotify's shortened URLs
- e.g. `await spotify.expandLink('https://spotify.link/hRkBrwub9xb')`

## 0.13.1

- fix empty playbackState returning 404
Expand Down
8 changes: 5 additions & 3 deletions lib/src/spotify_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ class SpotifyApi extends SpotifyApiBase {

static oauth2.AuthorizationCodeGrant authorizationCodeGrant(
SpotifyApiCredentials credentials,
{Function(SpotifyApiCredentials)? onCredentialsRefreshed}) {
return SpotifyApiBase.authorizationCodeGrant(
credentials, http.Client(), onCredentialsRefreshed);
{String? codeVerifier,
Function(SpotifyApiCredentials)? onCredentialsRefreshed}) {
return SpotifyApiBase.authorizationCodeGrant(credentials, http.Client(),
codeVerifier: codeVerifier,
onCredentialsRefreshed: onCredentialsRefreshed);
}
}
29 changes: 24 additions & 5 deletions lib/src/spotify_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,57 @@ abstract class SpotifyApiBase {
'https://accounts.spotify.com/authorize';

bool _shouldWait = false;
late FutureOr<oauth2.Client> _client;

late FutureOr<oauth2.Client> _client;
FutureOr<oauth2.Client> get client => _client;

late Artists _artists;
Artists get artists => _artists;

late Albums _albums;
Albums get albums => _albums;

late Browse _browse;
Browse get browse => _browse;

late Tracks _tracks;
Tracks get tracks => _tracks;

late Playlists _playlists;
Playlists get playlists => _playlists;

late Episodes _episodes;
Episodes get episodes => _episodes;

late RecommendationsEndpoint _recommendations;
RecommendationsEndpoint get recommendations => _recommendations;

late Markets _markets;
Markets get markets => _markets;

late Users _users;
Users get users => _users;

late Search _search;
Search get search => _search;

late AudioFeatures _audioFeatures;
AudioFeatures get audioFeatures => _audioFeatures;

late AudioAnalysisEndpoint _audioAnalysis;
AudioAnalysisEndpoint get audioAnalysis => _audioAnalysis;

late Categories _categories;
Categories get categories => _categories;

late Me _me;
Me get me => _me;

late PlayerEndpoint _player;
PlayerEndpoint get player => _player;

late Shows _shows;
Shows get shows => _shows;
FutureOr<oauth2.Client> get client => _client;

SpotifyApiBase.fromClient(FutureOr<http.BaseClient> client) {
_client = client as FutureOr<oauth2.Client>;
Expand Down Expand Up @@ -94,22 +111,24 @@ abstract class SpotifyApiBase {

static oauth2.AuthorizationCodeGrant authorizationCodeGrant(
SpotifyApiCredentials credentials, http.Client httpClient,
[Function(SpotifyApiCredentials)? callBack]) {
{String? codeVerifier,
Function(SpotifyApiCredentials)? onCredentialsRefreshed}) {
return oauth2.AuthorizationCodeGrant(
credentials.clientId!,
Uri.parse(SpotifyApiBase._authorizationUrl),
Uri.parse(SpotifyApiBase._tokenUrl),
secret: credentials.clientSecret,
codeVerifier: codeVerifier,
httpClient: httpClient,
onCredentialsRefreshed: callBack != null
onCredentialsRefreshed: onCredentialsRefreshed != null
? (oauth2.Credentials cred) {
final newCredentials = SpotifyApiCredentials(
credentials.clientId, credentials.clientSecret,
accessToken: cred.accessToken,
expiration: cred.expiration,
refreshToken: cred.refreshToken,
scopes: cred.scopes);
callBack(newCredentials);
onCredentialsRefreshed(newCredentials);
}
: null);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: spotify
description: An incomplete dart library for interfacing with the Spotify Web API.
version: 0.13.1
version: 0.13.2
homepage: https://github.com/rinukkusu/spotify-dart

environment:
Expand Down
1 change: 0 additions & 1 deletion test/spotify_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:convert';
import 'spotify_mock.dart';
import 'package:test/test.dart';
import 'package:spotify/spotify.dart';
Expand Down

0 comments on commit 7215f9f

Please sign in to comment.