getHeartbeats method
Gets the heartbeats for a given date
Implementation
Future<List<Heartbeat>> getHeartbeats(DateTime date) async {
final path = '$_baseUrl/users/current/heartbeats';
final parsedDate = DateFormat('yyyy-MM-dd').format(date);
logger.d('Getting heartbeats for date $parsedDate');
final response = await _provider.get(
path,
queryParams: {'date': parsedDate},
headers: _defaultHeaders,
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body) as Map<String, dynamic>;
return (data['data'] as List<dynamic>)
.map((e) => Heartbeat.fromJson(e))
.toList();
} else {
return [];
}
}