wd_list_user_docs.rb - AWS Code Sample


Lists the documents for each of your WorkDocs users.

# Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. # # This file is licensed under the Apache License, Version 2.0 (the "License"). # You may not use this file except in compliance with the License. A copy of the # License is located at # # http://aws.amazon.com/apache2.0/ # # This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS # OF ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. require 'aws-sdk-workdocs' # v2: require 'aws-sdk' def get_user_folder(client, orgId, user_email) root_folder = '' resp = client.describe_users({ organization_id: orgId, }) # resp.users should have only one entry resp.users.each do |user| if user.email_address == user_email root_folder = user.root_folder_id end end return root_folder end client = Aws::WorkDocs::Client.new(region: 'us-west-2') # Set to the email address of a user user_email = 'someone@somewhere' # Set to the OrganizationId of your WorkDocs site. orgId = 'd-123456789c' user_folder = get_user_folder(client, orgId, user_email) if user_folder == '' puts 'Could not get root folder for user with email address ' + user_email exit(1) end resp = client.describe_folder_contents({ folder_id: user_folder, # required sort: "NAME", # accepts DATE, NAME order: "ASCENDING", # accepts ASCENDING, DESCENDING }) resp.documents.each do |doc| md = doc.latest_version_metadata puts "Name: #{md.name}" puts "Size (bytes): #{md.size}" puts "Last modified: #{doc.modified_timestamp}" puts "Doc ID: #{doc.id}" puts "Version ID: #{md.id}" puts end

Sample Details

Service: workdocs

Last tested: 2018-03-16

Author: Doug-AWS

Type: full-example