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