getEngines method
Gets the list of engines available.
Implementation
Future<List<Engine>> getEngines({
required String apiKey,
String? organization,
String? clientId,
String? clientVersion,
}) async {
Map<String, String> headers = {
"Authorization": apiKey,
'Content-Type': 'application/json',
"Access-Control-Allow-Origin": "*", // Required for CORS support to work
};
if (organization != null) {
headers.putIfAbsent("Organization", () => organization);
}
if (clientId != null) {
headers.putIfAbsent("Stability-Client-ID", () => clientId);
}
if (clientVersion != null) {
headers.putIfAbsent("Stability-Client-Version", () => clientVersion);
}
Uri endpoint;
if (secure) {
endpoint = Uri.https(baseUrl, "/v1/engines/list");
} else {
endpoint = Uri.http(baseUrl, "/v1/engines/list");
}
var response = await http.get(endpoint, headers: headers);
if (response.statusCode == 200 || response.statusCode == 201) {
return (jsonDecode(const Utf8Decoder().convert(response.bodyBytes))
as List)
.map<Engine>((e) => Engine.fromJson(e))
.toList();
} else {
var error = ServerError.fromJson(jsonDecode(response.body));
throw EngineException(
statusCode: response.statusCode, message: error.message);
}
}