Expand description
§archiveis - Rust API Wrapper for Archive.is
This crate provides simple access to the Archive.is Capturing Service.
§Quick Start
§Archive a url
The ArchiveClient
is build with hyper
and uses futures for capturing archive.is links.
let client = ArchiveClient::default();
let archived = client.capture("http://example.com/").await?;
println!("targeted url: {}", archived.target_url);
println!("url of archived site: {}", archived.archived_url);
println!("archive.is submit token: {}", archived.submit_token);
§Archive multiple urls
archive.is uses a temporary token to validate a archive request.
The ArchiveClient
capture
function first obtains a new submit token via a GET request.
The token is usually valid several minutes, and even if archive.is switched to a new in the
meantime token,the older ones are still valid. So if we need to archive multiple links,
we can only need to obtain the token once and then invoke the capturing service directly with
capture_with_token
for each url. capture_all
returns a Vec of Results of every capturing
request, so every single capture request gets executed regardless of the success of prior requests.
let client = ArchiveClient::default();
// the urls to capture
let urls = vec![
"http://example.com/",
"https://github.com/MattsSe/archiveis-rs",
"https://crates.io",
];
let (archived, failures) : (Vec<_>, Vec<_>) = client.capture_all(urls).await?.into_iter()
.partition(Result::is_ok);
let archived: Vec<_> = archived.into_iter().map(Result::unwrap).collect();
let failures: Vec<_> = failures.into_iter().map(Result::unwrap_err).collect();
if failures.is_empty() {
println!("all links successfully archived.");
} else {
for err in &failures {
if let archiveis::Error::MissingUrl(url) | archiveis::Error::ServerError(url) = err {
println!("Failed to archive url: {}", url);
}
}
}
Structs§
- Archive
Client - A Client that serves as a wrapper around the archive.is capture service
- Archived
- Represents a result of the capture service
Enums§
- Error
- The Error Type used in this crate
Type Aliases§
- Result
- Result type for this crate