mobilitydata_client/apis/
licenses_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetLicenseError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetLicensesError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetMatchingLicensesError {
36 UnknownValue(serde_json::Value),
37}
38
39
40pub async fn get_license(configuration: &configuration::Configuration, id: &str) -> Result<models::LicenseWithRules, Error<GetLicenseError>> {
42 let p_path_id = id;
44
45 let uri_str = format!("{}/v1/licenses/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
46 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
47
48 if let Some(ref user_agent) = configuration.user_agent {
49 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
50 }
51 if let Some(ref token) = configuration.bearer_access_token {
52 req_builder = req_builder.bearer_auth(token.to_owned());
53 };
54
55 let req = req_builder.build()?;
56 let resp = configuration.client.execute(req).await?;
57
58 let status = resp.status();
59 let content_type = resp
60 .headers()
61 .get("content-type")
62 .and_then(|v| v.to_str().ok())
63 .unwrap_or("application/octet-stream");
64 let content_type = super::ContentType::from(content_type);
65
66 if !status.is_client_error() && !status.is_server_error() {
67 let content = resp.text().await?;
68 match content_type {
69 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
70 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LicenseWithRules`"))),
71 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::LicenseWithRules`")))),
72 }
73 } else {
74 let content = resp.text().await?;
75 let entity: Option<GetLicenseError> = serde_json::from_str(&content).ok();
76 Err(Error::ResponseError(ResponseContent { status, content, entity }))
77 }
78}
79
80pub async fn get_licenses(configuration: &configuration::Configuration, limit: Option<i32>, offset: Option<i32>) -> Result<Vec<models::LicenseBase>, Error<GetLicensesError>> {
82 let p_query_limit = limit;
84 let p_query_offset = offset;
85
86 let uri_str = format!("{}/v1/licenses", configuration.base_path);
87 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
88
89 if let Some(ref param_value) = p_query_limit {
90 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
91 }
92 if let Some(ref param_value) = p_query_offset {
93 req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
94 }
95 if let Some(ref user_agent) = configuration.user_agent {
96 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
97 }
98 if let Some(ref token) = configuration.bearer_access_token {
99 req_builder = req_builder.bearer_auth(token.to_owned());
100 };
101
102 let req = req_builder.build()?;
103 let resp = configuration.client.execute(req).await?;
104
105 let status = resp.status();
106 let content_type = resp
107 .headers()
108 .get("content-type")
109 .and_then(|v| v.to_str().ok())
110 .unwrap_or("application/octet-stream");
111 let content_type = super::ContentType::from(content_type);
112
113 if !status.is_client_error() && !status.is_server_error() {
114 let content = resp.text().await?;
115 match content_type {
116 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
117 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::LicenseBase>`"))),
118 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::LicenseBase>`")))),
119 }
120 } else {
121 let content = resp.text().await?;
122 let entity: Option<GetLicensesError> = serde_json::from_str(&content).ok();
123 Err(Error::ResponseError(ResponseContent { status, content, entity }))
124 }
125}
126
127pub async fn get_matching_licenses(configuration: &configuration::Configuration, get_matching_licenses_request: models::GetMatchingLicensesRequest) -> Result<Vec<models::MatchingLicense>, Error<GetMatchingLicensesError>> {
129 let p_body_get_matching_licenses_request = get_matching_licenses_request;
131
132 let uri_str = format!("{}/v1/licenses:match", configuration.base_path);
133 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
134
135 if let Some(ref user_agent) = configuration.user_agent {
136 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
137 }
138 if let Some(ref token) = configuration.bearer_access_token {
139 req_builder = req_builder.bearer_auth(token.to_owned());
140 };
141 req_builder = req_builder.json(&p_body_get_matching_licenses_request);
142
143 let req = req_builder.build()?;
144 let resp = configuration.client.execute(req).await?;
145
146 let status = resp.status();
147 let content_type = resp
148 .headers()
149 .get("content-type")
150 .and_then(|v| v.to_str().ok())
151 .unwrap_or("application/octet-stream");
152 let content_type = super::ContentType::from(content_type);
153
154 if !status.is_client_error() && !status.is_server_error() {
155 let content = resp.text().await?;
156 match content_type {
157 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
158 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::MatchingLicense>`"))),
159 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::MatchingLicense>`")))),
160 }
161 } else {
162 let content = resp.text().await?;
163 let entity: Option<GetMatchingLicensesError> = serde_json::from_str(&content).ok();
164 Err(Error::ResponseError(ResponseContent { status, content, entity }))
165 }
166}
167