share method

Future<Permission> share(
  1. String user, {
  2. PermType type = PermType.user,
  3. PermRole role = PermRole.reader,
  4. bool withLink = false,
})

Shares Spreadsheet.

Requires SheetsApi.DriveScope.

user - the email address or domain name for the entity. type - the account type. role - the primary role for this user. withLink - whether the link is required for this permission.

Returns Future of shared Permission.

Throws Exception if GSheets's scopes does not include DriveScope. Throws GSheetsException if DriveScope is not configured.

Implementation

Future<Permission> share(
  String user, {
  PermType type = PermType.user,
  PermRole role = PermRole.reader,
  bool withLink = false,
}) async {
  final response = await _client.post(
    '$_filesEndpoint$id/permissions'.toUri(),
    body: jsonEncode({
      'value': user,
      'type': Permission._parseType(type),
      'role': Permission._parseRole(role),
      'withLink': withLink,
    }),
    headers: {'Content-type': 'application/json'},
  );
  checkResponse(response);
  return Permission._fromJson(jsonDecode(response.body));
}