setOydabase function
Sets the Oydabase configuration by sending a POST request to the specified API endpoint.
The function takes in the host
, port
, oydaBase
, user
, and password
parameters
to construct the request body. It then sends the request to the API endpoint and
handles the response accordingly.
If the request is successful (status code 200), it prints a success message and returns true. Otherwise, it prints the error message from the response body and returns false.
If an error occurs during the request, it prints the error message and returns false.
Implementation
Future<Map<String, dynamic>> setOydabase(String host, int port, String oydaBase,
String user, String password) async {
final url =
Uri.parse('https://oydabackend.azurewebsites.net/api/set_oydabase');
final Map<String, dynamic> requestBody = {
'host': host,
'port': port,
'oydaBase': oydaBase,
'user': user,
'password': password,
};
try {
final response = await http.post(
url,
headers: {'Content-Type': 'application/json'},
body: json.encode(requestBody),
);
if (response.statusCode == 200) {
final responseBody = json.decode(response.body);
print('${responseBody['message']}');
print('Dev Key: ${responseBody['dev_key']}');
return {'success': true, 'dev_key': responseBody['dev_key']};
} else {
final responseBody = json.decode(response.body);
print('Error: ${responseBody['error']}');
return {'success': false, 'dev_key': null};
}
} catch (e) {
print('Error connecting to the Oydabase: $e');
return {'success': false, 'dev_key': null};
}
}