2022-02-14 20:19:04 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'package:leg_barkr_app/utils/endpoints.dart' as Endpoints;
|
|
|
|
|
|
|
|
class StepsService {
|
2022-02-15 11:52:19 +00:00
|
|
|
Future<int> getStepsToday(String deviceId, String sessionToken) async {
|
2022-02-14 20:19:04 +00:00
|
|
|
final response = await http.get(
|
|
|
|
Uri.parse(Endpoints.getStepsToday),
|
|
|
|
headers: <String, String>{
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
2022-02-15 11:52:19 +00:00
|
|
|
'Authorization': sessionToken,
|
|
|
|
'Device-ID': deviceId,
|
2022-02-14 20:19:04 +00:00
|
|
|
},
|
|
|
|
);
|
2022-02-15 11:52:19 +00:00
|
|
|
if (response.statusCode == 200) {
|
|
|
|
return jsonDecode(response.body)['cumulative_steps_today'];
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2022-02-14 20:19:04 +00:00
|
|
|
}
|
2022-02-14 23:28:27 +00:00
|
|
|
|
2022-02-15 11:52:19 +00:00
|
|
|
Future<List<int>> getStepsLastFiveDays(String deviceId, String sessionToken) async {
|
2022-02-14 23:28:27 +00:00
|
|
|
final response = await http.get(
|
|
|
|
Uri.parse(Endpoints.getStepsLastFiveDays),
|
|
|
|
headers: <String, String>{
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
2022-02-15 11:52:19 +00:00
|
|
|
'Authorization': sessionToken,
|
|
|
|
'Device-ID': deviceId,
|
2022-02-14 23:28:27 +00:00
|
|
|
},
|
|
|
|
);
|
2022-02-15 11:52:19 +00:00
|
|
|
if (response.statusCode == 200) {
|
|
|
|
List<dynamic> list = jsonDecode(response.body)['daily_steps'];
|
|
|
|
List<int> steps = [];
|
|
|
|
for (final l in list){
|
|
|
|
steps.add(l);
|
|
|
|
}
|
|
|
|
return steps;
|
|
|
|
} else {
|
|
|
|
return [];
|
2022-02-15 11:06:39 +00:00
|
|
|
}
|
2022-02-14 23:28:27 +00:00
|
|
|
}
|
2022-02-14 20:19:04 +00:00
|
|
|
}
|