1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use anyhow::Result;

use crate::Client;

pub struct Jobs {
    pub client: Client,
}

impl Jobs {
    #[doc(hidden)]
    pub fn new(client: Client) -> Self {
        Jobs { client }
    }

    /**
     * Get List of Jobs.
     *
     * This function performs a `GET` to the `/jobs` endpoint.
     *
     * Gets a list of transcription jobs submitted within the last 30 days in reverse chronological order up to the provided `limit` number of jobs per call. **Note:** Jobs older than 30 days will not be listed. Pagination is supported via passing the last job `id` from a previous call into `starting_after`.
     *
     * **Parameters:**
     *
     * * `limit: i64` -- Limits the number of jobs returned, default is 100, max is 1000.
     * * `starting_after: &str` -- If specified, returns transcription jobs submitted before the job with this id, exclusive (job with this id is not included).
     */
    pub async fn get_list_of(
        &self,
        limit: i64,
        starting_after: &str,
    ) -> Result<Vec<crate::types::JobAllOf>> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if limit > 0 {
            query_args.push(("limit".to_string(), limit.to_string()));
        }
        if !starting_after.is_empty() {
            query_args.push(("starting_after".to_string(), starting_after.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!("/jobs?{}", query_);

        self.client.get(&url, None).await
    }

    /**
     * Get List of Jobs.
     *
     * This function performs a `GET` to the `/jobs` endpoint.
     *
     * As opposed to `get_list_of`, this function returns all the pages of the request at once.
     *
     * Gets a list of transcription jobs submitted within the last 30 days in reverse chronological order up to the provided `limit` number of jobs per call. **Note:** Jobs older than 30 days will not be listed. Pagination is supported via passing the last job `id` from a previous call into `starting_after`.
     */
    pub async fn get_all_list_all_of(
        &self,
        starting_after: &str,
    ) -> Result<Vec<crate::types::JobAllOf>> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if !starting_after.is_empty() {
            query_args.push(("starting_after".to_string(), starting_after.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!("/jobs?{}", query_);

        self.client.get_all_pages(&url, None).await
    }

    /**
     * Submit Transcription Job.
     *
     * This function performs a `POST` to the `/jobs` endpoint.
     *
     * Starts an asynchronous job to transcribe speech-to-text for a media file. Media files can be specified in two ways, either by including a public url to the media in the transcription job `options` or by uploading a local file as part of a multipart/form request.
     */
    pub async fn submit_transcription(
        &self,
        body: &crate::types::SubmitJobMediaUrlOptionsAllOf,
    ) -> Result<crate::types::JobAllOf> {
        let url = "/jobs".to_string();
        self.client
            .post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
            .await
    }

    /**
     * Get Job By Id.
     *
     * This function performs a `GET` to the `/jobs/{id}` endpoint.
     *
     * Returns information about a transcription job
     */
    pub async fn get(&self, id: &str) -> Result<crate::types::JobAllOf> {
        let url = format!(
            "/jobs/{}",
            crate::progenitor_support::encode_path(&id.to_string()),
        );

        self.client.get(&url, None).await
    }

    /**
     * Delete Job by Id.
     *
     * This function performs a `DELETE` to the `/jobs/{id}` endpoint.
     *
     * Deletes a transcription job. All data related to the job, such as input media and transcript, will be permanently deleted. A job can only be deleted once it's completed (either with success or failure).
     */
    pub async fn delete(&self, id: &str) -> Result<()> {
        let url = format!(
            "/jobs/{}",
            crate::progenitor_support::encode_path(&id.to_string()),
        );

        self.client.delete(&url, None).await
    }
}