Bugfix due to bad deduplication
All checks were successful
Run Tests on Code / run-tests (push) Successful in 13s
All checks were successful
Run Tests on Code / run-tests (push) Successful in 13s
This commit is contained in:
parent
34b3bb45c5
commit
45bfca8cc5
1 changed files with 11 additions and 23 deletions
34
src/lemmy.rs
34
src/lemmy.rs
|
@ -89,24 +89,15 @@ pub(crate) async fn login(config: &Config) -> Result<Lemmy, ()> {
|
|||
|
||||
impl Lemmy {
|
||||
pub(crate) async fn post(&self, post: CreatePost) -> Result<PostId, ()> {
|
||||
let response = self.fetch_data_json("/api/v3/post", &post).await?;
|
||||
|
||||
let response: String = self.post_data_json("/api/v3/post", &post).await?;
|
||||
let json_data: PostView = self.parse_json(&response).await?;
|
||||
|
||||
Ok(json_data.post.id)
|
||||
}
|
||||
|
||||
async fn feature(&self, params: FeaturePost) -> Result<PostView, ()> {
|
||||
let response = self.fetch_data_json("/api/v3/post/feature", ¶ms).await?;
|
||||
|
||||
let json_data = match serde_json::from_str::<HashMap<&str, PostView>>(&response) {
|
||||
Ok(mut data) => data.remove("post_view").expect("Element should be present"),
|
||||
Err(e) => {
|
||||
let err_msg = format!("{e}");
|
||||
error!(err_msg);
|
||||
return Err(());
|
||||
}
|
||||
};
|
||||
let response: String = self.post_data_json("/api/v3/post/feature", ¶ms).await?;
|
||||
let json_data: PostView = self.parse_json(&response).await?;
|
||||
|
||||
Ok(json_data)
|
||||
}
|
||||
|
@ -136,8 +127,7 @@ impl Lemmy {
|
|||
..Default::default()
|
||||
};
|
||||
|
||||
let response = self.fetch_data_query("/api/v3/post/list", &list_params).await?;
|
||||
|
||||
let response: String = self.get_data_query("/api/v3/post/list", &list_params).await?;
|
||||
let json_data: GetPostsResponse = self.parse_json(&response).await?;
|
||||
|
||||
Ok(json_data
|
||||
|
@ -154,8 +144,7 @@ impl Lemmy {
|
|||
..Default::default()
|
||||
};
|
||||
|
||||
let response = self.fetch_data_query("/api/v3/post/list", &list_params).await?;
|
||||
|
||||
let response: String = self.get_data_query("/api/v3/post/list", &list_params).await?;
|
||||
let json_data: GetPostsResponse = self.parse_json(&response).await?;
|
||||
|
||||
Ok(json_data
|
||||
|
@ -172,8 +161,7 @@ impl Lemmy {
|
|||
..Default::default()
|
||||
};
|
||||
|
||||
let response = self.fetch_data_query("/api/v3/community/list", &list_params).await?;
|
||||
|
||||
let response: String = self.get_data_query("/api/v3/community/list", &list_params).await?;
|
||||
let json_data: ListCommunitiesResponse = self.parse_json(&response).await?;
|
||||
|
||||
let mut communities: HashMap<String, CommunityId> = HashMap::new();
|
||||
|
@ -185,9 +173,9 @@ impl Lemmy {
|
|||
Ok(communities)
|
||||
}
|
||||
|
||||
async fn fetch_data_json<T: Serialize>(&self, route: &str, json: &T ) -> Result<String,()> {
|
||||
async fn post_data_json<T: Serialize>(&self, route: &str, json: &T ) -> Result<String,()> {
|
||||
let res = HTTP_CLIENT
|
||||
.post(format!("{}{route}", self.instance))
|
||||
.post(format!("{}{route}", &self.instance))
|
||||
.bearer_auth(&self.jwt_token.to_string())
|
||||
.json(&json)
|
||||
.send()
|
||||
|
@ -195,11 +183,11 @@ impl Lemmy {
|
|||
self.extract_data(res).await
|
||||
}
|
||||
|
||||
async fn fetch_data_query<T: Serialize>(&self, route: &str, json: &T ) -> Result<String,()> {
|
||||
async fn get_data_query<T: Serialize>(&self, route: &str, param: &T ) -> Result<String,()> {
|
||||
let res = HTTP_CLIENT
|
||||
.post(format!("{}{route}", self.instance))
|
||||
.get(format!("{}{route}", &self.instance))
|
||||
.bearer_auth(&self.jwt_token.to_string())
|
||||
.query(&json)
|
||||
.query(¶m)
|
||||
.send()
|
||||
.await;
|
||||
self.extract_data(res).await
|
||||
|
|
Loading…
Reference in a new issue