Struct OneDrive

Source
pub struct OneDrive { /* private fields */ }
Expand description

The authorized client to access OneDrive resources in a specified Drive.

Implementations§

Source§

impl OneDrive

Source

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.

Source

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.

Source

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].

Source

pub fn client(&self) -> &Client

Get the reqwest::Client used to create the OneDrive instance.

Source

pub fn access_token(&self) -> &str

Get the access token used to create the OneDrive instance.

Source

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

Microsoft Docs

Source

pub async fn get_drive(&self) -> Result<Drive>

Shortcut to get_drive_with_option with default parameters.

§See also

get_drive_with_option

Source

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::DriveItems 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

Microsoft Docs

Source

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

list_children_with_option

Source

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

Microsoft Docs

Source

pub async fn get_item<'a>( &self, item: impl Into<ItemLocation<'a>>, ) -> Result<DriveItem>

Shortcut to get_item_with_option with default parameters.

§See also

get_item_with_option

Source

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

Microsoft Docs

Source

pub async fn get_item_download_url<'a>( &self, item: impl Into<ItemLocation<'a>>, ) -> Result<String>

Source

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 HTTP 409 CONFLICT if conflict_behavior is set to Fail and the target already exists.
  • Will result in Err with HTTP 400 BAD REQUEST if facets are not properly set.
§See also

Microsoft Docs

Source

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

Microsoft Docs

Source

pub async fn create_folder<'a>( &self, parent_item: impl Into<ItemLocation<'a>>, name: &FileName, ) -> Result<DriveItem>

Shortcut to create_folder_with_option with default options.

§See also

create_folder_with_option

Source

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

Microsoft Docs

Source

pub async fn update_item<'a>( &self, item: impl Into<ItemLocation<'a>>, patch: &DriveItem, ) -> Result<DriveItem>

Shortcut to update_item_with_option with default options.

§See also

update_item_with_option

Source

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

Microsoft Docs

Source

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

Microsoft Docs

Source

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.

Source

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.

Source

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

Microsoft Docs

Source

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

Microsoft Docs

Source

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>

Shortcut to move_with_option with ConflictBehavior::Fail.

§See also

move_with_option

Source

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

Microsoft Docs

Source

pub async fn delete<'a>(&self, item: impl Into<ItemLocation<'a>>) -> Result<()>

Shortcut to delete_with_option.

§See also

delete_with_option

Source

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

Microsoft Docs

Source

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

track_root_changes_from_initial_with_option

Source

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.

Source

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

Microsoft Docs

Source

pub async fn get_root_latest_delta_url(&self) -> Result<String>

Shortcut to get_root_latest_delta_url_with_option with default parameters.

§See also

get_root_latest_delta_url_with_option

Trait Implementations§

Source§

impl Clone for OneDrive

Source§

fn clone(&self) -> OneDrive

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OneDrive

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,