Created
January 17, 2012 16:19
-
-
Save beezly/1627306 to your computer and use it in GitHub Desktop.
List editors of shared documents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'gdata' | |
MAX_RETRIES = 5 | |
LOGIN_USER = "[email protected]" | |
LOGIN_PASSWORD = "administratorpassword" | |
# Login and use version 3 of the api (only v3 allows admin access to files) | |
client = GData::Client::DocList.new | |
client.version=3 | |
client.clientlogin(LOGIN_USER, LOGIN_PASSWORD) | |
if ARGV[0] | |
user=ARGV[0] | |
else | |
user="default" | |
end | |
attempt = 0 | |
begin | |
attempt += 1 | |
feed = client.get("https://docs.google.com/feeds/#{user}/private/full/-/mine").to_xml | |
rescue | |
if attempt < MAX_RETRIES | |
retry | |
else | |
raise | |
end | |
end | |
# Pull out a list of all documents and populate with ACLs | |
documents = [] | |
feed.elements.each('entry') do |entry| | |
feedLink = entry.elements['gd:feedLink'].attribute('href').value | |
acl = [] | |
attempt = 0 | |
begin | |
attempt += 1 | |
acllist = client.get(feedLink).to_xml | |
rescue | |
if attempt < MAX_RETRIES | |
retry | |
else | |
raise | |
end | |
end | |
acllist.elements.each('entry') do |entry| | |
begin | |
role = entry.elements['gAcl:role'].attribute('value').value | |
scope_type = entry.elements['gAcl:scope'].attribute('type').value | |
scope_value = entry.elements['gAcl:scope'].attribute('value').value | |
acl.push :id => scope_value, :role => role, :type => scope_type | |
rescue | |
# We discovered an ACL entry we didn't understand. Ah well | |
end | |
end | |
documents.push :title => entry.elements['title'].text, :id => entry.elements['id'].text, :acl => acl, :url => entry.elements.to_a("link[@rel='alternate']")[0].attribute('href').value | |
end | |
# Get a list of all writers so we can iterate through them to send the e-mails | |
writers = [] | |
documents.each do |doc| | |
(doc[:acl].select { |e| e[:role] == "writer" }).each do |x| | |
id = x.fetch :id | |
writers.push id unless writers.include? id or id == "everyone" | |
end | |
end | |
# Now show a list of documents that each writer has access to | |
writers.each do |w| | |
puts w | |
(documents.select { |d| (d[:acl].select { |a| a[:id] == w and a[:role] == 'writer' }).length > 0 }).each { |d| puts d[:title], d[:url] } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment