diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 06d6b47a..aef36abc 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -8,11 +8,11 @@ jobs: runs-on: ubuntu-latest container: - image: google/dart:latest + image: dart:latest steps: - uses: actions/checkout@v1 - name: Install dependencies - run: pub get + run: dart pub get - name: Run tests - run: pub run test + run: dart test diff --git a/CHANGELOG.md b/CHANGELOG.md index c899c7f6..d8719973 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.9.1 +- bump dependency versions +- regenerate serialization models + ## 0.9.0 - add new-releases endpoint diff --git a/README.md b/README.md index 5c5f0cd3..f2ad969d 100644 --- a/README.md +++ b/README.md @@ -184,14 +184,14 @@ Please file feature requests and bugs at the [issue tracker][tracker]. ## Development ### Generating JSON Serializers -Run `pub run build_runner build` to generate JSON serializers via [json_serializable][]. -Run `pub run build_runner watch` to continuously rebuild serializers in the background when files are updated. +Run `dart run build_runner build` to generate JSON serializers via [json_serializable][]. +Run `dart run build_runner watch` to continuously rebuild serializers in the background when files are updated. ### Running tests -Run `pub run test` to run all of the tests in `test/spotify_test.dart`. +Run `dart test` to run all of the tests in `test/spotify_test.dart`. ### Running example code -Run `pub run example/example` to run the example code. You'll need to modify `example/example.dart` to use your Spotify client ID and secret. +Run `dart example/example` to run the example code. You'll need to modify `example/example.dart` to use your Spotify client ID and secret. If you would like to run the example that accesses your user data (such as currently playing song etc.), run `pub run example/example_auth.dart`. There, you are requested to enter your redirect url (see the comment above [`redirectUri`](#authorization-code-flow)). After that, you are requested to call a given url (or paste it into your browser). That url will do a redirect in your browser. You should copy and paste this redirected url into your console to see the currently playing song and your available devices. diff --git a/lib/src/models/_models.g.dart b/lib/src/models/_models.g.dart index fd45a2a4..dffd9093 100644 --- a/lib/src/models/_models.g.dart +++ b/lib/src/models/_models.g.dart @@ -6,89 +6,47 @@ part of spotify.models; // JsonSerializableGenerator // ************************************************************************** -ExternalUrls _$ExternalUrlsFromJson(Map json) { - return ExternalUrls()..spotify = json['spotify'] as String?; -} - -ExternalIds _$ExternalIdsFromJson(Map json) { - return ExternalIds() - ..isrc = json['isrc'] as String? - ..ean = json['ean'] as String? - ..upc = json['upc'] as String?; -} - -Album _$AlbumFromJson(Map json) { - return Album() - ..albumType = json['album_type'] as String? - ..artists = (json['artists'] as List?) - ?.map((e) => ArtistSimple.fromJson(e as Map)) - .toList() - ..availableMarkets = (json['available_markets'] as List?) - ?.map((e) => e as String) - .toList() - ..externalUrls = json['external_urls'] == null - ? null - : ExternalUrls.fromJson(json['external_urls'] as Map) - ..href = json['href'] as String? - ..id = json['id'] as String? - ..images = (json['images'] as List?) - ?.map((e) => Image.fromJson(e as Map)) - .toList() - ..name = json['name'] as String? - ..releaseDate = json['release_date'] as String? - ..releaseDatePrecision = _$enumDecodeNullable( - _$DatePrecisionEnumMap, json['release_date_precision']) - ..type = json['type'] as String? - ..uri = json['uri'] as String? - ..tracks = AlbumSimple._extractTracksFromPage(json['tracks']) - ..copyrights = (json['copyrights'] as List?) - ?.map((e) => Copyright.fromJson(e as Map)) - .toList() - ..externalIds = json['external_ids'] == null - ? null - : ExternalIds.fromJson(json['external_ids'] as Map) - ..genres = - (json['genres'] as List?)?.map((e) => e as String).toList() - ..label = json['label'] as String? - ..popularity = json['popularity'] as int?; -} - -K _$enumDecode( - Map enumValues, - Object? source, { - K? unknownValue, -}) { - if (source == null) { - throw ArgumentError( - 'A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}', - ); - } - - return enumValues.entries.singleWhere( - (e) => e.value == source, - orElse: () { - if (unknownValue == null) { - throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}', - ); - } - return MapEntry(unknownValue, enumValues.values.first); - }, - ).key; -} - -K? _$enumDecodeNullable( - Map enumValues, - dynamic source, { - K? unknownValue, -}) { - if (source == null) { - return null; - } - return _$enumDecode(enumValues, source, unknownValue: unknownValue); -} +ExternalUrls _$ExternalUrlsFromJson(Map json) => + ExternalUrls()..spotify = json['spotify'] as String?; + +ExternalIds _$ExternalIdsFromJson(Map json) => ExternalIds() + ..isrc = json['isrc'] as String? + ..ean = json['ean'] as String? + ..upc = json['upc'] as String?; + +Album _$AlbumFromJson(Map json) => Album() + ..albumType = json['album_type'] as String? + ..artists = (json['artists'] as List?) + ?.map((e) => ArtistSimple.fromJson(e as Map)) + .toList() + ..availableMarkets = (json['available_markets'] as List?) + ?.map((e) => e as String) + .toList() + ..externalUrls = json['external_urls'] == null + ? null + : ExternalUrls.fromJson(json['external_urls'] as Map) + ..href = json['href'] as String? + ..id = json['id'] as String? + ..images = (json['images'] as List?) + ?.map((e) => Image.fromJson(e as Map)) + .toList() + ..name = json['name'] as String? + ..releaseDate = json['release_date'] as String? + ..releaseDatePrecision = $enumDecodeNullable( + _$DatePrecisionEnumMap, json['release_date_precision']) + ..type = json['type'] as String? + ..uri = json['uri'] as String? + ..tracks = AlbumSimple._extractTracksFromPage(json['tracks']) + ..copyrights = (json['copyrights'] as List?) + ?.map((e) => Copyright.fromJson(e as Map)) + .toList() + ..externalIds = json['external_ids'] == null + ? null + : ExternalIds.fromJson(json['external_ids'] as Map) + ..genres = + (json['genres'] as List?)?.map((e) => e as String).toList() + ..label = json['label'] as String? + ..popularity = json['popularity'] as int?; const _$DatePrecisionEnumMap = { DatePrecision.day: 'day', @@ -96,113 +54,99 @@ const _$DatePrecisionEnumMap = { DatePrecision.year: 'year', }; -AlbumSimple _$AlbumSimpleFromJson(Map json) { - return AlbumSimple() - ..albumType = json['album_type'] as String? - ..artists = (json['artists'] as List?) - ?.map((e) => ArtistSimple.fromJson(e as Map)) - .toList() - ..availableMarkets = (json['available_markets'] as List?) - ?.map((e) => e as String) - .toList() - ..externalUrls = json['external_urls'] == null - ? null - : ExternalUrls.fromJson(json['external_urls'] as Map) - ..href = json['href'] as String? - ..id = json['id'] as String? - ..images = (json['images'] as List?) - ?.map((e) => Image.fromJson(e as Map)) - .toList() - ..name = json['name'] as String? - ..releaseDate = json['release_date'] as String? - ..releaseDatePrecision = _$enumDecodeNullable( - _$DatePrecisionEnumMap, json['release_date_precision']) - ..type = json['type'] as String? - ..uri = json['uri'] as String? - ..tracks = AlbumSimple._extractTracksFromPage(json['tracks']); -} - -Artist _$ArtistFromJson(Map json) { - return Artist() - ..externalUrls = json['external_urls'] == null - ? null - : ExternalUrls.fromJson(json['external_urls'] as Map) - ..href = json['href'] as String? - ..id = json['id'] as String? - ..name = json['name'] as String? - ..type = json['type'] as String? - ..uri = json['uri'] as String? - ..followers = json['followers'] == null - ? null - : Followers.fromJson(json['followers'] as Map) - ..genres = - (json['genres'] as List?)?.map((e) => e as String).toList() - ..images = (json['images'] as List?) - ?.map((e) => Image.fromJson(e as Map)) - .toList() - ..popularity = json['popularity'] as int?; -} - -ArtistSimple _$ArtistSimpleFromJson(Map json) { - return ArtistSimple() - ..externalUrls = json['external_urls'] == null - ? null - : ExternalUrls.fromJson(json['external_urls'] as Map) - ..href = json['href'] as String? - ..id = json['id'] as String? - ..name = json['name'] as String? - ..type = json['type'] as String? - ..uri = json['uri'] as String?; -} - -AudioFeature _$AudioFeatureFromJson(Map json) { - return AudioFeature() - ..acousticness = (json['acousticness'] as num?)?.toDouble() - ..analysisUrl = json['analysis_url'] as String? - ..danceability = (json['danceability'] as num?)?.toDouble() - ..durationMs = json['duration_ms'] as int? - ..energy = (json['energy'] as num?)?.toDouble() - ..id = json['id'] as String? - ..instrumentalness = (json['instrumentalness'] as num?)?.toDouble() - ..key = json['key'] as int? - ..liveness = (json['liveness'] as num?)?.toDouble() - ..loudness = (json['loudness'] as num?)?.toDouble() - ..mode = json['mode'] as int? - ..speechiness = (json['speechiness'] as num?)?.toDouble() - ..tempo = (json['tempo'] as num?)?.toDouble() - ..timeSignature = json['time_signature'] as int? - ..trackHref = json['track_href'] as String? - ..type = json['type'] as String? - ..uri = json['uri'] as String? - ..valence = (json['valence'] as num?)?.toDouble(); -} - -Category _$CategoryFromJson(Map json) { - return Category() - ..href = json['href'] as String? - ..icons = (json['icons'] as List?) - ?.map((e) => Image.fromJson(e as Map)) - .toList() - ..id = json['id'] as String? - ..name = json['name'] as String?; -} - -Copyright _$CopyrightFromJson(Map json) { - return Copyright() - ..text = json['text'] as String? - ..type = json['type'] as String?; -} - -Device _$DeviceFromJson(Map json) { - return Device() - ..id = json['id'] as String? - ..isActive = json['is_active'] as bool? ?? false - ..isPrivateSession = json['is_private_session'] as bool? ?? false - ..isRestricted = json['is_restricted'] as bool? ?? false - ..name = json['name'] as String? - ..type = _$enumDecodeNullable(_$DeviceTypeEnumMap, json['type']) - ..volumePercent = json['volume_percent'] as int?; -} +AlbumSimple _$AlbumSimpleFromJson(Map json) => AlbumSimple() + ..albumType = json['album_type'] as String? + ..artists = (json['artists'] as List?) + ?.map((e) => ArtistSimple.fromJson(e as Map)) + .toList() + ..availableMarkets = (json['available_markets'] as List?) + ?.map((e) => e as String) + .toList() + ..externalUrls = json['external_urls'] == null + ? null + : ExternalUrls.fromJson(json['external_urls'] as Map) + ..href = json['href'] as String? + ..id = json['id'] as String? + ..images = (json['images'] as List?) + ?.map((e) => Image.fromJson(e as Map)) + .toList() + ..name = json['name'] as String? + ..releaseDate = json['release_date'] as String? + ..releaseDatePrecision = $enumDecodeNullable( + _$DatePrecisionEnumMap, json['release_date_precision']) + ..type = json['type'] as String? + ..uri = json['uri'] as String? + ..tracks = AlbumSimple._extractTracksFromPage(json['tracks']); + +Artist _$ArtistFromJson(Map json) => Artist() + ..externalUrls = json['external_urls'] == null + ? null + : ExternalUrls.fromJson(json['external_urls'] as Map) + ..href = json['href'] as String? + ..id = json['id'] as String? + ..name = json['name'] as String? + ..type = json['type'] as String? + ..uri = json['uri'] as String? + ..followers = json['followers'] == null + ? null + : Followers.fromJson(json['followers'] as Map) + ..genres = + (json['genres'] as List?)?.map((e) => e as String).toList() + ..images = (json['images'] as List?) + ?.map((e) => Image.fromJson(e as Map)) + .toList() + ..popularity = json['popularity'] as int?; + +ArtistSimple _$ArtistSimpleFromJson(Map json) => ArtistSimple() + ..externalUrls = json['external_urls'] == null + ? null + : ExternalUrls.fromJson(json['external_urls'] as Map) + ..href = json['href'] as String? + ..id = json['id'] as String? + ..name = json['name'] as String? + ..type = json['type'] as String? + ..uri = json['uri'] as String?; + +AudioFeature _$AudioFeatureFromJson(Map json) => AudioFeature() + ..acousticness = (json['acousticness'] as num?)?.toDouble() + ..analysisUrl = json['analysis_url'] as String? + ..danceability = (json['danceability'] as num?)?.toDouble() + ..durationMs = json['duration_ms'] as int? + ..energy = (json['energy'] as num?)?.toDouble() + ..id = json['id'] as String? + ..instrumentalness = (json['instrumentalness'] as num?)?.toDouble() + ..key = json['key'] as int? + ..liveness = (json['liveness'] as num?)?.toDouble() + ..loudness = (json['loudness'] as num?)?.toDouble() + ..mode = json['mode'] as int? + ..speechiness = (json['speechiness'] as num?)?.toDouble() + ..tempo = (json['tempo'] as num?)?.toDouble() + ..timeSignature = json['time_signature'] as int? + ..trackHref = json['track_href'] as String? + ..type = json['type'] as String? + ..uri = json['uri'] as String? + ..valence = (json['valence'] as num?)?.toDouble(); + +Category _$CategoryFromJson(Map json) => Category() + ..href = json['href'] as String? + ..icons = (json['icons'] as List?) + ?.map((e) => Image.fromJson(e as Map)) + .toList() + ..id = json['id'] as String? + ..name = json['name'] as String?; + +Copyright _$CopyrightFromJson(Map json) => Copyright() + ..text = json['text'] as String? + ..type = json['type'] as String?; + +Device _$DeviceFromJson(Map json) => Device() + ..id = json['id'] as String? + ..isActive = json['is_active'] as bool? ?? false + ..isPrivateSession = json['is_private_session'] as bool? ?? false + ..isRestricted = json['is_restricted'] as bool? ?? false + ..name = json['name'] as String? + ..type = $enumDecodeNullable(_$DeviceTypeEnumMap, json['type']) + ..volumePercent = json['volume_percent'] as int?; const _$DeviceTypeEnumMap = { DeviceType.Computer: 'Computer', @@ -220,69 +164,57 @@ const _$DeviceTypeEnumMap = { DeviceType.Unknown: 'Unknown', }; -SpotifyError _$SpotifyErrorFromJson(Map json) { - return SpotifyError() - ..status = json['status'] as int? - ..message = json['message'] as String?; -} - -Followers _$FollowersFromJson(Map json) { - return Followers() - ..href = json['href'] as String? - ..total = json['total'] as int?; -} - -Image _$ImageFromJson(Map json) { - return Image() - ..height = json['height'] as int? - ..width = json['width'] as int? - ..url = json['url'] as String?; -} - -Paging _$PagingFromJson(Map json) { - return Paging() - ..href = json['href'] as String? - ..itemsNative = itemsNativeFromJson(json['items'] as List) - ..limit = json['limit'] as int - ..next = json['next'] as String? - ..offset = json['offset'] as int? - ..previous = json['previous'] as String? - ..total = json['total'] as int; -} - -CursorPaging _$CursorPagingFromJson(Map json) { - return CursorPaging() - ..href = json['href'] as String? - ..itemsNative = itemsNativeFromJson(json['items'] as List) - ..limit = json['limit'] as int - ..next = json['next'] as String? - ..cursors = json['cursors'] == null - ? null - : Cursor.fromJson(json['cursors'] as Map); -} - -Cursor _$CursorFromJson(Map json) { - return Cursor()..after = json['after'] as String?; -} - -Player _$PlayerFromJson(Map json) { - return Player() - ..timestamp = json['timestamp'] as int? - ..context = json['context'] == null - ? null - : PlayerContext.fromJson(json['context'] as Map) - ..progress_ms = json['progress_ms'] as int? - ..item = json['item'] == null - ? null - : Track.fromJson(json['item'] as Map) - ..currentlyPlayingType = _$enumDecodeNullable( - _$CurrentlyPlayingTypeEnumMap, json['currently_playing_type']) - ..isPlaying = json['is_playing'] as bool? ?? false - ..isShuffling = json['shuffle_state'] as bool? ?? false - ..repeatState = - _$enumDecodeNullable(_$RepeatStateEnumMap, json['repeat_state']) ?? - RepeatState.off; -} +SpotifyError _$SpotifyErrorFromJson(Map json) => SpotifyError() + ..status = json['status'] as int? + ..message = json['message'] as String?; + +Followers _$FollowersFromJson(Map json) => Followers() + ..href = json['href'] as String? + ..total = json['total'] as int?; + +Image _$ImageFromJson(Map json) => Image() + ..height = json['height'] as int? + ..width = json['width'] as int? + ..url = json['url'] as String?; + +Paging _$PagingFromJson(Map json) => Paging() + ..href = json['href'] as String? + ..itemsNative = itemsNativeFromJson(json['items'] as List) + ..limit = json['limit'] as int + ..next = json['next'] as String? + ..offset = json['offset'] as int? + ..previous = json['previous'] as String? + ..total = json['total'] as int; + +CursorPaging _$CursorPagingFromJson(Map json) => + CursorPaging() + ..href = json['href'] as String? + ..itemsNative = itemsNativeFromJson(json['items'] as List) + ..limit = json['limit'] as int + ..next = json['next'] as String? + ..cursors = json['cursors'] == null + ? null + : Cursor.fromJson(json['cursors'] as Map); + +Cursor _$CursorFromJson(Map json) => + Cursor()..after = json['after'] as String?; + +Player _$PlayerFromJson(Map json) => Player() + ..timestamp = json['timestamp'] as int? + ..context = json['context'] == null + ? null + : PlayerContext.fromJson(json['context'] as Map) + ..progress_ms = json['progress_ms'] as int? + ..item = json['item'] == null + ? null + : Track.fromJson(json['item'] as Map) + ..currentlyPlayingType = $enumDecodeNullable( + _$CurrentlyPlayingTypeEnumMap, json['currently_playing_type']) + ..isPlaying = json['is_playing'] as bool? ?? false + ..isShuffling = json['shuffle_state'] as bool? ?? false + ..repeatState = + $enumDecodeNullable(_$RepeatStateEnumMap, json['repeat_state']) ?? + RepeatState.off; const _$CurrentlyPlayingTypeEnumMap = { CurrentlyPlayingType.track: 'track', @@ -297,304 +229,274 @@ const _$RepeatStateEnumMap = { RepeatState.track: 'track', }; -PlayerContext _$PlayerContextFromJson(Map json) { - return PlayerContext() - ..external_urls = json['external_urls'] == null - ? null - : ExternalUrls.fromJson(json['external_urls'] as Map) - ..href = json['href'] as String? - ..type = json['type'] as String? - ..uri = json['uri'] as String?; -} - -Playlist _$PlaylistFromJson(Map json) { - return Playlist() - ..collaborative = json['collaborative'] as bool? - ..description = json['description'] as String? - ..externalUrls = json['external_urls'] == null - ? null - : ExternalUrls.fromJson(json['external_urls'] as Map) - ..followers = json['followers'] == null - ? null - : Followers.fromJson(json['followers'] as Map) - ..href = json['href'] as String? - ..id = json['id'] as String? - ..images = (json['images'] as List?) - ?.map((e) => Image.fromJson(e as Map)) - .toList() - ..name = json['name'] as String? - ..owner = json['owner'] == null - ? null - : User.fromJson(json['owner'] as Map) - ..public = json['public'] as bool? - ..snapshotId = json['snapshot_id'] as String? - ..tracks = json['tracks'] == null - ? null - : Paging.fromJson(json['tracks'] as Map) - ..type = json['type'] as String? - ..uri = json['uri'] as String?; -} - -PlaylistSimple _$PlaylistSimpleFromJson(Map json) { - return PlaylistSimple() - ..collaborative = json['collaborative'] as bool? - ..description = json['description'] as String? - ..externalUrls = json['external_urls'] == null - ? null - : ExternalUrls.fromJson(json['external_urls'] as Map) - ..href = json['href'] as String? - ..id = json['id'] as String? - ..images = (json['images'] as List?) - ?.map((e) => Image.fromJson(e as Map)) - .toList() - ..name = json['name'] as String? - ..owner = json['owner'] == null - ? null - : User.fromJson(json['owner'] as Map) - ..public = json['public'] as bool? - ..snapshotId = json['snapshot_id'] as String? - ..tracksLink = json['tracks'] == null - ? null - : TracksLink.fromJson(json['tracks'] as Map) - ..type = json['type'] as String? - ..uri = json['uri'] as String?; -} - -PlaylistsFeatured _$PlaylistsFeaturedFromJson(Map json) { - return PlaylistsFeatured()..message = json['message'] as String?; -} - -PlaylistTrack _$PlaylistTrackFromJson(Map json) { - return PlaylistTrack() - ..addedAt = json['added_at'] == null - ? null - : DateTime.parse(json['added_at'] as String) - ..addedBy = json['added_by'] == null - ? null - : UserPublic.fromJson(json['added_by'] as Map) - ..isLocal = json['is_local'] as bool? - ..track = json['track'] == null - ? null - : Track.fromJson(json['track'] as Map); -} - -Recommendations _$RecommendationsFromJson(Map json) { - return Recommendations() - ..seeds = (json['seeds'] as List?) - ?.map((e) => RecommendationsSeed.fromJson(e as Map)) - .toList() - ..tracks = (json['tracks'] as List?) - ?.map((e) => TrackSimple.fromJson(e as Map)) - .toList(); -} - -RecommendationsSeed _$RecommendationsSeedFromJson(Map json) { - return RecommendationsSeed() - ..afterFilteringSize = json['afterFilteringSize'] as int? - ..afterRelinkingSize = json['afterRelinkingSize'] as int? - ..href = json['href'] as String? - ..id = json['id'] as String? - ..initialPoolSize = json['initialPoolSize'] as int? - ..type = json['type'] as String?; -} - -Show _$ShowFromJson(Map json) { - return Show() - ..availableMarkets = (json['available_markets'] as List?) - ?.map((e) => e as String) - .toList() - ..copyrights = (json['copyrights'] as List?) - ?.map((e) => Copyright.fromJson(e as Map)) - .toList() - ..description = json['description'] as String? - ..explicit = json['explicit'] as bool? - ..externalUrls = json['external_urls'] == null - ? null - : ExternalUrls.fromJson(json['external_urls'] as Map) - ..href = json['href'] as String? - ..id = json['id'] as String? - ..images = (json['images'] as List?) - ?.map((e) => Image.fromJson(e as Map)) - .toList() - ..isExternallyHosted = json['is_externally_hosted'] as bool? - ..languages = - (json['languages'] as List?)?.map((e) => e as String).toList() - ..mediaType = json['media_type'] as String? - ..name = json['name'] as String? - ..publisher = json['publisher'] as String? - ..type = json['type'] as String? - ..uri = json['uri'] as String?; -} - -Episode _$EpisodeFromJson(Map json) { - return Episode() - ..audioPreviewUrl = json['audio_preview_url'] as String? - ..description = json['description'] as String? - ..durationMs = json['duration_ms'] as int? - ..explicit = json['explicit'] as bool? - ..externalUrls = json['external_urls'] == null - ? null - : ExternalUrls.fromJson(json['external_urls'] as Map) - ..href = json['href'] as String? - ..id = json['id'] as String? - ..images = (json['images'] as List?) - ?.map((e) => Image.fromJson(e as Map)) - .toList() - ..isExternallyHosted = json['is_externally_hosted'] as bool? - ..isPlayable = json['is_playable'] as bool? - ..language = json['language'] as String? - ..languages = - (json['languages'] as List?)?.map((e) => e as String).toList() - ..name = json['name'] as String? - ..releaseDate = json['release_date'] == null - ? null - : DateTime.parse(json['release_date'] as String) - ..releaseDatePrecision = json['release_date_precision'] as String? - ..type = json['type'] as String? - ..uri = json['uri'] as String?; -} - -Track _$TrackFromJson(Map json) { - return Track() - ..album = json['album'] == null - ? null - : AlbumSimple.fromJson(json['album'] as Map) - ..artists = (json['artists'] as List?) - ?.map((e) => Artist.fromJson(e as Map)) - .toList() - ..availableMarkets = (json['available_markets'] as List?) - ?.map((e) => e as String) - .toList() - ..discNumber = json['disc_number'] as int? - ..durationMs = json['duration_ms'] as int? - ..explicit = json['explicit'] as bool? - ..externalIds = json['external_ids'] == null - ? null - : ExternalIds.fromJson(json['external_ids'] as Map) - ..externalUrls = json['external_urls'] == null - ? null - : ExternalUrls.fromJson(json['external_urls'] as Map) - ..href = json['href'] as String? - ..id = json['id'] as String? - ..isPlayable = json['is_playable'] as bool? - ..linkedFrom = json['linked_from'] == null - ? null - : TrackLink.fromJson(json['linked_from'] as Map) - ..name = json['name'] as String? - ..popularity = json['popularity'] as int? - ..previewUrl = json['preview_url'] as String? - ..trackNumber = json['track_number'] as int? - ..type = json['type'] as String? - ..uri = json['uri'] as String?; -} - -TrackSimple _$TrackSimpleFromJson(Map json) { - return TrackSimple() - ..artists = (json['artists'] as List?) - ?.map((e) => Artist.fromJson(e as Map)) - .toList() - ..availableMarkets = (json['available_markets'] as List?) - ?.map((e) => e as String) - .toList() - ..discNumber = json['disc_number'] as int? - ..durationMs = json['duration_ms'] as int? - ..explicit = json['explicit'] as bool? - ..externalUrls = json['external_urls'] == null - ? null - : ExternalUrls.fromJson(json['external_urls'] as Map) - ..href = json['href'] as String? - ..id = json['id'] as String? - ..isPlayable = json['is_playable'] as bool? - ..linkedFrom = json['linked_from'] == null - ? null - : TrackLink.fromJson(json['linked_from'] as Map) - ..name = json['name'] as String? - ..previewUrl = json['preview_url'] as String? - ..trackNumber = json['track_number'] as int? - ..type = json['type'] as String? - ..uri = json['uri'] as String?; -} - -TrackSaved _$TrackSavedFromJson(Map json) { - return TrackSaved() - ..addedAt = json['added_at'] == null - ? null - : DateTime.parse(json['added_at'] as String) - ..track = json['track'] == null - ? null - : Track.fromJson(json['track'] as Map); -} - -TrackLink _$TrackLinkFromJson(Map json) { - return TrackLink() - ..externalUrls = (json['external_urls'] as Map?)?.map( - (k, e) => MapEntry(k, e as String), - ) - ..href = json['href'] as String? - ..id = json['id'] as String? - ..type = json['type'] as String? - ..uri = json['uri'] as String?; -} - -TracksLink _$TracksLinkFromJson(Map json) { - return TracksLink() - ..href = json['href'] as String? - ..total = json['total'] as int?; -} - -User _$UserFromJson(Map json) { - return User() - ..birthdate = json['birthdate'] as String? - ..country = json['country'] as String? - ..displayName = json['display_name'] as String? - ..email = json['email'] as String? - ..followers = json['followers'] == null - ? null - : Followers.fromJson(json['followers'] as Map) - ..href = json['href'] as String? - ..id = json['id'] as String? - ..images = (json['images'] as List?) - ?.map((e) => Image.fromJson(e as Map)) - .toList() - ..product = json['product'] as String? - ..type = json['type'] as String? - ..uri = json['uri'] as String?; -} - -UserPublic _$UserPublicFromJson(Map json) { - return UserPublic() - ..displayName = json['display_name'] as String? - ..followers = json['followers'] == null - ? null - : Followers.fromJson(json['followers'] as Map) - ..href = json['href'] as String? - ..id = json['id'] as String? - ..images = (json['images'] as List?) - ?.map((e) => Image.fromJson(e as Map)) - .toList() - ..type = json['type'] as String? - ..uri = json['uri'] as String?; -} - -PlayHistory _$PlayHistoryFromJson(Map json) { - return PlayHistory() - ..track = json['track'] == null - ? null - : TrackSimple.fromJson(json['track'] as Map) - ..playedAt = json['played_at'] == null - ? null - : DateTime.parse(json['played_at'] as String) - ..context = json['context'] == null - ? null - : PlayerContext.fromJson(json['context'] as Map); -} - -Queue _$QueueFromJson(Map json) { - return Queue() - ..currentlyPlaying = json['currently_playing'] == null - ? null - : Track.fromJson(json['currently_playing'] as Map) - ..queue = (json['queue'] as List?) - ?.map((e) => Track.fromJson(e as Map)) - .toList(); -} +PlayerContext _$PlayerContextFromJson(Map json) => + PlayerContext() + ..external_urls = json['external_urls'] == null + ? null + : ExternalUrls.fromJson(json['external_urls'] as Map) + ..href = json['href'] as String? + ..type = json['type'] as String? + ..uri = json['uri'] as String?; + +Playlist _$PlaylistFromJson(Map json) => Playlist() + ..collaborative = json['collaborative'] as bool? + ..description = json['description'] as String? + ..externalUrls = json['external_urls'] == null + ? null + : ExternalUrls.fromJson(json['external_urls'] as Map) + ..followers = json['followers'] == null + ? null + : Followers.fromJson(json['followers'] as Map) + ..href = json['href'] as String? + ..id = json['id'] as String? + ..images = (json['images'] as List?) + ?.map((e) => Image.fromJson(e as Map)) + .toList() + ..name = json['name'] as String? + ..owner = json['owner'] == null + ? null + : User.fromJson(json['owner'] as Map) + ..public = json['public'] as bool? + ..snapshotId = json['snapshot_id'] as String? + ..tracks = json['tracks'] == null + ? null + : Paging.fromJson(json['tracks'] as Map) + ..type = json['type'] as String? + ..uri = json['uri'] as String?; + +PlaylistSimple _$PlaylistSimpleFromJson(Map json) => + PlaylistSimple() + ..collaborative = json['collaborative'] as bool? + ..description = json['description'] as String? + ..externalUrls = json['external_urls'] == null + ? null + : ExternalUrls.fromJson(json['external_urls'] as Map) + ..href = json['href'] as String? + ..id = json['id'] as String? + ..images = (json['images'] as List?) + ?.map((e) => Image.fromJson(e as Map)) + .toList() + ..name = json['name'] as String? + ..owner = json['owner'] == null + ? null + : User.fromJson(json['owner'] as Map) + ..public = json['public'] as bool? + ..snapshotId = json['snapshot_id'] as String? + ..tracksLink = json['tracks'] == null + ? null + : TracksLink.fromJson(json['tracks'] as Map) + ..type = json['type'] as String? + ..uri = json['uri'] as String?; + +PlaylistsFeatured _$PlaylistsFeaturedFromJson(Map json) => + PlaylistsFeatured()..message = json['message'] as String?; + +PlaylistTrack _$PlaylistTrackFromJson(Map json) => + PlaylistTrack() + ..addedAt = json['added_at'] == null + ? null + : DateTime.parse(json['added_at'] as String) + ..addedBy = json['added_by'] == null + ? null + : UserPublic.fromJson(json['added_by'] as Map) + ..isLocal = json['is_local'] as bool? + ..track = json['track'] == null + ? null + : Track.fromJson(json['track'] as Map); + +Recommendations _$RecommendationsFromJson(Map json) => + Recommendations() + ..seeds = (json['seeds'] as List?) + ?.map((e) => RecommendationsSeed.fromJson(e as Map)) + .toList() + ..tracks = (json['tracks'] as List?) + ?.map((e) => TrackSimple.fromJson(e as Map)) + .toList(); + +RecommendationsSeed _$RecommendationsSeedFromJson(Map json) => + RecommendationsSeed() + ..afterFilteringSize = json['afterFilteringSize'] as int? + ..afterRelinkingSize = json['afterRelinkingSize'] as int? + ..href = json['href'] as String? + ..id = json['id'] as String? + ..initialPoolSize = json['initialPoolSize'] as int? + ..type = json['type'] as String?; + +Show _$ShowFromJson(Map json) => Show() + ..availableMarkets = (json['available_markets'] as List?) + ?.map((e) => e as String) + .toList() + ..copyrights = (json['copyrights'] as List?) + ?.map((e) => Copyright.fromJson(e as Map)) + .toList() + ..description = json['description'] as String? + ..explicit = json['explicit'] as bool? + ..externalUrls = json['external_urls'] == null + ? null + : ExternalUrls.fromJson(json['external_urls'] as Map) + ..href = json['href'] as String? + ..id = json['id'] as String? + ..images = (json['images'] as List?) + ?.map((e) => Image.fromJson(e as Map)) + .toList() + ..isExternallyHosted = json['is_externally_hosted'] as bool? + ..languages = + (json['languages'] as List?)?.map((e) => e as String).toList() + ..mediaType = json['media_type'] as String? + ..name = json['name'] as String? + ..publisher = json['publisher'] as String? + ..type = json['type'] as String? + ..uri = json['uri'] as String?; + +Episode _$EpisodeFromJson(Map json) => Episode() + ..audioPreviewUrl = json['audio_preview_url'] as String? + ..description = json['description'] as String? + ..durationMs = json['duration_ms'] as int? + ..explicit = json['explicit'] as bool? + ..externalUrls = json['external_urls'] == null + ? null + : ExternalUrls.fromJson(json['external_urls'] as Map) + ..href = json['href'] as String? + ..id = json['id'] as String? + ..images = (json['images'] as List?) + ?.map((e) => Image.fromJson(e as Map)) + .toList() + ..isExternallyHosted = json['is_externally_hosted'] as bool? + ..isPlayable = json['is_playable'] as bool? + ..language = json['language'] as String? + ..languages = + (json['languages'] as List?)?.map((e) => e as String).toList() + ..name = json['name'] as String? + ..releaseDate = json['release_date'] == null + ? null + : DateTime.parse(json['release_date'] as String) + ..releaseDatePrecision = json['release_date_precision'] as String? + ..type = json['type'] as String? + ..uri = json['uri'] as String?; + +Track _$TrackFromJson(Map json) => Track() + ..album = json['album'] == null + ? null + : AlbumSimple.fromJson(json['album'] as Map) + ..artists = (json['artists'] as List?) + ?.map((e) => Artist.fromJson(e as Map)) + .toList() + ..availableMarkets = (json['available_markets'] as List?) + ?.map((e) => e as String) + .toList() + ..discNumber = json['disc_number'] as int? + ..durationMs = json['duration_ms'] as int? + ..explicit = json['explicit'] as bool? + ..externalIds = json['external_ids'] == null + ? null + : ExternalIds.fromJson(json['external_ids'] as Map) + ..externalUrls = json['external_urls'] == null + ? null + : ExternalUrls.fromJson(json['external_urls'] as Map) + ..href = json['href'] as String? + ..id = json['id'] as String? + ..isPlayable = json['is_playable'] as bool? + ..linkedFrom = json['linked_from'] == null + ? null + : TrackLink.fromJson(json['linked_from'] as Map) + ..name = json['name'] as String? + ..popularity = json['popularity'] as int? + ..previewUrl = json['preview_url'] as String? + ..trackNumber = json['track_number'] as int? + ..type = json['type'] as String? + ..uri = json['uri'] as String?; + +TrackSimple _$TrackSimpleFromJson(Map json) => TrackSimple() + ..artists = (json['artists'] as List?) + ?.map((e) => Artist.fromJson(e as Map)) + .toList() + ..availableMarkets = (json['available_markets'] as List?) + ?.map((e) => e as String) + .toList() + ..discNumber = json['disc_number'] as int? + ..durationMs = json['duration_ms'] as int? + ..explicit = json['explicit'] as bool? + ..externalUrls = json['external_urls'] == null + ? null + : ExternalUrls.fromJson(json['external_urls'] as Map) + ..href = json['href'] as String? + ..id = json['id'] as String? + ..isPlayable = json['is_playable'] as bool? + ..linkedFrom = json['linked_from'] == null + ? null + : TrackLink.fromJson(json['linked_from'] as Map) + ..name = json['name'] as String? + ..previewUrl = json['preview_url'] as String? + ..trackNumber = json['track_number'] as int? + ..type = json['type'] as String? + ..uri = json['uri'] as String?; + +TrackSaved _$TrackSavedFromJson(Map json) => TrackSaved() + ..addedAt = json['added_at'] == null + ? null + : DateTime.parse(json['added_at'] as String) + ..track = json['track'] == null + ? null + : Track.fromJson(json['track'] as Map); + +TrackLink _$TrackLinkFromJson(Map json) => TrackLink() + ..externalUrls = (json['external_urls'] as Map?)?.map( + (k, e) => MapEntry(k, e as String), + ) + ..href = json['href'] as String? + ..id = json['id'] as String? + ..type = json['type'] as String? + ..uri = json['uri'] as String?; + +TracksLink _$TracksLinkFromJson(Map json) => TracksLink() + ..href = json['href'] as String? + ..total = json['total'] as int?; + +User _$UserFromJson(Map json) => User() + ..birthdate = json['birthdate'] as String? + ..country = json['country'] as String? + ..displayName = json['display_name'] as String? + ..email = json['email'] as String? + ..followers = json['followers'] == null + ? null + : Followers.fromJson(json['followers'] as Map) + ..href = json['href'] as String? + ..id = json['id'] as String? + ..images = (json['images'] as List?) + ?.map((e) => Image.fromJson(e as Map)) + .toList() + ..product = json['product'] as String? + ..type = json['type'] as String? + ..uri = json['uri'] as String?; + +UserPublic _$UserPublicFromJson(Map json) => UserPublic() + ..displayName = json['display_name'] as String? + ..followers = json['followers'] == null + ? null + : Followers.fromJson(json['followers'] as Map) + ..href = json['href'] as String? + ..id = json['id'] as String? + ..images = (json['images'] as List?) + ?.map((e) => Image.fromJson(e as Map)) + .toList() + ..type = json['type'] as String? + ..uri = json['uri'] as String?; + +PlayHistory _$PlayHistoryFromJson(Map json) => PlayHistory() + ..track = json['track'] == null + ? null + : TrackSimple.fromJson(json['track'] as Map) + ..playedAt = json['played_at'] == null + ? null + : DateTime.parse(json['played_at'] as String) + ..context = json['context'] == null + ? null + : PlayerContext.fromJson(json['context'] as Map); + +Queue _$QueueFromJson(Map json) => Queue() + ..currentlyPlaying = json['currently_playing'] == null + ? null + : Track.fromJson(json['currently_playing'] as Map) + ..queue = (json['queue'] as List?) + ?.map((e) => Track.fromJson(e as Map)) + .toList(); diff --git a/lib/src/models/audio_feature.dart b/lib/src/models/audio_feature.dart index d0e1ea79..0d67dff9 100644 --- a/lib/src/models/audio_feature.dart +++ b/lib/src/models/audio_feature.dart @@ -30,7 +30,7 @@ class AudioFeature extends Object { int? durationMs; /// The track length - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) Duration? get duration => Duration(milliseconds: durationMs ?? 0); /// Energy is a measure from 0.0 to 1.0 and represents a perceptual measure of diff --git a/lib/src/models/playlist.dart b/lib/src/models/playlist.dart index 63f374be..fea7dec9 100644 --- a/lib/src/models/playlist.dart +++ b/lib/src/models/playlist.dart @@ -66,7 +66,7 @@ class Playlist extends Object implements PlaylistSimple { /// Use [Playlist.tracks] @override - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) TracksLink? tracksLink; /// Information about the tracks of the playlist. diff --git a/lib/src/models/track.dart b/lib/src/models/track.dart index c357dca4..e0a40230 100644 --- a/lib/src/models/track.dart +++ b/lib/src/models/track.dart @@ -36,7 +36,7 @@ class Track extends Object implements TrackSimple { int? durationMs; /// The track length - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) @override Duration? get duration => Duration(milliseconds: durationMs ?? 0); @@ -143,7 +143,7 @@ class TrackSimple extends Object { int? durationMs; /// The track length - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) Duration? get duration => Duration(milliseconds: durationMs ?? 0); /// Whether or not the track has explicit lyrics diff --git a/pubspec.yaml b/pubspec.yaml index 5ffe13d0..e893f7b1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,18 +1,18 @@ name: spotify description: An incomplete dart library for interfacing with the Spotify Web API. -version: 0.9.0 +version: 0.9.1 homepage: https://github.com/rinukkusu/spotify-dart environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.18.0 <3.0.0' dependencies: http: ^0.13.3 - json_annotation: ^4.0.0 + json_annotation: ^4.8.0 oauth2: ^2.0.0 pedantic: ^1.11.0 dev_dependencies: test: ^1.16.5 build_runner: ^2.0.3 - json_serializable: ^4.1.1 + json_serializable: ">=4.1.1 <7.0.0"