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::option::Option;
use std::rc::Rc;

use reqwest;

use super::{configuration, urlencode, Error};

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

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

pub trait FindApi {
    fn get_find_external_id(
        &self,
        external_id: &str,
        external_source: &str,
        language: Option<&str>,
    ) -> Result<crate::models::FindByExternalIdResults, Error>;
}

impl FindApi for FindApiClient {
    fn get_find_external_id(
        &self,
        external_id: &str,
        external_source: &str,
        language: Option<&str>,
    ) -> Result<crate::models::FindByExternalIdResults, Error> {
        let configuration: &configuration::Configuration = self.configuration.borrow();
        let client = &configuration.client;

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

        req_builder = req_builder.query(&[("external_source", &external_source.to_string())]);
        if let Some(ref s) = language {
            req_builder = req_builder.query(&[("language", &s.to_string())]);
        }
        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()?)
    }
}