Skip to main content

ipatool_kit/
client.rs

1//! App Store client trait and shared types.
2
3use serde::{Deserialize, Serialize};
4
5use crate::error::Result;
6
7pub use crate::helpers::{App, SearchResult};
8
9#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
10pub struct AuthInfo {
11    #[serde(default)]
12    pub email: String,
13    #[serde(default)]
14    pub name: String,
15    #[serde(default)]
16    pub storefront: String,
17    #[serde(default)]
18    pub success: bool,
19}
20
21#[derive(Clone, Default)]
22pub struct LoginRequest {
23    pub email: String,
24    pub password: String,
25    pub auth_code: Option<String>,
26    pub keychain_passphrase: Option<String>,
27}
28
29impl std::fmt::Debug for LoginRequest {
30    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31        f.debug_struct("LoginRequest")
32            .field("email", &self.email)
33            .field("password", &"***")
34            .field("auth_code", &self.auth_code.as_ref().map(|_| "***"))
35            .field(
36                "keychain_passphrase",
37                &self.keychain_passphrase.as_ref().map(|_| "***"),
38            )
39            .finish()
40    }
41}
42
43#[derive(Clone, Default)]
44pub struct DownloadRequest {
45    pub app_id: Option<i64>,
46    pub bundle_id: Option<String>,
47    pub output: Option<String>,
48    pub external_version_id: Option<String>,
49    pub purchase: bool,
50    pub keychain_passphrase: Option<String>,
51}
52
53impl std::fmt::Debug for DownloadRequest {
54    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55        f.debug_struct("DownloadRequest")
56            .field("app_id", &self.app_id)
57            .field("bundle_id", &self.bundle_id)
58            .field("output", &self.output)
59            .field("external_version_id", &self.external_version_id)
60            .field("purchase", &self.purchase)
61            .field(
62                "keychain_passphrase",
63                &self.keychain_passphrase.as_ref().map(|_| "***"),
64            )
65            .finish()
66    }
67}
68
69#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
70pub struct VersionInfo {
71    #[serde(default)]
72    pub external_id: String,
73    #[serde(default)]
74    pub display_version: String,
75    #[serde(default)]
76    pub release_date: String,
77}
78
79/// Abstraction over App Store operations.
80pub trait AppStoreClient {
81    fn login(&self, req: &LoginRequest) -> Result<AuthInfo>;
82    fn auth_info(&self, keychain_passphrase: Option<&str>) -> Result<AuthInfo>;
83    fn revoke(&self) -> Result<()>;
84    fn search(
85        &self,
86        term: &str,
87        limit: u32,
88        keychain_passphrase: Option<&str>,
89    ) -> Result<SearchResult>;
90    fn purchase(
91        &self,
92        app_id: Option<i64>,
93        bundle_id: Option<&str>,
94        keychain_passphrase: Option<&str>,
95    ) -> Result<()>;
96    fn download(&self, req: &DownloadRequest) -> Result<String>;
97    fn list_versions(
98        &self,
99        app_id: Option<i64>,
100        bundle_id: Option<&str>,
101        keychain_passphrase: Option<&str>,
102    ) -> Result<Vec<String>>;
103    fn get_version_metadata(
104        &self,
105        app_id: Option<i64>,
106        bundle_id: Option<&str>,
107        external_version_id: &str,
108        keychain_passphrase: Option<&str>,
109    ) -> Result<VersionInfo>;
110    fn list_purchases(&self, keychain_passphrase: Option<&str>) -> Result<Vec<crate::OwnedApp>>;
111}