Skip to main content

ghl_sdk/services/
blogs.rs

1// @generated by xtask/generate_services.py — do not edit by hand.
2//! `blogs` — typed methods for all 7 API v2 operations
3//! in this module.
4//!
5//! Access via [`Ghl::blogs`](crate::Ghl::blogs).
6//!
7//! Request and response types come from [`ghl_models::v2::blogs`](https://docs.rs/ghl-models/latest/ghl_models/v2/blogs/); every endpoint is also documented in the
8//! [`blogs` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/blogs.md).
9//!
10//! Enable with `features = ["blogs"]`.
11
12#![allow(clippy::too_many_arguments)]
13
14use crate::client::Ghl;
15use crate::error::Result;
16use ghl_models::v2::blogs as models;
17
18/// Typed access to the `blogs` API v2 surface (7 operations). Obtained via
19/// [`Ghl::blogs`](crate::Ghl::blogs).
20#[derive(Debug, Clone)]
21pub struct BlogsService {
22    pub(crate) client: Ghl,
23}
24
25impl BlogsService {
26    pub(crate) fn new(client: Ghl) -> Self {
27        Self { client }
28    }
29}
30
31/// Query parameters for [`BlogsService::get_all_authors`].
32#[derive(Debug, Clone, Default)]
33pub struct GetAllAuthorsParams {
34    /// Location Id
35    /// Required by the API.
36    pub location_id: String,
37    /// Number of authors to show in the listing
38    /// Required by the API.
39    pub limit: f64,
40    /// Number of authors to skip in listing
41    /// Required by the API.
42    pub offset: f64,
43}
44
45impl GetAllAuthorsParams {
46    /// Start from the parameters the API requires.
47    pub fn new(location_id: impl Into<String>, limit: f64, offset: f64) -> Self {
48        Self {
49            location_id: location_id.into(),
50            limit,
51            offset,
52        }
53    }
54
55    fn to_query(&self) -> Vec<(String, String)> {
56        let q: Vec<(String, String)> = vec![
57            ("locationId".into(), self.location_id.clone()),
58            ("limit".into(), self.limit.to_string()),
59            ("offset".into(), self.offset.to_string()),
60        ];
61        q
62    }
63}
64
65/// Query parameters for [`BlogsService::get_all_categories`].
66#[derive(Debug, Clone, Default)]
67pub struct GetAllCategoriesParams {
68    /// `locationId` query parameter.
69    /// Required by the API.
70    pub location_id: String,
71    /// Number of categories to show in the listing
72    /// Required by the API.
73    pub limit: f64,
74    /// Number of categories to skip in listing
75    /// Required by the API.
76    pub offset: f64,
77}
78
79impl GetAllCategoriesParams {
80    /// Start from the parameters the API requires.
81    pub fn new(location_id: impl Into<String>, limit: f64, offset: f64) -> Self {
82        Self {
83            location_id: location_id.into(),
84            limit,
85            offset,
86        }
87    }
88
89    fn to_query(&self) -> Vec<(String, String)> {
90        let q: Vec<(String, String)> = vec![
91            ("locationId".into(), self.location_id.clone()),
92            ("limit".into(), self.limit.to_string()),
93            ("offset".into(), self.offset.to_string()),
94        ];
95        q
96    }
97}
98
99/// Query parameters for [`BlogsService::get_blog_posts_by_blog_id`].
100#[derive(Debug, Clone, Default)]
101pub struct GetBlogPostsByBlogIdParams {
102    /// `locationId` query parameter.
103    /// Required by the API.
104    pub location_id: String,
105    /// `blogId` query parameter.
106    /// Required by the API.
107    pub blog_id: String,
108    /// `limit` query parameter.
109    /// Required by the API.
110    pub limit: f64,
111    /// `offset` query parameter.
112    /// Required by the API.
113    pub offset: f64,
114    /// search for any post by name
115    pub search_term: Option<String>,
116    /// `status` query parameter.
117    /// Allowed values: `PUBLISHED`, `SCHEDULED`, `ARCHIVED`, `DRAFT`.
118    pub status: Option<String>,
119}
120
121impl GetBlogPostsByBlogIdParams {
122    /// Start from the parameters the API requires.
123    pub fn new(
124        location_id: impl Into<String>,
125        blog_id: impl Into<String>,
126        limit: f64,
127        offset: f64,
128    ) -> Self {
129        Self {
130            location_id: location_id.into(),
131            blog_id: blog_id.into(),
132            limit,
133            offset,
134            ..Default::default()
135        }
136    }
137
138    /// search for any post by name
139    pub fn search_term(mut self, v: impl Into<String>) -> Self {
140        self.search_term = Some(v.into());
141        self
142    }
143
144    /// Set the `status` query parameter.
145    pub fn status(mut self, v: impl Into<String>) -> Self {
146        self.status = Some(v.into());
147        self
148    }
149
150    fn to_query(&self) -> Vec<(String, String)> {
151        let mut q: Vec<(String, String)> = vec![
152            ("locationId".into(), self.location_id.clone()),
153            ("blogId".into(), self.blog_id.clone()),
154            ("limit".into(), self.limit.to_string()),
155            ("offset".into(), self.offset.to_string()),
156        ];
157        if let Some(v) = &self.search_term {
158            q.push(("searchTerm".into(), v.to_string()));
159        }
160        if let Some(v) = &self.status {
161            q.push(("status".into(), v.to_string()));
162        }
163        q
164    }
165}
166
167/// Query parameters for [`BlogsService::check_url_slug`].
168#[derive(Debug, Clone, Default)]
169pub struct CheckUrlSlugParams {
170    /// `urlSlug` query parameter.
171    /// Required by the API.
172    pub url_slug: String,
173    /// `locationId` query parameter.
174    /// Required by the API.
175    pub location_id: String,
176    /// `postId` query parameter.
177    pub post_id: Option<String>,
178}
179
180impl CheckUrlSlugParams {
181    /// Start from the parameters the API requires.
182    pub fn new(url_slug: impl Into<String>, location_id: impl Into<String>) -> Self {
183        Self {
184            url_slug: url_slug.into(),
185            location_id: location_id.into(),
186            ..Default::default()
187        }
188    }
189
190    /// Set the `postId` query parameter.
191    pub fn post_id(mut self, v: impl Into<String>) -> Self {
192        self.post_id = Some(v.into());
193        self
194    }
195
196    fn to_query(&self) -> Vec<(String, String)> {
197        let mut q: Vec<(String, String)> = vec![
198            ("urlSlug".into(), self.url_slug.clone()),
199            ("locationId".into(), self.location_id.clone()),
200        ];
201        if let Some(v) = &self.post_id {
202            q.push(("postId".into(), v.to_string()));
203        }
204        q
205    }
206}
207
208/// Query parameters for [`BlogsService::get_blogs_by_location_id`].
209#[derive(Debug, Clone, Default)]
210pub struct GetBlogsByLocationIdParams {
211    /// `locationId` query parameter.
212    /// Required by the API.
213    pub location_id: String,
214    /// `skip` query parameter.
215    /// Required by the API.
216    pub skip: f64,
217    /// `limit` query parameter.
218    /// Required by the API.
219    pub limit: f64,
220    /// search for any post by name
221    pub search_term: Option<String>,
222}
223
224impl GetBlogsByLocationIdParams {
225    /// Start from the parameters the API requires.
226    pub fn new(location_id: impl Into<String>, skip: f64, limit: f64) -> Self {
227        Self {
228            location_id: location_id.into(),
229            skip,
230            limit,
231            ..Default::default()
232        }
233    }
234
235    /// search for any post by name
236    pub fn search_term(mut self, v: impl Into<String>) -> Self {
237        self.search_term = Some(v.into());
238        self
239    }
240
241    fn to_query(&self) -> Vec<(String, String)> {
242        let mut q: Vec<(String, String)> = vec![
243            ("locationId".into(), self.location_id.clone()),
244            ("skip".into(), self.skip.to_string()),
245            ("limit".into(), self.limit.to_string()),
246        ];
247        if let Some(v) = &self.search_term {
248            q.push(("searchTerm".into(), v.to_string()));
249        }
250        q
251    }
252}
253
254impl BlogsService {
255    /// Get all authors
256    ///
257    /// The "Get all authors" Api return the blog authors for a given location ID. Please
258    /// use "blogs/author.readonly"
259    ///
260    /// `GET /blogs/authors`
261    ///
262    /// Requires scope: `blogs/author.readonly`.
263    pub async fn get_all_authors(
264        &self,
265        params: &GetAllAuthorsParams,
266    ) -> Result<models::AuthorsResponseDTO> {
267        let query = params.to_query();
268        self.client
269            .send_versioned(
270                reqwest::Method::GET,
271                "/blogs/authors",
272                &query,
273                None::<&()>,
274                Some("2021-07-28"),
275            )
276            .await
277    }
278
279    /// Get all categories
280    ///
281    /// The "Get all categories" Api return the blog categoies for a given location ID.
282    /// Please use "blogs/category.readonly"
283    ///
284    /// `GET /blogs/categories`
285    ///
286    /// Requires scope: `blogs/category.readonly`.
287    pub async fn get_all_categories(
288        &self,
289        params: &GetAllCategoriesParams,
290    ) -> Result<models::CategoriesResponseDTO> {
291        let query = params.to_query();
292        self.client
293            .send_versioned(
294                reqwest::Method::GET,
295                "/blogs/categories",
296                &query,
297                None::<&()>,
298                Some("2021-07-28"),
299            )
300            .await
301    }
302
303    /// Create Blog Post
304    ///
305    /// The "Create Blog Post" API allows you create blog post for any given blog site.
306    /// Please use blogs/post.write
307    ///
308    /// `POST /blogs/posts`
309    ///
310    /// Requires scope: `blogs/post.write`.
311    pub async fn create_blog_post(
312        &self,
313        body: &models::CreateBlogPostParams,
314    ) -> Result<models::BlogPostCreateResponseWrapperDTO> {
315        let query = Vec::new();
316        self.client
317            .send_versioned(
318                reqwest::Method::POST,
319                "/blogs/posts",
320                &query,
321                Some(body),
322                Some("2021-07-28"),
323            )
324            .await
325    }
326
327    /// Get Blog posts by Blog ID
328    ///
329    /// The "Get Blog posts by Blog ID" API allows you get blog posts for any given blog
330    /// site using blog ID.Please use blogs/posts.readonly
331    ///
332    /// `GET /blogs/posts/all`
333    ///
334    /// Requires scope: `blogs/posts.readonly`.
335    pub async fn get_blog_posts_by_blog_id(
336        &self,
337        params: &GetBlogPostsByBlogIdParams,
338    ) -> Result<models::BlogPostGetResponseWrapperDTO> {
339        let query = params.to_query();
340        self.client
341            .send_versioned(
342                reqwest::Method::GET,
343                "/blogs/posts/all",
344                &query,
345                None::<&()>,
346                Some("2021-07-28"),
347            )
348            .await
349    }
350
351    /// Check url slug
352    ///
353    /// The "Check url slug" API allows check the blog slug validation which is needed
354    /// before publishing any blog post. Please use blogs/check-slug.readonly. you can find
355    /// the POST ID from the post edit url.
356    ///
357    /// `GET /blogs/posts/url-slug-exists`
358    ///
359    /// Requires scope: `blogs/check-slug.readonly`.
360    pub async fn check_url_slug(
361        &self,
362        params: &CheckUrlSlugParams,
363    ) -> Result<models::UrlSlugCheckResponseDTO> {
364        let query = params.to_query();
365        self.client
366            .send_versioned(
367                reqwest::Method::GET,
368                "/blogs/posts/url-slug-exists",
369                &query,
370                None::<&()>,
371                Some("2021-07-28"),
372            )
373            .await
374    }
375
376    /// Update Blog Post
377    ///
378    /// The "Update Blog Post" API allows you update blog post for any given blog site.
379    /// Please use blogs/post-update.write
380    ///
381    /// `PUT /blogs/posts/{postId}`
382    ///
383    /// Requires scope: `blogs/post-update.write`.
384    pub async fn update_blog_post(
385        &self,
386        post_id: &str,
387        body: &models::UpdateBlogPostParams,
388    ) -> Result<models::BlogPostUpdateResponseWrapperDTO> {
389        let path = format!("/blogs/posts/{}", crate::services::encode(post_id));
390        let query = Vec::new();
391        self.client
392            .send_versioned(
393                reqwest::Method::PUT,
394                &path,
395                &query,
396                Some(body),
397                Some("2021-07-28"),
398            )
399            .await
400    }
401
402    /// Get Blogs by Location ID
403    ///
404    /// The "Get Blogs by Location ID" API allows you get blogs using Location ID.Please use
405    /// blogs/list.readonly
406    ///
407    /// `GET /blogs/site/all`
408    ///
409    /// Requires scope: `blogs/list.readonly`.
410    pub async fn get_blogs_by_location_id(
411        &self,
412        params: &GetBlogsByLocationIdParams,
413    ) -> Result<models::BlogGetResponseWrapperDTO> {
414        let query = params.to_query();
415        self.client
416            .send_versioned(
417                reqwest::Method::GET,
418                "/blogs/site/all",
419                &query,
420                None::<&()>,
421                Some("2021-07-28"),
422            )
423            .await
424    }
425}