setOydaBase method
- @Deprecated("Set the oydabase from the oydacli instead. This method will be removed in the future.")
Sets the OYDA base configuration.
The host parameter specifies the host address.
The portparameter specifies the port number.
The oydaBase parameter specifies the OYDA base.
The user parameter specifies the username.
The password parameter specifies the password.
Returns a Future that completes when the OYDA base is set.
Implementation
@Deprecated(
"Set the oydabase from the oydacli instead. This method will be removed in the future.")
/// Sets the OYDA base configuration.
///
/// The `host` parameter specifies the host address.
/// The `port`parameter specifies the port number.
/// The `oydaBase` parameter specifies the OYDA base.
/// The `user` parameter specifies the username.
/// The `password` parameter specifies the password.
///
/// Returns a `Future` that completes when the OYDA base is set.
Future<void> setOydaBase(String? host, String? port, String? oydaBase,
String? user, String? password) async {
if (host == null ||
port == null ||
oydaBase == null ||
user == null ||
password == null) {
throw Exception('Missing required parameters for setting the oydabase.');
}
if (this.oydaBase != null &&
this.oydaBase == oydaBase &&
this.host != null &&
this.host == host &&
this.port != null &&
this.port == port &&
this.user != null &&
this.user == user &&
this.password != null &&
this.password == password) {
print('Oydabase already set to "$oydaBase".');
return;
}
final url =
Uri.parse('http://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) {
dotenv.env['HOST'] = host;
dotenv.env['PORT'] = port;
dotenv.env['OYDA_BASE'] = oydaBase;
dotenv.env['USER'] = user;
dotenv.env['PASSWORD'] = password;
this.host = host;
this.port = port;
this.oydaBase = oydaBase;
this.user = user;
this.password = password;
final responseBody = jsonDecode(response.body);
print(responseBody['message'] ??
'Connected to Oydabase @ $host:$port/$oydaBase.');
} else {
final responseBody = jsonDecode(response.body);
throw '${responseBody['error']}';
}
} catch (e) {
throw Exception('Error connecting to the Oydabase: $e');
}
}