1#![doc = include_str!("../README.md")]
2
3use std::fmt::Write;
4use std::time::Duration;
5
6mod error;
7mod http;
8pub mod models;
9pub mod partner;
10pub mod public;
11pub mod wasapi;
12
13pub use error::Error;
14
15pub use http_ferry;
19pub use http_ferry::DownloadLocation;
20
21pub type DownloadOutcome<L = std::path::PathBuf> =
26 http_ferry::Outcome<crate::models::wasapi::WasapiFile, L>;
27
28pub use partner::PartnerClient;
29pub use public::PublicClient;
30pub use wasapi::{WasapiClient, WebdataQuery};
31
32pub mod s3 {
40 pub use http_ferry::s3::S3Location;
41}
42
43pub const USER_AGENT: &str = concat!("Archive-It-Client (", env!("CARGO_PKG_VERSION"), ")");
44
45pub fn sha1_hex(bytes: impl AsRef<[u8]>) -> String {
46 let bytes = bytes.as_ref();
47 let mut hex = String::with_capacity(bytes.len() * 2);
48 for b in bytes {
49 write!(&mut hex, "{b:02x}").expect("writing to String cannot fail");
50 }
51 hex
52}
53
54#[derive(Debug, Default, Clone, Copy, serde::Serialize)]
55pub struct PageOpts {
56 #[serde(skip_serializing_if = "Option::is_none")]
57 pub limit: Option<u32>,
58 #[serde(skip_serializing_if = "Option::is_none")]
59 pub offset: Option<u32>,
60}
61
62#[derive(Debug, Clone)]
63pub struct Config {
64 pub base_url: String,
65 pub timeout: Duration,
66 pub download_timeout: Duration,
67 pub max_attempts: u32,
68 pub backoff: Duration,
69}
70
71impl Config {
72 pub fn api() -> Self {
73 Self {
74 base_url: "https://partner.archive-it.org/api/".into(),
75 timeout: Duration::from_secs(30),
76 download_timeout: Duration::from_secs(30),
77 max_attempts: 3,
78 backoff: Duration::from_millis(250),
79 }
80 }
81
82 pub fn wasapi() -> Self {
83 Self {
84 base_url: "https://partner.archive-it.org/wasapi/v1/".into(),
85 timeout: Duration::from_secs(60),
86 download_timeout: Duration::from_secs(300),
87 ..Self::api()
88 }
89 }
90}