Public Access
feat(api_connection): add test request to VBB API and ignore env files
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
|
||||
import 'dart:core';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'transport_helper.dart';
|
||||
|
||||
class ApiHandler {
|
||||
// TODO: Split next line for better Error Handling
|
||||
static final String baseUrl = dotenv.get("VBB_API_URL");
|
||||
static final String accessID = dotenv.get("VBB_API_KEY");
|
||||
|
||||
//static Future<Map<String, dynamic>> findStations(String locationName) async {
|
||||
static Future<String> findStations(String locationName) async {
|
||||
String urlPath = '/api/fahrinfo/latest/location.name';
|
||||
String urlParams = '?input=$locationName';
|
||||
Uri url = Uri.https(baseUrl, urlPath, {
|
||||
'accessId': accessID,
|
||||
'input': locationName,
|
||||
'maxNo': '2',
|
||||
'type': 'S' // Station/Stops only
|
||||
});
|
||||
//print(url);
|
||||
var jsonResponse = await http.get(url,
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
});
|
||||
final httpPackageJson = json.decode(jsonResponse.body) as Map<String, dynamic>;
|
||||
//print(httpPackageJson["stopLocationOrCoordLocation"]);
|
||||
final id = httpPackageJson["stopLocationOrCoordLocation"][0]["StopLocation"]["id"];
|
||||
//print("and now just ids: ");
|
||||
//print(id);
|
||||
return id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user