getAgent method

Future<ManagedAgent> getAgent({
  1. required String projectId,
  2. required String name,
})

Implementation

Future<ManagedAgent> getAgent({required String projectId, required String name}) async {
  final encodedProjectId = Uri.encodeComponent(projectId);
  final encodedAgentName = Uri.encodeComponent(name);
  final uri = Uri.parse('$baseUrl/accounts/projects/$encodedProjectId/agents/$encodedAgentName');
  final response = await httpClient.get(uri);

  if (response.statusCode == 404) {
    throw NotFoundException('agent not found');
  }

  if (response.statusCode >= 400) {
    throw MeshagentException(
      'Failed to get agent. '
      'Status code: ${response.statusCode}, body: ${response.body}',
    );
  }

  return ManagedAgent.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
}