tmdb_client 0.2.0

Rust client for The Movie Database (TMDB) API.
/*
 * API
 *
 * ## Welcome  This is a place to put general notes and extra information, for internal use.  To get started designing/documenting this API, select a version on the left. # Title No Description
 *
 * The version of the OpenAPI document: 3
 *
 * Generated by: https://openapi-generator.tech
 */

use std::borrow::Borrow;
use std::rc::Rc;

use reqwest;

use super::{configuration, Error};

pub struct JobsApiClient {
    configuration: Rc<configuration::Configuration>,
}

impl JobsApiClient {
    pub fn new(configuration: Rc<configuration::Configuration>) -> JobsApiClient {
        JobsApiClient {
            configuration: configuration,
        }
    }
}

pub trait JobsApi {
    fn get_jobs_list(&self) -> Result<crate::models::Jobs, Error>;
}

impl JobsApi for JobsApiClient {
    fn get_jobs_list(&self) -> Result<crate::models::Jobs, Error> {
        let configuration: &configuration::Configuration = self.configuration.borrow();
        let client = &configuration.client;

        let uri_str = format!("{}/job/list", configuration.base_path);
        let mut req_builder = client.get(uri_str.as_str());

        if let Some(ref apikey) = configuration.api_key {
            let key = apikey.key.clone();
            let val = match apikey.prefix {
                Some(ref prefix) => format!("{} {}", prefix, key),
                None => key,
            };
            req_builder = req_builder.query(&[("api_key", val)]);
        }
        if let Some(ref user_agent) = configuration.user_agent {
            req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
        }

        // send request
        let req = req_builder.build()?;

        Ok(client.execute(req)?.error_for_status()?.json()?)
    }
}