Class: GoogleDrive::AclEntry

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/google_drive/acl_entry.rb

Overview

An entry of an ACL (access control list) of a spreadsheet.

Use GoogleDrive::Acl#[] to get GoogleDrive::AclEntry object.

This code is based on github.com/guyboertje/gdata-spreadsheet-ruby .

Constant Summary

Constants included from Util

Util::EXT_TO_CONTENT_TYPE, Util::IMPORTABLE_CONTENT_TYPE_MAP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

concat_url, construct_and_query, construct_query, convert_params, delegate_api_methods, encode_query, get_singleton_class, h

Constructor Details

#initialize(params_or_api_permission, acl = nil) ⇒ AclEntry

params_or_api_permission is a Hash object with keys :type, :email_address, :domain, :role and :allow_file_discovery. See GoogleDrive::Acl#push for description of the parameters.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/google_drive/acl_entry.rb', line 19

def initialize(params_or_api_permission, acl = nil)
  @acl = acl
  if acl
    @api_permission = params_or_api_permission
    @params = nil
    delegate_api_methods(self, @api_permission)
  else
    @api_permission = nil
    @params = convert_params(params_or_api_permission)
  end
end

Instance Attribute Details

#aclObject (readonly)

Returns the value of attribute acl.



31
32
33
# File 'lib/google_drive/acl_entry.rb', line 31

def acl
  @acl
end

#api_permissionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
# File 'lib/google_drive/acl_entry.rb', line 37

def api_permission
  @api_permission
end

#paramsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
# File 'lib/google_drive/acl_entry.rb', line 34

def params
  @params
end

Instance Method Details

#additional_rolesObject



59
60
61
# File 'lib/google_drive/acl_entry.rb', line 59

def additional_roles
  @params ? @params[:additionalRoles] : @api_permission.additional_roles
end

#allow_file_discoveryObject

If false, the file is shared only with people who know the link. Only used for type “anyone”.



103
104
105
# File 'lib/google_drive/acl_entry.rb', line 103

def allow_file_discovery
  @params ? @params[:allow_file_discovery] : @api_permission.allow_file_discovery
end

#domainObject

The Google Apps domain name.



73
74
75
# File 'lib/google_drive/acl_entry.rb', line 73

def domain
  @params ? @params[:domain] : @api_permission.domain
end

#email_addressObject

Email address of the user or the group.



68
69
70
# File 'lib/google_drive/acl_entry.rb', line 68

def email_address
  @params ? @params[:email_address] : @api_permission.email_address
end

#idObject



63
64
65
# File 'lib/google_drive/acl_entry.rb', line 63

def id
  @params ? @params[:id] : @api_permission.id
end

#inspectObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/google_drive/acl_entry.rb', line 128

def inspect
  case type
  when 'user', 'group'
    "\#<%p type=%p, email_address=%p, role=%p>" %
      [self.class, type, email_address, role]
  when 'domain'
    "\#<%p type=%p, domain=%p, role=%p>" %
      [self.class, type, domain, role]
  when 'anyone'
    "\#<%p type=%p, role=%p, allow_file_discovery=%p>" %
      [self.class, type, role, allow_file_discovery]
  else
    "\#<%p type=%p, role=%p>" %
      [self.class, type, role]
  end
end

#roleObject

The role given to the scope. One of:

  • “owner”: The owner.

  • “writer”: With read/write access.

  • “reader”: With read-only access.



43
44
45
# File 'lib/google_drive/acl_entry.rb', line 43

def role
  @params ? @params[:role] : @api_permission.role
end

#role=(role) ⇒ Object

Changes the role of the scope.

e.g.

spreadsheet.acl[1].role = "writer"


119
120
121
122
123
124
125
126
# File 'lib/google_drive/acl_entry.rb', line 119

def role=(role)
  if @params
    @params[:role] = role
  else
    @api_permission.role = role
    @acl.update_role(self)
  end
end

#typeObject Also known as: scope_type

Type of the scope. One of:

  • “user”: a Google account specified by the email_address field.

  • “group”: a Google Group specified by the email_address field.

  • “domain”: a Google Apps domain specified by the domain field.

  • “anyone”: Publicly shared with all users.



53
54
55
# File 'lib/google_drive/acl_entry.rb', line 53

def type
  @params ? @params[:type] : @api_permission.type
end

#valueObject Also known as: scope



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/google_drive/acl_entry.rb', line 77

def value
  if @params
    case @params[:type]
    when 'user', 'group'
      @params[:email_address]
    when 'domain'
      @params[:domain]
    else
      nil
    end
  else
    case @api_permission.type
    when 'user', 'group'
      @api_permission.email_address
    when 'domain'
      @api_permission.domain
    else
      nil
    end
  end
end

If true, the file is shared only with people who know the link. Only used for type “anyone”.



109
110
111
# File 'lib/google_drive/acl_entry.rb', line 109

def with_link
  allow_file_discovery == false
end