line-bot-sdk-rust 3.0.0

LINE Messaging API SDK for Rust
Documentation
/*
* Copyright (C) 2016 LINE Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
 * LINE Messaging API
 *
 * This document describes LINE Messaging API.
 *
 * The version of the OpenAPI document: 0.0.1
 *
 * Generated by: https://openapi-generator.tech
 */

use std::borrow::Borrow;
#[allow(unused_imports)]
use std::option::Option;
use std::sync::Arc;

use hyper;
use hyper_util::client::legacy::connect::Connect;

use super::request as __internal_request;
use super::{configuration, Error};
use crate::line_manage_audience::models;

#[derive(Clone)]
pub struct ManageAudienceBlobApiClient<C: Connect>
where
    C: Clone + std::marker::Send + Sync + 'static,
{
    configuration: Arc<configuration::Configuration<C>>,
}

impl<C: Connect> ManageAudienceBlobApiClient<C>
where
    C: Clone + std::marker::Send + Sync,
{
    pub fn new(
        configuration: Arc<configuration::Configuration<C>>,
    ) -> ManageAudienceBlobApiClient<C> {
        ManageAudienceBlobApiClient { configuration }
    }
}

pub trait ManageAudienceBlobApi: Send + Sync {
    fn add_user_ids_to_audience(
        &self,
        file: std::path::PathBuf,
        audience_group_id: Option<i64>,
        upload_description: Option<&str>,
    ) -> impl std::future::Future<Output = Result<(), Error>> + Send;
    fn create_audience_for_uploading_user_ids(
        &self,
        file: std::path::PathBuf,
        description: Option<&str>,
        is_ifa_audience: Option<bool>,
        upload_description: Option<&str>,
    ) -> impl std::future::Future<Output = Result<models::CreateAudienceGroupResponse, Error>> + Send;
}

impl<C: Connect> ManageAudienceBlobApi for ManageAudienceBlobApiClient<C>
where
    C: Clone + std::marker::Send + Sync,
{
    #[allow(unused_mut)]
    async fn add_user_ids_to_audience(
        &self,
        file: std::path::PathBuf,
        audience_group_id: Option<i64>,
        upload_description: Option<&str>,
    ) -> Result<(), Error> {
        let mut req = __internal_request::Request::new(
            hyper::Method::PUT,
            "/v2/bot/audienceGroup/upload/byFile".to_string(),
        );
        if let Some(param_value) = audience_group_id {
            req = req.with_form_param("audienceGroupId".to_string(), param_value.to_string());
        }
        if let Some(param_value) = upload_description {
            req = req.with_form_param("uploadDescription".to_string(), param_value.to_string());
        }
        req = req.with_form_param("file".to_string(), file.display().to_string());
        req = req.returns_nothing();

        req.execute(self.configuration.borrow()).await
    }

    #[allow(unused_mut)]
    async fn create_audience_for_uploading_user_ids(
        &self,
        file: std::path::PathBuf,
        description: Option<&str>,
        is_ifa_audience: Option<bool>,
        upload_description: Option<&str>,
    ) -> Result<models::CreateAudienceGroupResponse, Error> {
        let mut req = __internal_request::Request::new(
            hyper::Method::POST,
            "/v2/bot/audienceGroup/upload/byFile".to_string(),
        );
        if let Some(param_value) = description {
            req = req.with_form_param("description".to_string(), param_value.to_string());
        }
        if let Some(param_value) = is_ifa_audience {
            req = req.with_form_param("isIfaAudience".to_string(), param_value.to_string());
        }
        if let Some(param_value) = upload_description {
            req = req.with_form_param("uploadDescription".to_string(), param_value.to_string());
        }
        req = req.with_form_param("file".to_string(), file.display().to_string());

        req.execute(self.configuration.borrow()).await
    }
}