-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: David Graeff <[email protected]>
- Loading branch information
David Graeff
committed
Jan 22, 2020
1 parent
ebce58f
commit fe2e094
Showing
14 changed files
with
226 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use super::*; | ||
use crate::errors::extract_google_api_error_async; | ||
|
||
/// | ||
/// Deletes the document at the given path. | ||
/// | ||
/// You cannot use this directly with paths from [`list`] and [`query`] document metadata objects. | ||
/// Those contain an absolute document path. Use [`abs_to_rel`] to convert to a relative path. | ||
/// | ||
/// ## Arguments | ||
/// * 'auth' The authentication token | ||
/// * 'path' The relative collection path and document id, for example "my_collection/document_id" | ||
/// * 'fail_if_not_existing' If true this method will return an error if the document does not exist. | ||
pub fn delete(auth: &impl FirebaseAuthBearer, path: &str, fail_if_not_existing: bool) -> Result<()> { | ||
let url = firebase_url(auth.project_id(), path); | ||
|
||
let query_request = dto::Write { | ||
current_document: Some(dto::Precondition { | ||
exists: match fail_if_not_existing { | ||
true => Some(true), | ||
false => None, | ||
}, | ||
..Default::default() | ||
}), | ||
..Default::default() | ||
}; | ||
|
||
let resp = auth | ||
.client() | ||
.delete(&url) | ||
.bearer_auth(auth.access_token().to_owned()) | ||
.json(&query_request) | ||
.send()?; | ||
|
||
extract_google_api_error(resp, || path.to_owned())?; | ||
|
||
Ok({}) | ||
} | ||
|
||
//#[unstable(feature = "unstable", issue = "1234", reason = "Not yet decided if _async suffix or own module namespace")] | ||
/// | ||
/// Deletes the document at the given path. | ||
/// | ||
/// You cannot use this directly with paths from [`list`] and [`query`] document metadata objects. | ||
/// Those contain an absolute document path. Use [`abs_to_rel`] to convert to a relative path. | ||
/// | ||
/// ## Arguments | ||
/// * 'auth' The authentication token | ||
/// * 'path' The relative collection path and document id, for example "my_collection/document_id" | ||
/// * 'fail_if_not_existing' If true this method will return an error if the document does not exist. | ||
#[cfg(feature = "unstable")] | ||
pub async fn delete_async(auth: &impl FirebaseAuthBearer, path: &str, fail_if_not_existing: bool) -> Result<()> { | ||
let url = firebase_url(auth.project_id(), path); | ||
|
||
let query_request = dto::Write { | ||
current_document: Some(dto::Precondition { | ||
exists: match fail_if_not_existing { | ||
true => Some(true), | ||
false => None, | ||
}, | ||
..Default::default() | ||
}), | ||
..Default::default() | ||
}; | ||
|
||
let resp = auth | ||
.client_async() | ||
.delete(&url) | ||
.bearer_auth(auth.access_token().to_owned()) | ||
.json(&query_request) | ||
.send() | ||
.await?; | ||
|
||
extract_google_api_error_async(resp, || path.to_owned()).await?; | ||
|
||
Ok({}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.