spotify-dart
spotify-dart copied to clipboard
Code conventions
While browsing through the endpoint
files, I stumbled upon methods with no parameters (e.g. playlist.me
) that are written with get
properties and actual methods with no parameters (e.g. me.savedShows()
). It would be nice to iron out the inconsistancy with a set code convention rules (contributing.md
) or at least a guide (e.g. an issue or wiki-page) for new developers who want to add more features.
Sounds like a great idea!
Here are my suggestions so far. Please feel free to add/change/remove/... them:
Suggested conventions:
- Methods with no parameters should be written as a property, e.g.
Bar get foo => ...;
or if it is an async
operation:
Future<Bar> get foo async => ...;
- All members of the models should be written in camelCase. If the API returns a value
with_underscore
, use@Jsonkey(name: 'with_underscore')
to map the json entry e.g.
@Jsonkey(name: 'with_underscore')
Bar? withUnderscore;
- Append query parameters in a variable:
/// Gets [Foo] given [bar]
Future<Foo> getFoo(Bar bar) async {
final query = _buildQuery({'bar': bar});
return await _api._get('$_path?$query');
}
-
GET
request methods should have unit tests. The path for the API (e.g.v1/me/tracks
) reflects thejson
response files in thetest/data/
folder. - Methods with only one line should be written with the shorthand
=>
arrow syntax. - Each endpoint method must have a documentation on what it does. It can be copied from the spotify documentation as well.
- Use
enum
instead ofString
for types returned by the API. See theAlbum
class for examples. - Create an enhanced enum with a
String key
for the API. See dart's documentation for that and theMe.TimeRange
enum as an example.