pub struct OneDrive { /* private fields */ }
Expand description
The authorized client to access OneDrive resources in a specified Drive.
Implementations§
Source§impl OneDrive
impl OneDrive
Sourcepub const UPLOAD_SMALL_MAX_SIZE: usize = 4_000_000usize
pub const UPLOAD_SMALL_MAX_SIZE: usize = 4_000_000usize
The upload size limit of upload_small
.
The value is from OneDrive Developer documentation (4MB) which is smaller than Microsoft Graph documentation (250MB). The exact limit is unknown. Here we chose the smaller one as a reference.
Sourcepub fn new(
access_token: impl Into<String>,
drive: impl Into<DriveLocation>,
) -> Self
pub fn new( access_token: impl Into<String>, drive: impl Into<DriveLocation>, ) -> Self
Create a new OneDrive instance with access token given to perform operations in a Drive.
§Panics
It panics if the underlying reqwest::Client
cannot be created.
Sourcepub fn new_with_client(
client: Client,
access_token: impl Into<String>,
drive: impl Into<DriveLocation>,
) -> Self
pub fn new_with_client( client: Client, access_token: impl Into<String>, drive: impl Into<DriveLocation>, ) -> Self
Same as OneDrive::new
but with custom reqwest::Client
.
§Note
The given client
should have redirection disabled to
make get_item_download_url[_with_option]
work properly.
See also the docs of get_item_download_url[_with_option]
.
Sourcepub fn access_token(&self) -> &str
pub fn access_token(&self) -> &str
Get the access token used to create the OneDrive instance.
Sourcepub async fn get_drive_with_option(
&self,
option: ObjectOption<DriveField>,
) -> Result<Drive>
pub async fn get_drive_with_option( &self, option: ObjectOption<DriveField>, ) -> Result<Drive>
Get current Drive
.
Retrieve the properties and relationships of a resource::Drive
resource.
§See also
Sourcepub async fn list_children_with_option<'a>(
&self,
item: impl Into<ItemLocation<'a>>,
option: CollectionOption<DriveItemField>,
) -> Result<Option<ListChildrenFetcher>>
pub async fn list_children_with_option<'a>( &self, item: impl Into<ItemLocation<'a>>, option: CollectionOption<DriveItemField>, ) -> Result<Option<ListChildrenFetcher>>
List children of a DriveItem
.
Retrieve a collection of resource::DriveItem
s in the children relationship
of the given one.
§Response
If successful, respond a fetcher for fetching changes from initial state (empty) to the snapshot of
current states. See ListChildrenFetcher
for more details.
If if_none_match
is set and it matches the item tag, return an None
.
§See also
Sourcepub async fn list_children<'a>(
&self,
item: impl Into<ItemLocation<'a>>,
) -> Result<Vec<DriveItem>>
pub async fn list_children<'a>( &self, item: impl Into<ItemLocation<'a>>, ) -> Result<Vec<DriveItem>>
Shortcut to list_children_with_option
with default params,
and fetch and collect all children.
§See also
Sourcepub async fn get_item_with_option<'a>(
&self,
item: impl Into<ItemLocation<'a>>,
option: ObjectOption<DriveItemField>,
) -> Result<Option<DriveItem>>
pub async fn get_item_with_option<'a>( &self, item: impl Into<ItemLocation<'a>>, option: ObjectOption<DriveItemField>, ) -> Result<Option<DriveItem>>
Get a DriveItem
resource.
Retrieve the metadata for a resource::DriveItem
by file system path or ID.
§Errors
Will return Ok(None)
if if_none_match
is set and it matches the item tag.
§See also
Sourcepub async fn get_item_download_url_with_option<'a>(
&self,
item: impl Into<ItemLocation<'a>>,
option: ObjectOption<DriveItemField>,
) -> Result<String>
pub async fn get_item_download_url_with_option<'a>( &self, item: impl Into<ItemLocation<'a>>, option: ObjectOption<DriveItemField>, ) -> Result<String>
Get a pre-authorized download URL for a file.
The URL returned is only valid for a short period of time (a few minutes).
§Note
This API only works with reqwest redirection disabled, which is the default option set by
OneDrive::new()
.
If the OneDrive
instance is created by new_with_client()
,
be sure the reqwest::Client
has redirection disabled.
Only If-None-Match
is supported in option
.
§See also
Sourcepub async fn get_item_download_url<'a>(
&self,
item: impl Into<ItemLocation<'a>>,
) -> Result<String>
pub async fn get_item_download_url<'a>( &self, item: impl Into<ItemLocation<'a>>, ) -> Result<String>
Shortcut to get_item_download_url_with_option
with default options.
§See also
Sourcepub async fn create_drive_item<'a>(
&self,
parent_item: impl Into<ItemLocation<'a>>,
drive_item: DriveItem,
option: DriveItemPutOption,
) -> Result<DriveItem>
pub async fn create_drive_item<'a>( &self, parent_item: impl Into<ItemLocation<'a>>, drive_item: DriveItem, option: DriveItemPutOption, ) -> Result<DriveItem>
Create a new DriveItem
allowing to set supported attributes.
DriveItem
resources have facets modeled as properties that provide data
about the DriveItem
’s identities and capabilities. You must provide one
of the following facets to create an item: bundle
, file
, folder
, remote_item
.
§Errors
- Will result in
Err
with HTTP409 CONFLICT
ifconflict_behavior
is set toFail
and the target already exists. - Will result in
Err
with HTTP400 BAD REQUEST
if facets are not properly set.
§See also
Sourcepub async fn create_folder_with_option<'a>(
&self,
parent_item: impl Into<ItemLocation<'a>>,
name: &FileName,
option: DriveItemPutOption,
) -> Result<DriveItem>
pub async fn create_folder_with_option<'a>( &self, parent_item: impl Into<ItemLocation<'a>>, name: &FileName, option: DriveItemPutOption, ) -> Result<DriveItem>
Create a new folder under an DriveItem
Create a new folder DriveItem
with a specified parent item or path.
§Errors
Will result in Err
with HTTP 409 CONFLICT
if conflict_behavior
is set to Fail
and the target already exists.
§See also
Sourcepub async fn create_folder<'a>(
&self,
parent_item: impl Into<ItemLocation<'a>>,
name: &FileName,
) -> Result<DriveItem>
pub async fn create_folder<'a>( &self, parent_item: impl Into<ItemLocation<'a>>, name: &FileName, ) -> Result<DriveItem>
Sourcepub async fn update_item_with_option<'a>(
&self,
item: impl Into<ItemLocation<'a>>,
patch: &DriveItem,
option: ObjectOption<DriveItemField>,
) -> Result<DriveItem>
pub async fn update_item_with_option<'a>( &self, item: impl Into<ItemLocation<'a>>, patch: &DriveItem, option: ObjectOption<DriveItemField>, ) -> Result<DriveItem>
Update DriveItem
properties
Update the metadata for a DriveItem
.
If you want to rename or move an DriveItem
to another place,
you should use move_
(or move_with_option
) instead of this, which is a wrapper
to this API endpoint to make things easier.
§See also
Sourcepub async fn update_item<'a>(
&self,
item: impl Into<ItemLocation<'a>>,
patch: &DriveItem,
) -> Result<DriveItem>
pub async fn update_item<'a>( &self, item: impl Into<ItemLocation<'a>>, patch: &DriveItem, ) -> Result<DriveItem>
Sourcepub async fn upload_small<'a>(
&self,
item: impl Into<ItemLocation<'a>>,
data: impl Into<Bytes>,
) -> Result<DriveItem>
pub async fn upload_small<'a>( &self, item: impl Into<ItemLocation<'a>>, data: impl Into<Bytes>, ) -> Result<DriveItem>
Upload or replace the contents of a DriveItem
file.
The simple upload API allows you to provide the contents of a new file or
update the contents of an existing file in a single API call. This method
only supports files up to Self::UPLOAD_SMALL_MAX_SIZE
. The length is not checked
locally and request will still be sent for large data.
§See also
Sourcepub async fn new_upload_session_with_initial_option<'a>(
&self,
item: impl Into<ItemLocation<'a>>,
initial: &DriveItem,
option: DriveItemPutOption,
) -> Result<(UploadSession, UploadSessionMeta)>
pub async fn new_upload_session_with_initial_option<'a>( &self, item: impl Into<ItemLocation<'a>>, initial: &DriveItem, option: DriveItemPutOption, ) -> Result<(UploadSession, UploadSessionMeta)>
Create an upload session.
Create an upload session to allow your app to upload files up to the maximum file size. An upload session allows your app to upload ranges of the file in sequential API requests, which allows the transfer to be resumed if a connection is dropped while the upload is in progress.
§Errors
Will return Err
with HTTP 412 PRECONDITION_FAILED
if if_match
is set
but does not match the item.
§Note
conflict_behavior
is supported.
§See also
Sourcepub async fn new_upload_session_with_option<'a>(
&self,
item: impl Into<ItemLocation<'a>>,
option: DriveItemPutOption,
) -> Result<(UploadSession, UploadSessionMeta)>
pub async fn new_upload_session_with_option<'a>( &self, item: impl Into<ItemLocation<'a>>, option: DriveItemPutOption, ) -> Result<(UploadSession, UploadSessionMeta)>
Shortcut to new_upload_session_with_initial_option
without initial attributes.
Sourcepub async fn new_upload_session<'a>(
&self,
item: impl Into<ItemLocation<'a>>,
) -> Result<(UploadSession, UploadSessionMeta)>
pub async fn new_upload_session<'a>( &self, item: impl Into<ItemLocation<'a>>, ) -> Result<(UploadSession, UploadSessionMeta)>
Shortcut to new_upload_session_with_option
with ConflictBehavior::Fail
.
Sourcepub async fn copy<'a, 'b>(
&self,
source_item: impl Into<ItemLocation<'a>>,
dest_folder: impl Into<ItemLocation<'b>>,
dest_name: &FileName,
) -> Result<CopyProgressMonitor>
pub async fn copy<'a, 'b>( &self, source_item: impl Into<ItemLocation<'a>>, dest_folder: impl Into<ItemLocation<'b>>, dest_name: &FileName, ) -> Result<CopyProgressMonitor>
Copy a DriveItem
.
Asynchronously creates a copy of an driveItem (including any children), under a new parent item or with a new name.
§Note
The conflict behavior is not mentioned in Microsoft Docs, and cannot be specified.
But it seems to behave as Rename
if the destination folder is just the current
parent folder, and Fail
otherwise.
§See also
Sourcepub async fn move_with_option<'a, 'b>(
&self,
source_item: impl Into<ItemLocation<'a>>,
dest_folder: impl Into<ItemLocation<'b>>,
dest_name: Option<&FileName>,
option: DriveItemPutOption,
) -> Result<DriveItem>
pub async fn move_with_option<'a, 'b>( &self, source_item: impl Into<ItemLocation<'a>>, dest_folder: impl Into<ItemLocation<'b>>, dest_name: Option<&FileName>, option: DriveItemPutOption, ) -> Result<DriveItem>
Move a DriveItem
to a new folder.
This is a special case of the Update method. Your app can combine moving an item to a new container and updating other properties of the item into a single request.
Note: Items cannot be moved between Drives using this request.
§Note
conflict_behavior
is supported.
§Errors
Will return Err
with HTTP 412 PRECONDITION_FAILED
if if_match
is set
but it does not match the item.
§See also
Sourcepub async fn move_<'a, 'b>(
&self,
source_item: impl Into<ItemLocation<'a>>,
dest_folder: impl Into<ItemLocation<'b>>,
dest_name: Option<&FileName>,
) -> Result<DriveItem>
pub async fn move_<'a, 'b>( &self, source_item: impl Into<ItemLocation<'a>>, dest_folder: impl Into<ItemLocation<'b>>, dest_name: Option<&FileName>, ) -> Result<DriveItem>
Sourcepub async fn delete_with_option<'a>(
&self,
item: impl Into<ItemLocation<'a>>,
option: DriveItemPutOption,
) -> Result<()>
pub async fn delete_with_option<'a>( &self, item: impl Into<ItemLocation<'a>>, option: DriveItemPutOption, ) -> Result<()>
Delete a DriveItem
.
Delete a DriveItem
by using its ID or path. Note that deleting items using
this method will move the items to the recycle bin instead of permanently
deleting the item.
§Error
Will result in error with HTTP 412 PRECONDITION_FAILED
if if_match
is set but
does not match the item.
§Panics
conflict_behavior
is NOT supported. Set it will cause a panic.
§See also
Sourcepub async fn track_root_changes_from_initial_with_option(
&self,
option: CollectionOption<DriveItemField>,
) -> Result<TrackChangeFetcher>
pub async fn track_root_changes_from_initial_with_option( &self, option: CollectionOption<DriveItemField>, ) -> Result<TrackChangeFetcher>
Track changes for root folder from initial state (empty state) to snapshot of current states.
This method allows your app to track changes to a drive and its children over time. Deleted items are returned with the deleted facet. Items with this property set should be removed from your local state.
Note: you should only delete a folder locally if it is empty after syncing all the changes.
§Panics
Track Changes API does not support $count=true
query parameter.
If CollectionOption::get_count
is set in option, it will panic.
§Results
Return a fetcher for fetching changes from initial state (empty) to the snapshot of
current states. See TrackChangeFetcher
for more details.
§See also
Sourcepub async fn track_root_changes_from_initial(
&self,
) -> Result<TrackChangeFetcher>
pub async fn track_root_changes_from_initial( &self, ) -> Result<TrackChangeFetcher>
Shortcut to track_root_changes_from_initial_with_option
with default parameters.
§See also
Sourcepub async fn track_root_changes_from_delta_url(
&self,
delta_url: &str,
) -> Result<TrackChangeFetcher>
pub async fn track_root_changes_from_delta_url( &self, delta_url: &str, ) -> Result<TrackChangeFetcher>
Track changes for root folder from snapshot (delta url) to snapshot of current states.
§Note
There is no with_option
version of this function. Since delta URL already carries
query parameters when you get it. The initial parameters will be automatically used
in all following requests through delta URL.
Sourcepub async fn get_root_latest_delta_url_with_option(
&self,
option: CollectionOption<DriveItemField>,
) -> Result<String>
pub async fn get_root_latest_delta_url_with_option( &self, option: CollectionOption<DriveItemField>, ) -> Result<String>
Get a delta url representing the snapshot of current states of root folder.
The delta url can be used in track_root_changes_from_delta_url
later
to get diffs between two snapshots of states.
Note that options (query parameters) are saved in delta url, so they are applied to all later
requests by track_changes_from_delta_url
without need for specifying them every time.
§Panics
Track Changes API does not support $count=true
query parameter.
If CollectionOption::get_count
is set in option, it will panic.
§See also
Sourcepub async fn get_root_latest_delta_url(&self) -> Result<String>
pub async fn get_root_latest_delta_url(&self) -> Result<String>
Shortcut to get_root_latest_delta_url_with_option
with default parameters.