PCloudClient
public final class PCloudClient
Utility class providing convenient interface to common API methods.
-
The underlying builder responsible for creating call tasks.
Declaration
Swift
public let callTaskBuilder: PCloudAPICallTaskBuilder
-
The underlying builder responsible for creating upload tasks.
Declaration
Swift
public let uploadTaskBuilder: PCloudAPIUploadTaskBuilder
-
The underlying builder responsible for creating download tasks.
Declaration
Swift
public let downloadTaskBuilder: PCloudAPIDownloadTaskBuilder
-
Initializes a new instance.
Declaration
Swift
public init(callTaskBuilder: PCloudAPICallTaskBuilder, uploadTaskBuilder: PCloudAPIUploadTaskBuilder, downloadTaskBuilder: PCloudAPIDownloadTaskBuilder)
Parameters
callTaskBuilder
Will be used to create call tasks.
uploadTaskBuilder
Will be used to create upload tasks.
downloadTaskBuilder
Will be used to create download tasks.
-
Creates and returns a task for fetching user metadata.
Return Value
A task producing a
User.Metadata
object on success. -
Creates and returns a task for fetching folder metadata along with metadata of its contents.
Declaration
Parameters
folderId
The unique identifier of the folder to fetch.
recursive
Pass
false
to fetch only the immediate children of the folder. Passtrue
to fetch the full folder tree of the folder.Return Value
A task producing a
Folder.Metadata
object on success. -
Creates and returns a task for creating a folder.
Declaration
Parameters
name
A name for the new folder.
folderId
The unique identifier of the parent folder.
Return Value
A task producing a
Folder.Metadata
object on success. -
Creates and returns a task for renaming a folder.
Declaration
Parameters
folderId
The unique identifier of the folder to rename.
newName
The new name for the folder.
Return Value
A task producing a
Folder.Metadata
object on success. -
Creates and returns a task for moving a folder.
Declaration
Parameters
folderId
The unique identifier of the folder to move.
destinationFolderId
The unique identifier of the destination folder.
Return Value
A task producing a
Folder.Metadata
object on success. -
Creates and returns a task for copying a folder.
Declaration
Parameters
folderId
The unique identifier of the folder to copy.
destinationFolderId
The unique identifier of the destination folder.
Return Value
A task producing a
Folder.Metadata
object on success. -
Creates and returns a task for uploading a file from a
Data
object.Declaration
Swift
public func upload(_ data: Data, toFolder folderId: UInt64, asFileNamed name: String, withModificationDate date: Date? = nil) -> UploadTask<PCloudAPI.UploadFile>
Parameters
data
The data to upload.
folderId
The unique identifier of the parent folder.
name
A name for the file.
date
The date to use as the modification date for the file when creating it in the file system. Passing
nil
will create the file with the current date as the modification date.Return Value
A task producing a
File.Metadata
object on success. -
Creates and returns a task for uploading a file from a local file.
Declaration
Swift
public func upload(fromFileAt path: URL, toFolder folderId: UInt64, asFileNamed name: String, withModificationDate date: Date? = nil) -> UploadTask<PCloudAPI.UploadFile>
Parameters
path
The local path of the file to upload.
folderId
The unique identifier of the parent folder.
name
A name for the file.
date
The date to use as the modification date for the file when creating it in the file system. Passing
nil
will create the file with the current date as the modification date.Return Value
A task producing a
File.Metadata
object on success. -
Creates and returns a task for creating an upload session. The upload identifier produced by this method can be used to upload a file over multiple requests.
Return Value
A task producing an upload identifier (
UInt64
value) on success. -
Creates and returns a task for fetching the current state of an upload session.
Declaration
Parameters
uploadId
An upload identifier.
Return Value
A task producing an
UploadInfo
instance on success. -
Creates and returns a task for writing the data of a local file to an upload session.
Declaration
Swift
public func upload(fromFileAt path: URL, toUpload uploadId: UInt64, atOffset offset: UInt64) -> UploadTask<PCloudAPI.WriteToUpload>
Parameters
path
The local path of the file to upload.
uploadId
An upload identifier.
offset
The upload session offset at which to start writing.
-
Creates and returns a task for writing a
Data
instance to an upload session.Declaration
Swift
public func upload(_ data: Data, toUpload uploadId: UInt64, atOffset offset: UInt64) -> UploadTask<PCloudAPI.WriteToUpload>
Parameters
data
The data to write.
uploadId
An upload identifier.
offset
The upload session offset at which to start writing.
-
Creates and returns a task for save an upload session as a file in the file system.
Declaration
Parameters
id
An identifier of the upload session to save.
parentFolderId
The identifier folder in which to save the file.
name
The file name to use when saving. Note this might change depending on the conflict resolution.
onConflict
An action to take if a file conflict occurs. Please see
PCloudAPI.SaveUpload
for more info.Return Value
A task producing a
File.Metadata
instance on success. -
Creates and returns a task for copying a file.
Declaration
Parameters
fileId
The unique identifier of the file to copy.
destinationFolderId
The unique identifier of the destination folder.
overwrite
Whether to overwrite (
true
) a file with the same name in the destination folder, or to fail (false
, the default).Return Value
A task producing a
File.Metadata
object on success. -
Creates and returns a task for renaming a file.
Declaration
Parameters
fileId
The unique identifier of the file to rename.
name
The new name for the file.
Return Value
A task producing a
File.Metadata
object on success. -
Creates and returns a task for moving a file.
Declaration
Parameters
fileId
The unique identifier of the file to move.
destinationFolderId
The unique identifier of the destination folder.
Return Value
A task producing a
File.Metadata
object on success. -
Creates and returns a task for deleting a file.
Parameters
fileId
The unique identifier of the file to delete.
Return Value
A task producing a
File.Metadata
object on success. -
Creates and returns a task for generating a link from which a file can be downloaded.
Declaration
Parameters
fileId
The unique identifier of the file.
Return Value
A task producing an
Array<FileLink.Metadata>
object on success. -
Creates and returns a task for generating a link from which a thumbnail for a file can be downloaded. Only files with
hasThumbnail
set totrue
can have thumbnail links generated.Declaration
Parameters
fileId
The unique identifier of the file.
thumbnailSize
The required size of the thumbnail. The width must be between 16 and 2048. The height must be between 16 and 1024. And both width and height must be divisible by either 4 or 5
forceExactThumbnailSize
Whether to enforce
thumbnailSize
(true
) by potentially cropping parts of the image, or to allow width or height (but not both) to be smaller than the requested size. Aspect ratio is always preserved.Return Value
A task producing an
Array<FileLink.Metadata>
object on success. -
Creates and returns a task for generating thumbnail links for multiple files. Logically equivalent to calling
getThumbnailLink()
for multiple files. Only files withhasThumbnail
set totrue
can have thumbnail links generated.Declaration
Parameters
fileIds
A set of unique file identifiers to generate thumbnail links for.
thumbnailSize
The required size of the thumbnail. The width must be between 16 and 2048. The height must be between 16 and 1024. And both width and height must be divisible by either 4 or 5
forceExactThumbnailSize
Whether to enforce
thumbnailSize
(true
) by potentially cropping parts of the images, or to allow width or height (but not both) to be smaller than the requested size. Aspect ratio is always preserved.Return Value
A task producing a
Dictionary<UInt64, Result<Array<FileLink.Metadata>, Error>>
object on success. The keys in the dictionary are the file identifiers passed as input to this method. Each file identifier is mapped against the result of aquiring a thumbnail link for that file. -
Creates and returns a task for downloading a file from a
URL
.Declaration
Swift
public func downloadFile(from address: URL, downloadTag: String? = nil, to destination: @escaping (URL) throws -> URL) -> DownloadTask
Parameters
address
The resource address.
downloadTag
To be passed alongside
FileLink.Metadata
resource addresses. Authenticates this client to the storage servers.destination
A block called with the temporary location of the downloaded file on disk. The block must either move or open the file for reading before it returns, otherwise the file gets deleted. The block should return the new location of the file.
Return Value
A task producing a
URL
on success which is the local path of the downloaded file.