Listing User Docs - AWS SDK for Ruby

Listing User Docs

The following example lists the documents for a user. Choose Copy to save the code locally, or see the link to the complete example at the end of this topic.

  1. Require the AWS SDK for Ruby module.

  2. Create a helper method to get the root folder of a user.

  3. Create a Amazon WorkDocs client.

  4. Get the root folder for that user.

5. Call describe_folder_contents to get the contents of the folder in ascending order.

6. Display the name, size (in bytes), last modified date, document ID and version ID for each document in the user’s root folder.

# 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

See the complete example on GitHub.