StatusDocument.parse constructor

StatusDocument.parse(
  1. Map<String, dynamic> json
)

Implementation

factory StatusDocument.parse(Map<String, dynamic> json) {
  String? id;
  Status? status;
  String? message;
  Links? links;
  DateTime? licenseUpdated;
  DateTime? statusUpdated;
  PotentialRights? potentialRights;
  List<Event> events = [];

  try {
    if (json.containsKey("id")) id = json["id"];
    if (json.containsKey("status")) {
      status = Status.valueOf(json["status"])!;
    }
    if (json.containsKey("message")) {
      message = json["message"];
    }
    if (json.containsKey("updated")) {
      Map? updatedJson = json["updated"];
      if (updatedJson != null && updatedJson.isNotEmpty) {
        licenseUpdated = DateTime.tryParse(updatedJson["license"]);
        statusUpdated = DateTime.tryParse(updatedJson["status"]);
      }
    }
    if (json.containsKey("links")) {
      links = Links.parse(json["links"] as List);
    }
    if (json.containsKey("events")) {
      events = Event.parseEvents(json["events"] as List);
    }
    if (json.containsKey("potential_rights")) {
      potentialRights = PotentialRights.parse(json["potential_rights"]);
    }
  } on Exception {
    throw Exception(LcpParsingError.errorDescription(LcpParsingErrors.json));
  }
  if (id == null ||
      status == null ||
      message == null ||
      licenseUpdated == null ||
      statusUpdated == null ||
      links == null) {
    throw Exception(LcpParsingError.errorDescription(LcpParsingErrors.json));
  }

  return StatusDocument._(id, status, message, licenseUpdated, statusUpdated,
      links, potentialRights, events, json);
}