NAME

Net::Google::Drive::Simple::Item - Representation of a Google Drive File

SYNOPSIS

use feature 'say';
use Net::Google::Drive::Simple;

# requires a ~/.google-drive.yml file with an access token,
# see description from Net::Google::Drive::Simple

my $gd = Net::Google::Drive::Simple->new();
my $children = $gd->children( "/" ); # or any other folder /path/location

foreach my $item ( @$children ) {
    # $item is one Net::Google::Drive::Simple::Item object

    if ( $item->is_folder ) {
        say "** ", $item->title, " is a folder";
    } else {
        say $item->title, " is a file ", $item->mimeType;
        eval { # originalFilename not necessary available for all files
           say $item->originalFilename(), " can be downloaded at ", $item->downloadUrl();
        };
    }
}

DESCRIPTION

Net::Google::Drive::Simple::Item provides a class to manipulate the File methadata from Google Drive API.

https://developers.google.com/drive/api/v3/reference/files

GETTING STARTED

This class should not be used directly, and you should use Net::Google::Drive::Simple as shown in the synopsis.

METHODS

new( $data )

Constructor, creates one object which hold on hash ref $data to manipulate the metadata for a file. All the keys from the hash below as documented in Google Drive API Doc are mapped using AUTOLOAD so you can use helpers for every first level entry like these:

$file->kind;
$file->id;
$file->name;
$file->mimeType;
....

{
  "kind": "drive#file",
  "id": string,
  "name": string,
  "mimeType": string,
  "description": string,
  "starred": boolean,
  "trashed": boolean,
  "explicitlyTrashed": boolean,
  "trashingUser": {
    "kind": "drive#user",
    "displayName": string,
    "photoLink": string,
    "me": boolean,
    "permissionId": string,
    "emailAddress": string
  },
  "trashedTime": datetime,
  "parents": [
    string
  ],
  "properties": {
    (key): string
  },
  "appProperties": {
    (key): string
  },
  "spaces": [
    string
  ],
  "version": long,
  "webContentLink": string,
  "webViewLink": string,
  "iconLink": string,
  "hasThumbnail": boolean,
  "thumbnailLink": string,
  "thumbnailVersion": long,
  "viewedByMe": boolean,
  "viewedByMeTime": datetime,
  "createdTime": datetime,
  "modifiedTime": datetime,
  "modifiedByMeTime": datetime,
  "modifiedByMe": boolean,
  "sharedWithMeTime": datetime,
  "sharingUser": {
    "kind": "drive#user",
    "displayName": string,
    "photoLink": string,
    "me": boolean,
    "permissionId": string,
    "emailAddress": string
  },
  "owners": [
    {
      "kind": "drive#user",
      "displayName": string,
      "photoLink": string,
      "me": boolean,
      "permissionId": string,
      "emailAddress": string
    }
  ],
  "teamDriveId": string,
  "driveId": string,
  "lastModifyingUser": {
    "kind": "drive#user",
    "displayName": string,
    "photoLink": string,
    "me": boolean,
    "permissionId": string,
    "emailAddress": string
  },
  "shared": boolean,
  "ownedByMe": boolean,
  "capabilities": {
    "canAddChildren": boolean,
    "canChangeCopyRequiresWriterPermission": boolean,
    "canChangeViewersCanCopyContent": boolean,
    "canComment": boolean,
    "canCopy": boolean,
    "canDelete": boolean,
    "canDeleteChildren": boolean,
    "canDownload": boolean,
    "canEdit": boolean,
    "canListChildren": boolean,
    "canModifyContent": boolean,
    "canMoveChildrenOutOfTeamDrive": boolean,
    "canMoveChildrenOutOfDrive": boolean,
    "canMoveChildrenWithinTeamDrive": boolean,
    "canMoveChildrenWithinDrive": boolean,
    "canMoveItemIntoTeamDrive": boolean,
    "canMoveItemOutOfTeamDrive": boolean,
    "canMoveItemOutOfDrive": boolean,
    "canMoveItemWithinTeamDrive": boolean,
    "canMoveItemWithinDrive": boolean,
    "canMoveTeamDriveItem": boolean,
    "canReadRevisions": boolean,
    "canReadTeamDrive": boolean,
    "canReadDrive": boolean,
    "canRemoveChildren": boolean,
    "canRename": boolean,
    "canShare": boolean,
    "canTrash": boolean,
    "canTrashChildren": boolean,
    "canUntrash": boolean
  },
  "viewersCanCopyContent": boolean,
  "copyRequiresWriterPermission": boolean,
  "writersCanShare": boolean,
  "permissions": [
    permissions Resource
  ],
  "permissionIds": [
    string
  ],
  "hasAugmentedPermissions": boolean,
  "folderColorRgb": string,
  "originalFilename": string,
  "fullFileExtension": string,
  "fileExtension": string,
  "md5Checksum": string,
  "size": long,
  "quotaBytesUsed": long,
  "headRevisionId": string,
  "contentHints": {
    "thumbnail": {
      "image": bytes,
      "mimeType": string
    },
    "indexableText": string
  },
  "imageMediaMetadata": {
    "width": integer,
    "height": integer,
    "rotation": integer,
    "location": {
      "latitude": double,
      "longitude": double,
      "altitude": double
    },
    "time": string,
    "cameraMake": string,
    "cameraModel": string,
    "exposureTime": float,
    "aperture": float,
    "flashUsed": boolean,
    "focalLength": float,
    "isoSpeed": integer,
    "meteringMode": string,
    "sensor": string,
    "exposureMode": string,
    "colorSpace": string,
    "whiteBalance": string,
    "exposureBias": float,
    "maxApertureValue": float,
    "subjectDistance": integer,
    "lens": string
  },
  "videoMediaMetadata": {
    "width": integer,
    "height": integer,
    "durationMillis": long
  },
  "isAppAuthorized": boolean,
  "exportLinks": {
    (key): string
  }
}
$file->is_folder

Return a boolean '1' or '0' to indicate if the current file is one folder or not. (this is using the mimeType value).

$iterm->is_folder
$file->is_file

Return a boolean '1' or '0' to indicate if the current file is a regular file (not a folder). (this is using the mimeType value).

$iterm->is_file or ! $iterm->is_folder
$file->kind

Identifies what kind of resource this is. Value: the fixed string "drive#file".

$file->id

The ID of the file.

$file->name

The name of the file. This is not necessarily unique within a folder. Note that for immutable items such as the top level folders of shared drives, My Drive root folder, and Application Data folder the name is constant.

$file->mimeType

The MIME type of the file. Google Drive will attempt to automatically detect an appropriate value from uploaded content if no value is provided. The value cannot be changed unless a new revision is uploaded.

If a file is created with a Google Doc MIME type, the uploaded content will be imported if possible. The supported import formats are published in the About resource.

$file->description

A short description of the file.

$file->starred

boolean - Whether the user has starred the file.

$file->trashed

boolean - Whether the file has been trashed, either explicitly or from a trashed parent folder. Only the owner may trash a file, and other users cannot see files in the owner's trash.

$file->explicitlyTrashed

boolean - Whether the file has been explicitly trashed, as opposed to recursively trashed from a parent folder.

$file->version

A monotonically increasing version number for the file. This reflects every change made to the file on the server, even those not visible to the user.

$file->createdTime

The time at which the file was created (RFC 3339 date-time).

$file->modifiedTime

The last time the file was modified by anyone (RFC 3339 date-time). Note that setting modifiedTime will also update modifiedByMeTime for the user.

$file->size

The size of the file's content in bytes. This is only applicable to files with binary content in Google Drive.

$file->capabilities

Capabilities the current user has on this file. Each capability corresponds to a fine-grained action that a user may take.

more...

Please refer to the official documentation

https://developers.google.com/drive/api/v3/reference/files

for more informations about the possible fields.

Tips

AUTOLOAD

The implemented AUTOLOAD function is case insensitive. The following functions $iterm-id>, $iterm-ID> and $iterm-Id> for example are all equivalent and return the 'id' for the file.

When trying to access to an unknown field, the code will die/throw an exception.

eval { $item->DoNotExist } and $@ =~ m{"Cannot find any attribute named 'DoNotExist'}

AUTHOR

2019, Nicolas R. <cpan@atoomic.org>