Skip to main content

line_bot_sdk_rust/line_module/apis/
line_module_api.rs

1/*
2* Copyright (C) 2016 LINE Corp.
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8*     http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16
17/*
18 * LINE Messaging API
19 *
20 * This document describes LINE Messaging API.
21 *
22 * The version of the OpenAPI document: 0.0.1
23 *
24 * Generated by: https://openapi-generator.tech
25 */
26
27use std::borrow::Borrow;
28#[allow(unused_imports)]
29use std::option::Option;
30use std::sync::Arc;
31
32use hyper;
33use hyper_util::client::legacy::connect::Connect;
34
35use super::request as __internal_request;
36use super::{configuration, Error};
37use crate::line_module::models;
38
39#[derive(Clone)]
40pub struct LineModuleApiClient<C: Connect>
41where
42    C: Clone + std::marker::Send + Sync + 'static,
43{
44    configuration: Arc<configuration::Configuration<C>>,
45}
46
47impl<C: Connect> LineModuleApiClient<C>
48where
49    C: Clone + std::marker::Send + Sync,
50{
51    pub fn new(configuration: Arc<configuration::Configuration<C>>) -> LineModuleApiClient<C> {
52        LineModuleApiClient { configuration }
53    }
54}
55
56pub trait LineModuleApi: Send + Sync {
57    fn acquire_chat_control(
58        &self,
59        chat_id: &str,
60        acquire_chat_control_request: Option<models::AcquireChatControlRequest>,
61    ) -> impl std::future::Future<Output = Result<(), Error>> + Send;
62    fn detach_module(
63        &self,
64        detach_module_request: Option<models::DetachModuleRequest>,
65    ) -> impl std::future::Future<Output = Result<(), Error>> + Send;
66    fn get_modules(
67        &self,
68        start: Option<&str>,
69        limit: Option<i32>,
70    ) -> impl std::future::Future<Output = Result<models::GetModulesResponse, Error>> + Send;
71    fn release_chat_control(
72        &self,
73        chat_id: &str,
74    ) -> impl std::future::Future<Output = Result<(), Error>> + Send;
75}
76
77impl<C: Connect> LineModuleApi for LineModuleApiClient<C>
78where
79    C: Clone + std::marker::Send + Sync,
80{
81    #[allow(unused_mut)]
82    async fn acquire_chat_control(
83        &self,
84        chat_id: &str,
85        acquire_chat_control_request: Option<models::AcquireChatControlRequest>,
86    ) -> Result<(), Error> {
87        let mut req = __internal_request::Request::new(
88            hyper::Method::POST,
89            "/v2/bot/chat/{chatId}/control/acquire".to_string(),
90        );
91        req = req.with_path_param("chatId".to_string(), chat_id.to_string());
92        req = req.with_body_param(acquire_chat_control_request);
93        req = req.returns_nothing();
94
95        req.execute(self.configuration.borrow()).await
96    }
97
98    #[allow(unused_mut)]
99    async fn detach_module(
100        &self,
101        detach_module_request: Option<models::DetachModuleRequest>,
102    ) -> Result<(), Error> {
103        let mut req = __internal_request::Request::new(
104            hyper::Method::POST,
105            "/v2/bot/channel/detach".to_string(),
106        );
107        req = req.with_body_param(detach_module_request);
108        req = req.returns_nothing();
109
110        req.execute(self.configuration.borrow()).await
111    }
112
113    #[allow(unused_mut)]
114    async fn get_modules(
115        &self,
116        start: Option<&str>,
117        limit: Option<i32>,
118    ) -> Result<models::GetModulesResponse, Error> {
119        let mut req =
120            __internal_request::Request::new(hyper::Method::GET, "/v2/bot/list".to_string());
121        if let Some(ref s) = start {
122            req = req.with_query_param("start".to_string(), s.to_string());
123        }
124        if let Some(ref s) = limit {
125            req = req.with_query_param("limit".to_string(), s.to_string());
126        }
127
128        req.execute(self.configuration.borrow()).await
129    }
130
131    #[allow(unused_mut)]
132    async fn release_chat_control(&self, chat_id: &str) -> Result<(), Error> {
133        let mut req = __internal_request::Request::new(
134            hyper::Method::POST,
135            "/v2/bot/chat/{chatId}/control/release".to_string(),
136        );
137        req = req.with_path_param("chatId".to_string(), chat_id.to_string());
138        req = req.returns_nothing();
139
140        req.execute(self.configuration.borrow()).await
141    }
142}