Skip to content

Commit a05c11f

Browse files
authored
Merge pull request #14 from sematext/feature-apptypes-appdelete
Added App deletion methods.
2 parents 5db6593 + e15d49a commit a05c11f

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "stcloud"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
authors = ["Sematext Inc"]
55
description = "Client package for talking to Sematext Cloud."
66
readme = "README.md"

src/apis/apps_api.rs

+67-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ impl<C: hyper::client::Connect> AppsApiClient<C> {
3737
}
3838

3939
pub trait AppsApi {
40+
fn delete_using_delete(&self, any_state_app_id: i64) -> Box<Future<Item = ::models::GenericApiResponse, Error = Error<serde_json::Value>>>;
4041
fn get_app_types_using_get(&self, ) -> Box<dyn Future<Item = ::models::GenericApiResponse, Error = Error<serde_json::Value>>>;
4142
fn get_using_get(&self, any_state_app_id: i64) -> Box<dyn Future<Item = ::models::GenericApiResponse, Error = Error<serde_json::Value>>>;
4243
fn invite_app_guests_using_post(&self, invitation: ::models::Invitation) -> Box<dyn Future<Item = ::models::GenericApiResponse, Error = Error<serde_json::Value>>>;
@@ -46,8 +47,73 @@ pub trait AppsApi {
4647
fn update_using_put1(&self, dto: ::models::UpdateAppInfo, any_state_app_id: i64) -> Box<dyn Future<Item = ::models::GenericApiResponse, Error = Error<serde_json::Value>>>;
4748
}
4849

49-
5050
impl<C: hyper::client::Connect>AppsApi for AppsApiClient<C> {
51+
fn delete_using_delete(&self, any_state_app_id: i64) -> Box<Future<Item = ::models::GenericApiResponse, Error = Error<serde_json::Value>>> {
52+
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
53+
54+
let mut auth_headers = HashMap::<String, String>::new();
55+
let mut auth_query = HashMap::<String, String>::new();
56+
if let Some(ref apikey) = configuration.api_key {
57+
let key = apikey.key.clone();
58+
let val = match apikey.prefix {
59+
Some(ref prefix) => format!("{} {}", prefix, key),
60+
None => key,
61+
};
62+
auth_headers.insert("Authorization".to_owned(), val);
63+
};
64+
let method = hyper::Method::Delete;
65+
66+
let query_string = {
67+
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
68+
for (key, val) in &auth_query {
69+
query.append_pair(key, val);
70+
}
71+
query.finish()
72+
};
73+
let uri_str = format!("{}/users-web/api/v3/apps/{anyStateAppId}?{}", configuration.base_path, query_string, anyStateAppId=any_state_app_id);
74+
75+
// TODO(farcaller): handle error
76+
// if let Err(e) = uri {
77+
// return Box::new(futures::future::err(e));
78+
// }
79+
let mut uri: hyper::Uri = uri_str.parse().unwrap();
80+
81+
let mut req = hyper::Request::new(method, uri);
82+
83+
if let Some(ref user_agent) = configuration.user_agent {
84+
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
85+
}
86+
87+
88+
for (key, val) in auth_headers {
89+
req.headers_mut().set_raw(key, val);
90+
}
91+
92+
93+
// send request
94+
Box::new(
95+
configuration.client.request(req)
96+
.map_err(|e| Error::from(e))
97+
.and_then(|resp| {
98+
let status = resp.status();
99+
resp.body().concat2()
100+
.and_then(move |body| Ok((status, body)))
101+
.map_err(|e| Error::from(e))
102+
})
103+
.and_then(|(status, body)| {
104+
if status.is_success() {
105+
Ok(body)
106+
} else {
107+
Err(Error::from((status, &*body)))
108+
}
109+
})
110+
.and_then(|body| {
111+
let parsed: Result<::models::GenericApiResponse, _> = serde_json::from_slice(&body);
112+
parsed.map_err(|e| Error::from(e))
113+
})
114+
)
115+
}
116+
51117
fn get_app_types_using_get(&self, ) -> Box<dyn Future<Item = ::models::GenericApiResponse, Error = Error<serde_json::Value>>> {
52118
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
53119

0 commit comments

Comments
 (0)