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 ListsApiClient {
    configuration: Rc<configuration::Configuration>,
}

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

pub trait ListsApi {
    fn get_list_details(
        &self,
        list_id: &str,
        language: Option<&str>,
    ) -> Result<crate::models::ListDetails, Error>;
    fn get_list_item_status(
        &self,
        list_id: &str,
        movie_id: i32,
    ) -> Result<crate::models::ItemStatus, Error>;
    fn post_list(
        &self,
        content_type: &str,
        session_id: &str,
        body: Option<crate::models::ListBody>,
    ) -> Result<crate::models::ListStatusResponse, Error>;
    fn post_list_add_item(
        &self,
        list_id: &str,
        content_type: &str,
        session_id: &str,
        body: Option<crate::models::MediaIdBody>,
    ) -> Result<crate::models::InlineResponse401, Error>;
    fn post_list_clear(
        &self,
        list_id: &str,
        confirm: bool,
        session_id: &str,
    ) -> Result<crate::models::InlineResponse401, Error>;
    fn post_list_remove_item(
        &self,
        list_id: &str,
        content_type: &str,
        session_id: &str,
        body: Option<crate::models::MediaIdBody>,
    ) -> Result<crate::models::InlineResponse401, Error>;
}

impl ListsApi for ListsApiClient {
    fn get_list_details(
        &self,
        list_id: &str,
        language: Option<&str>,
    ) -> Result<crate::models::ListDetails, Error> {
        let configuration: &configuration::Configuration = self.configuration.borrow();
        let client = &configuration.client;

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

        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()?)
    }

    fn get_list_item_status(
        &self,
        list_id: &str,
        movie_id: i32,
    ) -> Result<crate::models::ItemStatus, Error> {
        let configuration: &configuration::Configuration = self.configuration.borrow();
        let client = &configuration.client;

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

        req_builder = req_builder.query(&[("movie_id", &movie_id.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()?)
    }

    fn post_list(
        &self,
        content_type: &str,
        session_id: &str,
        body: Option<crate::models::ListBody>,
    ) -> Result<crate::models::ListStatusResponse, Error> {
        let configuration: &configuration::Configuration = self.configuration.borrow();
        let client = &configuration.client;

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

        req_builder = req_builder.query(&[("session_id", &session_id.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());
        }
        req_builder = req_builder.header("Content-Type", content_type.to_string());
        req_builder = req_builder.json(&body);

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

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

    fn post_list_add_item(
        &self,
        list_id: &str,
        content_type: &str,
        session_id: &str,
        body: Option<crate::models::MediaIdBody>,
    ) -> Result<crate::models::InlineResponse401, Error> {
        let configuration: &configuration::Configuration = self.configuration.borrow();
        let client = &configuration.client;

        let uri_str = format!(
            "{}/list/{list_id}/add_item",
            configuration.base_path,
            list_id = urlencode(list_id)
        );
        let mut req_builder = client.post(uri_str.as_str());

        req_builder = req_builder.query(&[("session_id", &session_id.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());
        }
        req_builder = req_builder.header("Content-Type", content_type.to_string());
        req_builder = req_builder.json(&body);

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

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

    fn post_list_clear(
        &self,
        list_id: &str,
        confirm: bool,
        session_id: &str,
    ) -> Result<crate::models::InlineResponse401, Error> {
        let configuration: &configuration::Configuration = self.configuration.borrow();
        let client = &configuration.client;

        let uri_str = format!(
            "{}/list/{list_id}/clear",
            configuration.base_path,
            list_id = urlencode(list_id)
        );
        let mut req_builder = client.post(uri_str.as_str());

        req_builder = req_builder.query(&[("confirm", &confirm.to_string())]);
        req_builder = req_builder.query(&[("session_id", &session_id.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()?)
    }

    fn post_list_remove_item(
        &self,
        list_id: &str,
        content_type: &str,
        session_id: &str,
        body: Option<crate::models::MediaIdBody>,
    ) -> Result<crate::models::InlineResponse401, Error> {
        let configuration: &configuration::Configuration = self.configuration.borrow();
        let client = &configuration.client;

        let uri_str = format!(
            "{}/list/{list_id}/remove_item",
            configuration.base_path,
            list_id = urlencode(list_id)
        );
        let mut req_builder = client.post(uri_str.as_str());

        req_builder = req_builder.query(&[("session_id", &session_id.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());
        }
        req_builder = req_builder.header("Content-Type", content_type.to_string());
        req_builder = req_builder.json(&body);

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

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