class GoogleDrive::AclEntry

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 .

Attributes

acl[R]
api_permission[RW]

@api private

params[R]

@api private

Public Class Methods

new(params_or_api_permission, acl = nil) click to toggle source

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.

# 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

Public Instance Methods

additional_roles() click to toggle source
# File lib/google_drive/acl_entry.rb, line 59
def additional_roles
  @params ? @params[:additionalRoles] : @api_permission.additional_roles
end
allow_file_discovery() click to toggle source

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

# File lib/google_drive/acl_entry.rb, line 99
def allow_file_discovery
  @params ?
    @params[:allow_file_discovery] : @api_permission.allow_file_discovery
end
domain() click to toggle source

The Google Apps domain name.

# File lib/google_drive/acl_entry.rb, line 73
def domain
  @params ? @params[:domain] : @api_permission.domain
end
email_address() click to toggle source

Email address of the user or the group.

# File lib/google_drive/acl_entry.rb, line 68
def email_address
  @params ? @params[:email_address] : @api_permission.email_address
end
id() click to toggle source
# File lib/google_drive/acl_entry.rb, line 63
def id
  @params ? @params[:id] : @api_permission.id
end
inspect() click to toggle source
# File lib/google_drive/acl_entry.rb, line 125
def inspect
  case type
  when 'user', 'group'
    format(
      "\#<%p type=%p, email_address=%p, role=%p>",
      self.class, type, email_address, role
    )
  when 'domain'
    format(
      "\#<%p type=%p, domain=%p, role=%p>",
      self.class, type, domain, role
    )
  when 'anyone'
    format(
      "\#<%p type=%p, role=%p, allow_file_discovery=%p>",
      self.class, type, role, allow_file_discovery
    )
  else
    format("\#<%p type=%p, role=%p>", self.class, type, role)
  end
end
role() click to toggle source

The role given to the scope. One of:

  • “owner”: The owner.

  • “writer”: With read/write access.

  • “reader”: With read-only access.

# File lib/google_drive/acl_entry.rb, line 43
def role
  @params ? @params[:role] : @api_permission.role
end
role=(role) click to toggle source

Changes the role of the scope.

e.g.

spreadsheet.acl[1].role = "writer"
# File lib/google_drive/acl_entry.rb, line 116
def role=(role)
  if @params
    @params[:role] = role
  else
    @api_permission.role = role
    @acl.update_role(self)
  end
end
scope()
Alias for: value
scope_type()
Alias for: type
type() click to toggle source

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.

# File lib/google_drive/acl_entry.rb, line 53
def type
  @params ? @params[:type] : @api_permission.type
end
Also aliased as: scope_type
value() click to toggle source
# 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]
    end
  else
    case @api_permission.type
    when 'user', 'group'
      @api_permission.email_address
    when 'domain'
      @api_permission.domain
    end
  end
end
Also aliased as: scope
with_key()
Alias for: with_link

Private Instance Methods

convert_params(orig_params) click to toggle source

Normalizes the key to Symbol, and converts parameters in the old version.

# File lib/google_drive/acl_entry.rb, line 150
def convert_params(orig_params)
  new_params = {}
  value = nil
  orig_params.each do |k, v|
    k = k.to_s
    case k
    when 'scope_type'
      new_params[:type] = (v == 'default' ? 'anyone' : v)
    when 'scope'
      new_params[:value] = v
    when 'with_key', 'withLink'
      new_params[:allow_file_discovery] = !v
    when 'value'
      value = v
    else
      new_params[k.intern] = v
    end
  end

  if value
    case new_params[:type]
    when 'user', 'group'
      new_params[:email_address] = value
    when 'domain'
      new_params[:domain] = value
    end
  end

  new_params
end