use crate::http::{HttpClient, Method, Request, RequestParts, encode_path};
use crate::pagination::Paginator;
use crate::types;
#[derive(Clone, Debug)]
pub struct StoriesResource {
http: HttpClient,
}
impl StoriesResource {
pub(crate) fn new(http: HttpClient) -> Self {
Self { http }
}
pub fn create(
&self,
account_id: &str,
params: impl Into<types::StoriesCreateParams>,
) -> Request<types::Message> {
let params = params.into();
let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/stories", encode_path(account_id)))
.body(¶ms)
.keyed();
self.http.request(parts)
}
pub fn list(
&self,
account_id: &str,
params: types::StoriesListParams,
) -> Paginator<types::StoryGroupList> {
let parts = RequestParts::new(Method::Get, format!("/v1/accounts/{}/stories", encode_path(account_id)))
.query_opt("contactId", params.contact_id.as_ref())
.query_opt("unviewed", params.unviewed.as_ref())
.query_opt("limit", params.limit.as_ref())
.retryable();
Paginator::new(self.http.clone(), parts, "cursor", params.cursor)
}
pub fn list_own(
&self,
account_id: &str,
params: types::StoriesListOwnParams,
) -> Paginator<types::StoryList> {
let parts = RequestParts::new(Method::Get, format!("/v1/accounts/{}/stories/own", encode_path(account_id)))
.query_opt("limit", params.limit.as_ref())
.retryable();
Paginator::new(self.http.clone(), parts, "cursor", params.cursor)
}
pub fn get(&self, account_id: &str, story_id: &str) -> Request<types::Story> {
let parts = RequestParts::new(Method::Get, format!("/v1/accounts/{}/stories/{}", encode_path(account_id), encode_path(story_id)))
.retryable();
self.http.request(parts)
}
pub fn get_media(
&self,
account_id: &str,
story_id: &str,
params: types::StoriesGetMediaParams,
) -> Request<types::StoryMediaFile> {
let parts = RequestParts::new(Method::Get, format!("/v1/accounts/{}/stories/{}/media", encode_path(account_id), encode_path(story_id)))
.query_opt("redirect", params.redirect.as_ref())
.retryable();
self.http.request(parts)
}
pub fn list_viewers(
&self,
account_id: &str,
story_id: &str,
params: types::StoriesListViewersParams,
) -> Paginator<types::StoryViewerList> {
let parts = RequestParts::new(Method::Get, format!("/v1/accounts/{}/stories/{}/viewers", encode_path(account_id), encode_path(story_id)))
.query_opt("limit", params.limit.as_ref())
.retryable();
Paginator::new(self.http.clone(), parts, "cursor", params.cursor)
}
pub fn view(&self, account_id: &str, story_id: &str) -> Request<types::Story> {
let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/stories/{}/view", encode_path(account_id), encode_path(story_id)))
.keyed();
self.http.request(parts)
}
pub fn react(
&self,
account_id: &str,
story_id: &str,
params: types::StoriesReactParams,
) -> Request<()> {
let parts = RequestParts::new(Method::Post, format!("/v1/accounts/{}/stories/{}/react", encode_path(account_id), encode_path(story_id)))
.body(¶ms)
.keyed()
.no_content();
self.http.request(parts)
}
pub fn delete(&self, account_id: &str, story_id: &str) -> Request<()> {
let parts = RequestParts::new(Method::Delete, format!("/v1/accounts/{}/stories/{}", encode_path(account_id), encode_path(story_id)))
.retryable()
.no_content();
self.http.request(parts)
}
}