Skip to content

Commit

Permalink
Merge pull request #208 from KRTirtho/fix-spotify-precision
Browse files Browse the repository at this point in the history
fix: spotify sending double instead of int for documented endpoints
  • Loading branch information
rinukkusu authored Mar 1, 2024
2 parents 6bff51c + 7215f9f commit c42c8ab
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 56 deletions.
73 changes: 39 additions & 34 deletions lib/src/models/_models.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions lib/src/models/audio_analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ abstract class _Section {
/// The estimated overall key of the section. The values in this field
/// ranging from `0 to `11` mapping to pitches using standard Pitch Class notation
/// (E.g. `0 = C`, `1 = C♯/D♭`, `2 = D`, and so on). If no key was detected, the value is `-1`.
@JsonKey(fromJson: convertToIntIfDoubleValue)
int? key;

/// The confidence, from 0.0 to 1.0, of the reliability of the key.
Expand All @@ -62,6 +63,7 @@ abstract class _Section {
/// Note that the major key (e.g. C major) could more likely be confused
/// with the minor key at `3` semitones lower (e.g. A minor) as both
/// keys carry the same pitches.
@JsonKey(fromJson: convertToIntIfDoubleValue)
int? mode;

/// The confidence, from `0.0` to `1.0`, of the reliability of the mode.
Expand All @@ -73,7 +75,7 @@ abstract class _Section {
/// how many beats are in each bar (or measure).
/// The time signature ranges from `3` to `7` indicating time signatures
/// of “3/4”, to “7/4”.
@JsonKey(name: 'time_signature')
@JsonKey(name: 'time_signature', fromJson: convertToIntIfDoubleValue)
int? timeSignature;

/// The confidence, from `0.0` to `1.0`, of the reliability of the
Expand All @@ -93,16 +95,16 @@ class TrackAudioAnalysis extends _Section {

/// The exact number of audio samples analyzed from this track.
/// See also [analysisSampleRate].
@JsonKey(name: 'num_samples')
@JsonKey(name: 'num_samples', fromJson: convertToIntIfDoubleValue)
int? numSamples;

/// The sample rate used to decode and analyze this track.
///
/// May differ from the actual sample rate of this track available on Spotify.
@JsonKey(name: 'analysis_sample_rate')
@JsonKey(name: 'analysis_sample_rate', fromJson: convertToIntIfDoubleValue)
int? analysisSampleRate;

@JsonKey(name: 'analysis_channels')
@JsonKey(name: 'analysis_channels', fromJson: convertToIntIfDoubleValue)
int? analysisChannels;

/// The time, in seconds, at which the track's fade-in period ends.
Expand Down
6 changes: 4 additions & 2 deletions lib/src/models/audio_feature.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AudioFeature extends Object {
double? danceability;

/// The track length in milliseconds.
@JsonKey(name: 'duration_ms')
@JsonKey(name: 'duration_ms', fromJson: convertToIntIfDoubleValue)
int? durationMs;

/// The track length
Expand Down Expand Up @@ -55,6 +55,7 @@ class AudioFeature extends Object {

/// The key the track is in. Integers map to pitches using standard Pitch
/// Class notation. E.g. `0 = C`, `1 = C♯/D♭`, `2 = D`, and so on.
@JsonKey(fromJson: convertToIntIfDoubleValue)
int? key;

/// Detects the presence of an audience in the recording. Higher liveness
Expand All @@ -72,6 +73,7 @@ class AudioFeature extends Object {
/// Mode indicates the modality (major or minor) of a track, the type of scale
/// from which its melodic content is derived. Major is represented by 1 and
/// minor is `0`.
@JsonKey(fromJson: convertToIntIfDoubleValue)
int? mode;

/// Speechiness detects the presence of spoken words in a track. The more
Expand All @@ -91,7 +93,7 @@ class AudioFeature extends Object {
/// An estimated overall time signature of a track. The time signature (meter)
/// is a notational convention to specify how many beats are in each bar (or
/// measure).
@JsonKey(name: 'time_signature')
@JsonKey(name: 'time_signature', fromJson: convertToIntIfDoubleValue)
int? timeSignature;

/// A link to the Web API endpoint providing full details of the track.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Device extends Object {
DeviceType? type;

/// The current volume in percent. This may be `null`.
@JsonKey(name: 'volume_percent')
@JsonKey(name: 'volume_percent', fromJson: convertToIntIfDoubleValue)
int? volumePercent;
}

Expand Down
3 changes: 1 addition & 2 deletions lib/src/models/episode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Episode extends Object {
String? description;

/// The episode length in milliseconds.
@JsonKey(name: 'duration_ms')
@JsonKey(name: 'duration_ms', fromJson: convertToIntIfDoubleValue)
int? durationMs;

/// Whether or not the episode has explicit content
Expand Down Expand Up @@ -80,7 +80,6 @@ class Episode extends Object {
/// Json representation of an episode with information about its show
@JsonSerializable(createToJson: false)
class EpisodeFull extends Episode {

EpisodeFull();

Show? show;
Expand Down
1 change: 1 addition & 0 deletions lib/src/models/error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class SpotifyError extends Object {

/// The HTTP status code (also returned in the response header; see Response
/// Status Codes for more information).
@JsonKey(fromJson: convertToIntIfDoubleValue)
int? status;

/// A short description of the cause of the error.
Expand Down
8 changes: 7 additions & 1 deletion lib/src/models/paging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ class BasePaging<T> extends Object {
/// Note this is the raw JSON value. Use a [Page]'s [Page.items] to get the
/// requested data as a deserialized list.
@JsonKey(
name: 'items', fromJson: itemsNativeFromJson, toJson: itemsNativeToJson)
name: 'items',
fromJson: itemsNativeFromJson,
toJson: itemsNativeToJson,
)
Iterable<dynamic>? itemsNative;

/// The maximum number of items in the response (as set in the query or by
/// default).
@JsonKey(fromJson: convertToIntIfDoubleValueWithoutNull)
int limit = 20;

/// URL to the next page of items. (`null` if none)
Expand All @@ -44,12 +48,14 @@ class Paging<T> extends BasePaging<T> {
factory Paging.fromJson(Map<String, dynamic> json) => _$PagingFromJson(json);

/// The offset of the items returned (as set in the query or by default).
@JsonKey(fromJson: convertToIntIfDoubleValue)
int? offset;

/// URL to the previous page of items. (null if none)
String? previous;

/// The total number of items available to return.
@JsonKey(fromJson: convertToIntIfDoubleValueWithoutNull)
int total = 0;
}

Expand Down
Loading

0 comments on commit c42c8ab

Please sign in to comment.