getBalance method

Future<Balance> getBalance({
  1. required String apiKey,
})

Get the credit balance of the account/organization associated with the API key

Implementation

Future<Balance> getBalance({
  required String apiKey,
}) async {

  Map<String, String> headers = {
    "Authorization": apiKey,
    'Content-Type': 'application/json',
    "Access-Control-Allow-Origin": "*", // Required for CORS support to work
  };


  Uri endpoint;
  if(secure) {
    endpoint = Uri.https(
        baseUrl, "/v1/user/balance");
  }
  else {
    endpoint = Uri.http(
        baseUrl, "/v1/user/balance");
  }

  var response = await
  http.get(endpoint, headers: headers);

  if (response.statusCode == 200 || response.statusCode == 201) {
    return Balance.fromJson(jsonDecode(const Utf8Decoder().convert(response.bodyBytes)));
  }
  else {
    var error = ServerError.fromJson(jsonDecode(response.body));
    throw UserException(statusCode: response.statusCode, message: error.message);
  }
}