use reqwest::Method;
use super::types::{
CreateFeedbackRequest, DynamicResponse, FeedbackCommentRequest, FeedbackVoteRequest,
IngestFeedbackRequest,
};
use crate::{enc, Error, HttpClient, QueryParam};
pub struct FeedbackApi<'a> {
http: &'a HttpClient,
}
impl<'a> FeedbackApi<'a> {
pub fn new(http: &'a HttpClient) -> Self {
Self { http }
}
pub async fn create_feedback(
&self,
request: &CreateFeedbackRequest,
) -> Result<DynamicResponse, Error> {
let body = serde_json::to_value(request).expect("feedback request is serializable");
self.http
.send_typed(Method::POST, "/feedback", &[], Some(&body), true)
.await
}
pub async fn ingest_feedback(
&self,
request: &IngestFeedbackRequest,
) -> Result<DynamicResponse, Error> {
let body = serde_json::to_value(request).expect("feedback ingest request is serializable");
self.http
.send_typed(Method::POST, "/feedback/ingest", &[], Some(&body), true)
.await
}
pub async fn list_feedback(&self, query: &[QueryParam]) -> Result<DynamicResponse, Error> {
self.http
.send_typed(Method::GET, "/feedback", query, None, true)
.await
}
pub async fn get_feedback(&self, id: &str) -> Result<DynamicResponse, Error> {
let path = format!("/feedback/{}", enc(id));
self.http
.send_typed(Method::GET, &path, &[], None, true)
.await
}
pub async fn comment_feedback(
&self,
id: &str,
request: &FeedbackCommentRequest,
) -> Result<DynamicResponse, Error> {
let body = serde_json::to_value(request).expect("feedback comment is serializable");
let path = format!("/feedback/{}/comments", enc(id));
self.http
.send_typed(Method::POST, &path, &[], Some(&body), true)
.await
}
pub async fn vote_feedback(
&self,
id: &str,
request: &FeedbackVoteRequest,
) -> Result<DynamicResponse, Error> {
let body = serde_json::to_value(request).expect("feedback vote is serializable");
let path = format!("/feedback/{}/vote", enc(id));
self.http
.send_typed(Method::POST, &path, &[], Some(&body), true)
.await
}
}