createConsentDocument method
Create a new (signed) consent document for this user. Returns the created ConsentDocument if the document is uploaded correctly.
Implementation
Future<ConsentDocument> createConsentDocument(
Map<String, dynamic> document) async {
// POST the document to the CARP web service
http.Response response = await http.post(
Uri.parse(Uri.encodeFull(consentDocumentEndpointUri)),
headers: headers,
body: json.encode(document));
int httpStatusCode = response.statusCode;
Map<String, dynamic> responseJson =
json.decode(response.body) as Map<String, dynamic>;
if ((httpStatusCode == HttpStatus.ok) ||
(httpStatusCode == HttpStatus.created)) {
return ConsentDocument._(responseJson);
}
// All other cases are treated as an error.
throw CarpServiceException(
httpStatus: HTTPStatus(httpStatusCode, response.reasonPhrase),
message: responseJson["message"].toString(),
path: responseJson["path"].toString(),
);
}