get method

Reads the collection referenced by this CollectionReference from the server.

If no collection exists on the server (yet), this local CollectionReference is returned.

Implementation

Future<CollectionReference> get() async {
  final response = await service._get(collectionUri);
  int httpStatusCode = response.statusCode;

  Map<String, dynamic> responseJson =
      json.decode(response.body) as Map<String, dynamic>;
  if (httpStatusCode == HttpStatus.ok) {
    return this
      .._id = responseJson['id'] as int
      .._path = responseJson['name'].toString();
  }

  // All other cases are treated as an error.
  throw CarpServiceException.fromMap(httpStatusCode, responseJson);
}