diff options
| author | Aldrik Ramaekers <aldrik@amftech.nl> | 2022-11-07 21:23:36 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@amftech.nl> | 2022-11-07 21:23:36 +0100 |
| commit | eed27fa5568e507c255a524185356786c877b2b8 (patch) | |
| tree | 4e2748dfd42ec1d3c4584102e6780db09bd82f0a /lib/services/storegear_api_service.dart | |
| parent | 94d5a9897bf536a359febab1b422a6aff1bfd080 (diff) | |
ready for irl test
Diffstat (limited to 'lib/services/storegear_api_service.dart')
| -rw-r--r-- | lib/services/storegear_api_service.dart | 57 |
1 files changed, 51 insertions, 6 deletions
diff --git a/lib/services/storegear_api_service.dart b/lib/services/storegear_api_service.dart index ecd0c94..109c17b 100644 --- a/lib/services/storegear_api_service.dart +++ b/lib/services/storegear_api_service.dart @@ -6,6 +6,8 @@ import 'package:training_planner/models/login_response.dart'; import 'package:training_planner/models/route_list.dart'; import 'package:training_planner/route.dart'; import 'package:training_planner/services/istoregear_api_service.dart'; +import 'package:training_planner/route.dart' as DHLRoute; +import 'package:training_planner/services/mock_route_provider_service.dart'; class StoregearApiService extends IStoregearApiService { String apiKey = ''; @@ -15,8 +17,7 @@ class StoregearApiService extends IStoregearApiService { final response = await http.post( Uri.parse('http://dhlapis.com/delivery/v1/users/login?env_type=PROD'), body: jsonEncode(req)); - debugPrint(jsonEncode(req)); - debugPrint(response.body); + if (response.statusCode == 200) { // If the server did return a 200 OK response, // then parse the JSON. @@ -56,6 +57,29 @@ class StoregearApiService extends IStoregearApiService { "in_trip_scan_finished": "true", "eva_added": "true", "trip_start_request_sent": "true" + }, + { + "timeframe_key": "96870", + "trip_key": "18996871", + "trip_number": "10", + "trip_pda_status": "5", + "trip_pda_status_description": "Rit overgedragen", + "trip_sequence_number": "1", + "number_in_trip": "139", + "plate": "VND-37-B", + "damage_registration": true, + "eva": "11:11", + "trip_date": "4/11/2022", + "first_address_lat": "50.8996568140536", + "first_address_lng": "5.75238472757395", + "started": "true", + "all_tasks_finished": "false", + "start_km": "24704", + "end_km": null, + "tasks_enriched": "true", + "in_trip_scan_finished": "true", + "eva_added": "true", + "trip_start_request_sent": "true" } ] } @@ -64,14 +88,12 @@ class StoregearApiService extends IStoregearApiService { @override Future<RouteList> getRoutes() async { - return _getMockRouteList(); + //return _getMockRouteList(); - debugPrint('WE GOT HERE!!! ' + apiKey); final response = await http.get( Uri.parse('http://dhlapis.com/delivery/v1/routes'), headers: {'X-API-KEY': apiKey}); - debugPrint(response.body); if (response.statusCode == 200) { // If the server did return a 200 OK response, // then parse the JSON. @@ -80,7 +102,6 @@ class StoregearApiService extends IStoregearApiService { if (content["message"] != null) { return RouteList(routes: []); } - debugPrint('amogus'); return RouteList.fromJson(content); } else { // If the server did not return a 200 OK response, @@ -88,4 +109,28 @@ class StoregearApiService extends IStoregearApiService { throw Exception('Failed to load routes'); } } + + Future<DHLRoute.Route?> getRoute(String tripkey) async { + //return MockRouteProviderService().getRoute(int.parse(tripkey)); + + final response = await http.get( + Uri.parse( + 'http://dhlapis.com/delivery/v1/routes/' + tripkey.toString()), + headers: {'X-API-KEY': apiKey}); + + if (response.statusCode == 200) { + // If the server did return a 200 OK response, + // then parse the JSON. + + var content = jsonDecode(response.body); + if (content["message"] != null) { + return null; + } + return DHLRoute.Route.fromJson(content); + } else { + // If the server did not return a 200 OK response, + // then throw an exception. + throw Exception('Failed to load route'); + } + } } |
