Skip to content

Commit e61af4d

Browse files
committed
Updated README
1 parent 4e3a291 commit e61af4d

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

README.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ import 'soundcloud_explode_dart/soundcloud_explode_dart.dart';
1818
1919
final client = SoundcloudClient();
2020
21-
// Most functions return a stream of results in the
22-
// form of Stream<Iterable<E>>.
21+
// Most functions return a stream of results in the form of Stream<Iterable<E>>.
2322
// The number of results returned in each Iterable<E>, as well as
24-
// the search result offset and search filter are optional parameters.
23+
// the result offset and search filter are optional parameters.
2524
final stream = client.search(
2625
'Haddaway - What Is Love',
2726
searchFilter: SearchFilter.tracks,
@@ -32,11 +31,23 @@ final streamIterator = StreamIterator(stream);
3231
3332
while (await streamIterator.moveNext()) {
3433
for (final result in streamIterator.current) {
35-
print(result.title);
34+
// Use pattern matching for mixed streams
35+
switch (result) {
36+
case final UserSearchResult user:
37+
break;
38+
39+
case final TrackSearchResult track:
40+
break;
41+
42+
case final PlaylistSearchResult playlist:
43+
break;
44+
}
3645
}
3746
}
3847
```
3948

49+
Alternatively, use one of the specialised functions, such as `getUsers(...)`, `getTracks(...)`, etc., which casts each item in the returned `Iterable<E>` to the specified type.
50+
4051
### Querying users
4152

4253
Retrieve metadata about specific users:
@@ -53,9 +64,9 @@ final user1 = await client.users.getByUrl('https://www.soundcloud.com/a-user');
5364
final user2 = await client.users.get(123456789);
5465
5566
// Get the tracks/playlists/albums a specific user has uploaded...
56-
final tracks = client.users.getTracks(user1.id);
57-
final playlists = client.users.getPlaylists(user1.id);
58-
final albums = client.users.getAlbums(user1.id);
67+
final trackStream = client.users.getTracks(user1.id);
68+
final playlistStream = client.users.getPlaylists(user1.id);
69+
final albumStream = client.users.getAlbums(user1.id);
5970
```
6071

6172
### Querying tracks and streams
@@ -96,7 +107,6 @@ await audioPlayer.play(stream.url);
96107
> To determine whether or not a track is fully playable:
97108
>
98109
> ```dart
99-
> final track = await client.tracks.get(123456789);
100110
> if (track.duration == track.fullDuration) {
101111
> // Track can be played until completion.
102112
> ...
@@ -105,22 +115,23 @@ await audioPlayer.play(stream.url);
105115
106116
### Querying playlists/albums
107117
108-
To retrieve metadata about specific playlists:
118+
To retrieve metadata about a specific playlist:
109119
110120
```dart
111121
import 'soundcloud_explode_dart/soundcloud_explode_dart.dart';
112122
113123
final client = SoundcloudClient();
114124
115-
// Playlists/albums can be retrieved via URL...
116-
final playlist11 = await client.playlists.getByUrl('https://www.soundcloud.com/a-user/sets/a-playlist-or-album');
125+
// Playlists can be retrieved via URL...
126+
final playlist1 = await client.playlists.getByUrl('https://www.soundcloud.com/a-user/sets/a-playlist');
117127
118128
// ...or via their playlist ID.
119129
final playlist2 = await client.playlists.get(123456789);
120130
121-
// Indicates if the playlist is identified as an album or not.
131+
// Playlists and albums are effectively synonymous on SoundCloud,
132+
// with only a boolean property differentiating the two.
122133
final isAlbum = playlist1.isAlbum;
123134
124-
// Get the tracks contained with a playlist/album...
135+
// Get the tracks contained within a playlist...
125136
final tracks = client.playlists.getTracks(playlist1.id);
126137
```

lib/src/users/user_client.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ class UserClient {
4949
if (offset < 0) {
5050
throw ArgumentError.value(
5151
offset,
52-
null,
52+
'offset',
5353
'Offset cannot be less than zero.',
5454
);
5555
}
5656

5757
if (limit < 0) {
5858
throw ArgumentError.value(
5959
limit,
60-
null,
60+
'limit',
6161
'Limit cannot be less than zero.',
6262
);
6363
}
@@ -146,15 +146,15 @@ class UserClient {
146146
if (offset < 0) {
147147
throw ArgumentError.value(
148148
offset,
149-
null,
149+
'offset',
150150
'Offset cannot be less than zero.',
151151
);
152152
}
153153

154154
if (limit < 0) {
155155
throw ArgumentError.value(
156156
limit,
157-
null,
157+
'limit',
158158
'Limit cannot be less than zero.',
159159
);
160160
}

0 commit comments

Comments
 (0)