Class: GoogleDriveV0::AclEntry

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

Overview

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

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

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

Constant Summary collapse

PARAM_NAMES =

:nodoc:

[:acl, :scope_type, :scope, :with_key, :role, :title, :edit_url, :etag]

Constants included from Util

Util::DOCS_BASE_URL, Util::EXT_TO_CONTENT_TYPE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

concat_url, encode_query, h, to_v3_url

Constructor Details

#initialize(params) ⇒ AclEntry

params is a Hash object with keys :scope_type, :scope and :role. See scope_type and role for the document of the fields.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/google_drive_v0/acl_entry.rb', line 22

def initialize(params)
  @params = {:role => "reader"}
  for name, value in params
    if !name.is_a?(Symbol)
      raise(ArgumentError, "Key must be Symbol, but is %p" % name)
    elsif !PARAM_NAMES.include?(name)
      raise(ArgumentError, "Invalid key: %p" % name)
    end
    @params[name] = value
  end
end

Instance Attribute Details

#paramsObject

:nodoc:



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

def params
  @params
end

Instance Method Details

#edit_urlObject



42
43
44
45
46
# File 'lib/google_drive_v0/acl_entry.rb', line 42

def edit_url
  warn(
      "WARNING: GoogleDriveV0::AclEntry\#edit_url is deprecated and will be removed in the next version.")
  return self.edit_url_internal
end

#edit_url_internalObject

:nodoc:



48
49
50
# File 'lib/google_drive_v0/acl_entry.rb', line 48

def edit_url_internal #:nodoc:
  return @params[:edit_url]
end

#inspectObject



61
62
63
64
# File 'lib/google_drive_v0/acl_entry.rb', line 61

def inspect
  return "\#<%p scope_type=%p, scope=%p, with_key=%p, role=%p>" %
      [self.class, @params[:scope_type], @params[:scope], @params[:with_key], @params[:role]]
end

#role=(role) ⇒ Object

Changes the role of the scope.

e.g.

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


56
57
58
59
# File 'lib/google_drive_v0/acl_entry.rb', line 56

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

#to_xmlObject

:nodoc:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/google_drive_v0/acl_entry.rb', line 66

def to_xml()  #:nodoc:
  
  etag_attr = self.etag ? "gd:etag='#{h(self.etag)}'" : ""
  value_attr = self.scope ? "value='#{h(self.scope)}'" : ""
  if self.with_key
    role_tag = <<-EOS
        <gAcl:withKey key='[ACL KEY]'>
          <gAcl:role value='#{h(self.role)}'/>
        </gAcl:withKey>
    EOS
  else
    role_tag = <<-EOS
      <gAcl:role value='#{h(self.role)}'/>
    EOS
  end
  
  return <<-EOS
    <entry
        xmlns='http://www.w3.org/2005/Atom'
        xmlns:gAcl='http://schemas.google.com/acl/2007'
        xmlns:gd='http://schemas.google.com/g/2005'
        #{etag_attr}>
      <category scheme='http://schemas.google.com/g/2005#kind'
          term='http://schemas.google.com/acl/2007#accessRule'/>
      #{role_tag}
      <gAcl:scope type='#{h(self.scope_type)}' #{value_attr}/>
    </entry>
  EOS
  
end