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;
|
||||
}
|
||||
}
|
||||
+19
-1
@@ -1,6 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'api_handler.dart';
|
||||
|
||||
void main() {
|
||||
void main() async {
|
||||
await dotenv.load();
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
@@ -55,6 +58,10 @@ class MyHomePage extends StatefulWidget {
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
//String API_KEY = ApiHandler.accessID;
|
||||
String API_KEY = "no telly";
|
||||
//Future<Map<String, dynamic>> ?id;
|
||||
String id = '';
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
@@ -66,6 +73,10 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
_counter++;
|
||||
});
|
||||
}
|
||||
void show_result(Future<String> future_id) async {
|
||||
id = await future_id;
|
||||
setState(() { });
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -109,6 +120,13 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
'$_counter',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
),
|
||||
Text('API key from ENV is $API_KEY'),
|
||||
MaterialButton(onPressed: () { show_result(ApiHandler.findStations('S Biesdorf')); setState(() {}); },
|
||||
child: Text(
|
||||
'Search for \'S Biesdorf\''
|
||||
),
|
||||
),
|
||||
Text(id)
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user