1use std::error;
2use std::fmt;
3
4#[derive(Debug, Clone)]
5pub struct ResponseContent<T> {
6 pub status: reqwest::StatusCode,
7 pub content: String,
8 pub entity: Option<T>,
9}
10
11#[derive(Debug)]
12pub enum Error<T> {
13 Reqwest(reqwest::Error),
14 Serde(serde_json::Error),
15 Io(std::io::Error),
16 ResponseError(ResponseContent<T>),
17}
18
19impl <T> fmt::Display for Error<T> {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 let (module, e) = match self {
22 Error::Reqwest(e) => ("reqwest", e.to_string()),
23 Error::Serde(e) => ("serde", e.to_string()),
24 Error::Io(e) => ("IO", e.to_string()),
25 Error::ResponseError(e) => ("response", format!("status code {}", e.status)),
26 };
27 write!(f, "error in {}: {}", module, e)
28 }
29}
30
31impl <T: fmt::Debug> error::Error for Error<T> {
32 fn source(&self) -> Option<&(dyn error::Error + 'static)> {
33 Some(match self {
34 Error::Reqwest(e) => e,
35 Error::Serde(e) => e,
36 Error::Io(e) => e,
37 Error::ResponseError(_) => return None,
38 })
39 }
40}
41
42impl <T> From<reqwest::Error> for Error<T> {
43 fn from(e: reqwest::Error) -> Self {
44 Error::Reqwest(e)
45 }
46}
47
48impl <T> From<serde_json::Error> for Error<T> {
49 fn from(e: serde_json::Error) -> Self {
50 Error::Serde(e)
51 }
52}
53
54impl <T> From<std::io::Error> for Error<T> {
55 fn from(e: std::io::Error) -> Self {
56 Error::Io(e)
57 }
58}
59
60pub fn urlencode<T: AsRef<str>>(s: T) -> String {
61 ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect()
62}
63
64pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> {
65 if let serde_json::Value::Object(object) = value {
66 let mut params = vec![];
67
68 for (key, value) in object {
69 match value {
70 serde_json::Value::Object(_) => params.append(&mut parse_deep_object(
71 &format!("{}[{}]", prefix, key),
72 value,
73 )),
74 serde_json::Value::Array(array) => {
75 for (i, value) in array.iter().enumerate() {
76 params.append(&mut parse_deep_object(
77 &format!("{}[{}][{}]", prefix, key, i),
78 value,
79 ));
80 }
81 },
82 serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())),
83 _ => params.push((format!("{}[{}]", prefix, key), value.to_string())),
84 }
85 }
86
87 return params;
88 }
89
90 unimplemented!("Only objects are supported with style=deepObject")
91}
92
93#[allow(dead_code)]
96enum ContentType {
97 Json,
98 Text,
99 Unsupported(String)
100}
101
102impl From<&str> for ContentType {
103 fn from(content_type: &str) -> Self {
104 if content_type.starts_with("application") && content_type.contains("json") {
105 return Self::Json;
106 } else if content_type.starts_with("text/plain") {
107 return Self::Text;
108 } else {
109 return Self::Unsupported(content_type.to_string());
110 }
111 }
112}
113
114pub mod account_api;
115pub mod ad_api;
116pub mod affiliate_api;
117pub mod agents_api;
118pub mod ai_api;
119pub mod allowance_api;
120pub mod ask_api;
121pub mod audit_api;
122pub mod author_api;
123pub mod authz_api;
124pub mod auto_api;
125pub mod base_api;
126pub mod benchmark_api;
127pub mod billing_api;
128pub mod blueprint_api;
129pub mod books_api;
130pub mod bot_api;
131pub mod campaign_api;
132pub mod captable_api;
133pub mod catalog_api;
134pub mod channels_api;
135pub mod cloudflare_api;
136pub mod code_api;
137pub mod commerce_api;
138pub mod company_api;
139pub mod compliance_api;
140pub mod content_api;
141pub mod crawl_api;
142pub mod crm_api;
143pub mod dataroom_api;
144pub mod dataset_api;
145pub mod deploy_api;
146pub mod destination_api;
147pub mod dns_api;
148pub mod domain_api;
149pub mod engine_api;
150pub mod entitlement_api;
151pub mod esign_api;
152pub mod eval_api;
153pub mod event_api;
154pub mod exec_api;
155pub mod experiment_api;
156pub mod explorer_api;
157pub mod flags_api;
158pub mod flow_api;
159pub mod framework_api;
160pub mod functions_api;
161pub mod gateway_api;
162pub mod git_api;
163pub mod graph_api;
164pub mod guide_api;
165pub mod help_api;
166pub mod iam_api;
167pub mod index_api;
168pub mod ingress_api;
169pub mod integrations_api;
170pub mod kms_api;
171pub mod knowledge_api;
172pub mod kv_api;
173pub mod label_api;
174pub mod leaderboard_api;
175pub mod legal_api;
176pub mod licensing_api;
177pub mod link_api;
178pub mod lsp_api;
179pub mod marketing_api;
180pub mod marketplace_api;
181pub mod meet_api;
182pub mod metrics_api;
183pub mod ml_api;
184pub mod mq_api;
185pub mod network_api;
186pub mod node_api;
187pub mod notify_api;
188pub mod o11y_api;
189pub mod openapi_api;
190pub mod plan_api;
191pub mod platform_api;
192pub mod pref_api;
193pub mod pricing_api;
194pub mod projects_api;
195pub mod prompt_api;
196pub mod provisioning_api;
197pub mod pubsub_api;
198pub mod reference_api;
199pub mod referral_api;
200pub mod registry_api;
201pub mod risk_api;
202pub mod s3_api;
203pub mod sandbox_api;
204pub mod sbom_api;
205pub mod search_api;
206pub mod security_api;
207pub mod seo_api;
208pub mod settings_api;
209pub mod share_api;
210pub mod social_api;
211pub mod standing_api;
212pub mod sync_api;
213pub mod tasks_api;
214pub mod taxonomy_api;
215pub mod team_api;
216pub mod tel_api;
217pub mod template_api;
218pub mod todo_api;
219pub mod tools_api;
220pub mod translate_api;
221pub mod treasury_api;
222pub mod trust_api;
223pub mod usage_api;
224pub mod validator_api;
225pub mod visor_api;
226pub mod wallet_api;
227pub mod web3_api;
228pub mod webhook_api;
229pub mod websearch_api;
230pub mod world_api;
231pub mod x402_api;
232
233pub mod configuration;