findObjects method
Find all objects of this bot with a specific type.
- {type} is the type of object that you want to find.
Implementation
Future<List<BotObject>?> findObjects({required BotObjectType type}) async {
try {
Uri url = Uri.parse(
"${GetIt.I<BotnoiClient>().endpoint}/developer/platform-api/object/${type.stringType}?bot_id=${_bot.id}");
http.Response response = await http.get(
url,
headers: _getHeader,
);
if (response.statusCode == 200) {
dynamic result = jsonDecode(utf8.decode(response.bodyBytes));
GetIt.I<BotnoiClient>().finishedSuccessfully();
return (result as List)
.map((e) =>
BotObject.fromJson(e as Map, botId: _bot.id)..belongToBot(_bot))
.toList();
}
GetIt.I<BotnoiClient>().finishedFailed();
GetIt.I<BotnoiClient>()
.error
.add("[findObjects] : ${response.reasonPhrase ?? "ERROR"}");
return null;
} catch (e) {
GetIt.I<BotnoiClient>().finishedFailed();
GetIt.I<BotnoiClient>().error.add("[findObjects] : $e");
return null;
}
}