Skip to content

Commit

Permalink
Merge pull request #209 from gmpassos/lints-3.0.0
Browse files Browse the repository at this point in the history
lints 3.0.0
  • Loading branch information
rinukkusu authored Mar 2, 2024
2 parents 7f5a628 + 6dab05a commit acef46d
Show file tree
Hide file tree
Showing 52 changed files with 206 additions and 181 deletions.
26 changes: 16 additions & 10 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ name: Dart CI
on: [push, pull_request]

jobs:
build:

build:
runs-on: ubuntu-latest

container:
image: dart:latest

steps:
- uses: actions/checkout@v1
- name: Install dependencies
run: dart pub get
- name: Run tests
run: dart test
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
- name: Dart version
run: |
dart --version
uname -a
- name: Install dependencies
run: dart pub get
- name: dart format
run: dart format -o none --set-exit-if-changed .
- name: dart analyze
run: dart analyze --fatal-infos --fatal-warnings .
- name: Run tests
run: dart run test

2 changes: 0 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ linter:
- cancel_subscriptions
- close_sinks
- hash_and_equals
- iterable_contains_unrelated_type
- list_remove_unrelated_type
- test_types_in_equals
- unrelated_type_equality_checks
- valid_regexps
33 changes: 20 additions & 13 deletions example/example.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) 2017, 2020 rinukkusu, hayribakici. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

// ignore_for_file: deprecated_member_use_from_same_package

import 'dart:io';
import 'dart:convert';
import 'package:spotify/spotify.dart';
Expand Down Expand Up @@ -30,43 +32,48 @@ void main() async {

print('\nArtists:');
var artists = await spotify.artists.list(['0OdUWJ0sBjDrqHygGUXeCF']);
artists.forEach((x) => print(x.name));
for (var x in artists) {
print(x.name);
}

print('\nAlbum:');
var album = await spotify.albums.get('2Hog1V8mdTWKhCYqI5paph');
print(album.name);

print('\nAlbum Tracks:');
var tracks = await spotify.albums.getTracks(album.id!).all();
tracks.forEach((track) {
for (var track in tracks) {
print(track.name);
});
}

print('\nNew Releases');
var newReleases = await spotify.browse.getNewReleases().first();
newReleases.items!.forEach((album) => print(album.name));
for (var album in newReleases.items!) {
print(album.name);
}

print('\nFeatured Playlist:');
var featuredPlaylists = await spotify.playlists.featured.all();
featuredPlaylists.forEach((playlist) {
for (var playlist in featuredPlaylists) {
print(playlist.name);
});
}

print('\nUser\'s playlists:');
var usersPlaylists =
await spotify.playlists.getUsersPlaylists('superinteressante').all();
usersPlaylists.forEach((playlist) {
for (var playlist in usersPlaylists) {
print(playlist.name);
});
}

print("\nSearching for \'Metallica\':");
print("\nSearching for 'Metallica':");
var search = await spotify.search.get('metallica').first(2);

search.forEach((pages) {
for (var pages in search) {
if (pages.items == null) {
print('Empty items');
}
pages.items!.forEach((item) {

for (var item in pages.items!) {
if (item is PlaylistSimple) {
print('Playlist: \n'
'id: ${item.id}\n'
Expand Down Expand Up @@ -123,8 +130,8 @@ void main() async {
'releaseDatePrecision: ${item.releaseDatePrecision}\n'
'-------------------------------');
}
});
});
}
}

var relatedArtists =
await spotify.artists.relatedArtists('0OdUWJ0sBjDrqHygGUXeCF');
Expand Down
22 changes: 15 additions & 7 deletions example/example_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,16 @@ Future<SpotifyApi?> _getUserAuthenticatedSpotifyApi(

print(
'Please paste this url \n\n$authUri\n\nto your browser and enter the redirected url:');
var redirectUrl;

Uri? redirectUrl;
var userInput = stdin.readLineSync();
if (userInput == null || (redirectUrl = Uri.tryParse(userInput)) == null) {
print('Invalid redirect url');
return null;
}

var client =
await grant.handleAuthorizationResponse(redirectUrl.queryParameters);
await grant.handleAuthorizationResponse(redirectUrl!.queryParameters);
return SpotifyApi.fromClient(client);
}

Expand Down Expand Up @@ -309,16 +310,23 @@ Future<Iterable<Track>> _getPlaylistTracks(

Future<PlaybackState?> _play(SpotifyApi spotify) async {
var track = await spotify.tracks.get('6zW80jVqLtgSF1yCtGHiiD');
print('Playing "${track.name} - ${track.artists?.first.name}" with track context for 10 s');
var result = await spotify.player.startWithTracks(['spotify:track:6zW80jVqLtgSF1yCtGHiiD?si=99fd66ccb2464bad'], positionMs: 10000);
print(
'Playing "${track.name} - ${track.artists?.first.name}" with track context for 10 s');
var result = await spotify.player.startWithTracks(
['spotify:track:6zW80jVqLtgSF1yCtGHiiD?si=99fd66ccb2464bad'],
positionMs: 10000);
sleep(Duration(seconds: 10));
print('Pausing...');
spotify.player.pause();
var album = await spotify.albums.get('0rwbMKjNkp4ehQTwf9V2Jk');
track = await spotify.tracks.get('4VnDmjYCZkyeqeb0NIKqdA');
print('Playing album "${album.name} - ${album.artists?.first.name}" with uri context');
print('and offset to "${track.name} - ${track.artists?.first.name}" for 10 s');
result = await spotify.player.startWithContext('spotify:album:0rwbMKjNkp4ehQTwf9V2Jk?si=HA-mX2mPQ1CUp7ExfdDt2g', offset: UriOffset('spotify:track:4VnDmjYCZkyeqeb0NIKqdA'));
print(
'Playing album "${album.name} - ${album.artists?.first.name}" with uri context');
print(
'and offset to "${track.name} - ${track.artists?.first.name}" for 10 s');
result = await spotify.player.startWithContext(
'spotify:album:0rwbMKjNkp4ehQTwf9V2Jk?si=HA-mX2mPQ1CUp7ExfdDt2g',
offset: UriOffset('spotify:track:4VnDmjYCZkyeqeb0NIKqdA'));
sleep(Duration(seconds: 10));

return result;
Expand Down
4 changes: 3 additions & 1 deletion lib/src/authorization_scope.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) 2023, hayribakici. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

part of spotify;
// ignore_for_file: deprecated_member_use_from_same_package

part of '../spotify.dart';

/// Class holding all available authorization scopes.
/// See [Spotify scopes documentation](https://developer.spotify.com/documentation/web-api/concepts/scopes)
Expand Down
4 changes: 2 additions & 2 deletions lib/src/endpoints/albums.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) 2017, rinukkusu. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

part of spotify;
part of '../../spotify.dart';

/// Endpoint for albums `v1/albums`
class Albums extends EndpointPaging {
@override
String get _path => 'v1/albums';

Albums(SpotifyApiBase api) : super(api);
Albums(super.api);

/// Retrieves an album with its [albumId]
Future<Album> get(String albumId) async {
Expand Down
8 changes: 4 additions & 4 deletions lib/src/endpoints/artists.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) 2017, rinukkusu. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

part of spotify;
part of '../../spotify.dart';

/// Endpoint for artists `v1/artists`
class Artists extends EndpointPaging {
@override
String get _path => 'v1/artists';

Artists(SpotifyApiBase api) : super(api);
Artists(super.api);

/// Retrieves an artist with its [artistId]
Future<Artist> get(String artistId) async {
Expand Down Expand Up @@ -72,9 +72,9 @@ class Artists extends EndpointPaging {
Market? country,
List<String>? includeGroups,
}) {
final _includeGroups = includeGroups?.join(',');
final includeGroups0 = includeGroups?.join(',');
final query = _buildQuery({
'include_groups': _includeGroups,
'include_groups': includeGroups0,
'country': country?.name,
});
return _getPages(
Expand Down
4 changes: 2 additions & 2 deletions lib/src/endpoints/audio_analysis.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) 2021, grabajuice. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

part of spotify;
part of '../../spotify.dart';

/// Endpoint of a tracks audio analysis
class AudioAnalysisEndpoint extends EndpointBase {
@override
String get _path => 'v1/audio-analysis';

AudioAnalysisEndpoint(SpotifyApiBase api) : super(api);
AudioAnalysisEndpoint(super.api);

Future<AudioAnalysis> get(String trackId) async {
var jsonString = await _api._get('$_path/$trackId');
Expand Down
4 changes: 2 additions & 2 deletions lib/src/endpoints/audio_features.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) 2017, rinukkusu. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

part of spotify;
part of '../../spotify.dart';

/// Endpoint of audio features `v1/audio-features`
class AudioFeatures extends EndpointBase {
@override
String get _path => 'v1/audio-features';

AudioFeatures(SpotifyApiBase api) : super(api);
AudioFeatures(super.api);

/// Returns audio features of a track with [trackId]
Future<AudioFeature> get(String trackId) async {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/endpoints/browse.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
part of spotify;
part of '../../spotify.dart';

/// Endpoint of browse `v1/browse`
class Browse extends EndpointPaging {
Browse(SpotifyApiBase api) : super(api);
Browse(super.api);

@override
String get _path => 'v1/browse';
Expand Down
4 changes: 2 additions & 2 deletions lib/src/endpoints/categories.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
part of spotify;
part of '../../spotify.dart';

/// Endpoint of browsing the categories `v1/browse/categories`
class Categories extends Browse {
@override
String get _path => '${super._path}/categories';

Categories(SpotifyApiBase api) : super(api);
Categories(super.api);

/// [country] - a country: an ISO 3166-1 alpha-2 country code. Provide this
/// parameter if you want to narrow the list of returned categories to those
Expand Down
2 changes: 1 addition & 1 deletion lib/src/endpoints/endpoint_base.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2017, rinukkusu. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

part of spotify;
part of '../../spotify.dart';

/// Base class of all endpoint classes
abstract class EndpointBase {
Expand Down
27 changes: 11 additions & 16 deletions lib/src/endpoints/endpoint_paging.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) 2017, 2018, hayribakici, chances. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

part of spotify;
part of '../../spotify.dart';

/// Base class of all endpoints using pagination
abstract class EndpointPaging extends EndpointBase {
EndpointPaging(SpotifyApiBase api) : super(api);
EndpointPaging(super.api);

Pages<T> _getPages<T>(String path, ParserFunction<T> pageItemParser,
[String? pageKey, ParserFunction<Object>? pageContainerParser]) =>
Expand Down Expand Up @@ -63,9 +63,7 @@ abstract class BasePage<T> {

/// A page that uses an offset to get to the next page.
class Page<T> extends BasePage<T> {
Page(Paging<T> _paging, ParserFunction<T> pageItemParser,
[Object? pageContainer])
: super(_paging, pageItemParser, pageContainer);
Page(Paging<T> super._paging, super.pageItemParser, [super.pageContainer]);

@override
bool get isLast {
Expand All @@ -85,9 +83,8 @@ class Page<T> extends BasePage<T> {

/// A page that uses a cursor to get to the next page
class CursorPage<T> extends BasePage<T> {
CursorPage(CursorPaging<T> _paging, ParserFunction<T> pageItemParser,
[Object? pageContainer])
: super(_paging, pageItemParser, pageContainer);
CursorPage(CursorPaging<T> super._paging, super.pageItemParser,
[super.pageContainer]);

@override
dynamic get _next => (_paging as CursorPaging<T>).cursors?.after ?? '';
Expand Down Expand Up @@ -202,7 +199,7 @@ abstract class SinglePages<T, V extends BasePage<T>> extends _Pages
firstPage.then(handlePageAndGetNext);
}, onCancel: () {
_cancelled = true;
return Future.value(true);
return;
}, onResume: () {
_bufferedPages.forEach(stream.add);
if (_bufferedPages.last.isLast) {
Expand All @@ -216,9 +213,8 @@ abstract class SinglePages<T, V extends BasePage<T>> extends _Pages

/// Handles retrieval of a page through an offset
class Pages<T> extends SinglePages<T, Page<T>> with OffsetStrategy<Page<T>> {
Pages(SpotifyApiBase api, String path, ParserFunction<T> pageParser,
[String? pageKey, ParserFunction<Object>? pageContainerMapper])
: super(api, path, pageParser, pageKey, pageContainerMapper);
Pages(super.api, super.path, super.pageParser,
[super.pageKey, super.pageContainerMapper]);

Pages.fromPaging(
SpotifyApiBase api, Paging<T> paging, ParserFunction<T> pageParser,
Expand Down Expand Up @@ -250,9 +246,8 @@ class Pages<T> extends SinglePages<T, Page<T>> with OffsetStrategy<Page<T>> {
/// Handles retrieval of a page through a cursor
class CursorPages<T> extends SinglePages<T, CursorPage<T>>
with CursorStrategy<CursorPage<T>> {
CursorPages(SpotifyApiBase api, String path, ParserFunction<T> pageParser,
[String? pageKey, ParserFunction<Object>? pageContainerMapper])
: super(api, path, pageParser, pageKey, pageContainerMapper);
CursorPages(super.api, super.path, super.pageParser,
[super.pageKey, super.pageContainerMapper]);

CursorPages.fromCursorPaging(
SpotifyApiBase api, CursorPaging<T> paging, ParserFunction<T> pageParser,
Expand Down Expand Up @@ -306,7 +301,7 @@ class BundledPages extends _Pages with OffsetStrategy<List<Page<dynamic>>> {
_pageMappers.forEach((key, value) {
if (map[key] != null) {
var paging = Paging.fromJson(map[key]);
var page;
Page page;
if (_pageContainerParser == null) {
page = Page(paging, value);
} else {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/endpoints/episodes.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// Copyright (c) 2023, hayribakici. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

part of spotify;
part of '../../spotify.dart';

/// Endpoint of episodes `v1/episodes`
class Episodes extends EndpointBase {
@override
String get _path => 'v1/episodes';

Episodes(SpotifyApiBase api) : super(api);
Episodes(super.api);

Future<EpisodeFull> get(String id, [Market? market]) async {
assert(id.isNotEmpty, 'No episode id was provided');
var jsonString =
await _api._get('$_path/$id?' + _buildQuery({'market': market?.name}));
await _api._get('$_path/$id?${_buildQuery({'market': market?.name})}');
return EpisodeFull.fromJson(jsonDecode(jsonString));
}

Expand Down
Loading

0 comments on commit acef46d

Please sign in to comment.