getMailbox method

Future<Mailbox> getMailbox({
  1. required String projectId,
  2. required String address,
})

GET /accounts/projects/{project_id}/mailboxes/{address}

Implementation

Future<Mailbox> getMailbox({required String projectId, required String address}) async {
  final encodedProjectId = Uri.encodeComponent(projectId);
  final encodedAddress = Uri.encodeComponent(address);
  final uri = Uri.parse('$baseUrl/accounts/projects/$encodedProjectId/mailboxes/$encodedAddress');
  final response = await httpClient.get(uri);

  if (response.statusCode == 404) {
    throw NotFoundException('Mailbox not found: $address');
  }

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

  final data = jsonDecode(response.body) as Map<String, dynamic>;
  return Mailbox.fromJson(data["mailbox"]);
}