pub fn new(
        product: String,
        version: String,
        identifier: String,
        username: &str,
        password: &str,
    ) -> Result<PlexTV, Error> {
        let client = Client::new();

        let mut product_headers = Headers::with_capacity(4);
        product_headers.set(XPlexProduct(product));
        product_headers.set(XPlexVersion(version));
        product_headers.set(XPlexClientIdentifier(identifier));

        let mut res = client
            .post("https://plex.tv/users/sign_in.json")
            .headers(product_headers.clone())
            .body(format!(
                "user[login]={}&user[password]={}",
                username,
                password
            ))
            .send()?;

        let res_struct: PlexTVAuthResponse = res.json()?;

        product_headers.set(XPlexToken(res_struct.user.clone().authentication_token));

        Ok(PlexTV {
            client,
            headers: product_headers,
            user: res_struct.user,
        })
    }
/// Create a new client for the plex.tv API.
///
/// Of particular note are the `product`, `version`, and `identifier` arguments. The Plex API
/// requires clients to set several headers containing metadata about themselves. `product`
/// should contain the name of the product consuming the API; `version` should contain the
/// version of the product, and `identifier` should be some sort of unique ID that identifies a
/// specific instance of a client.
Create a new client for the plex.tv API.
Create a new client for the plex . tv API .
pub fn new(
        product: String,
        version: String,
        identifier: String,
        username: &str,
        password: &str,
    ) -> Result<PlexTV, Error> {
        let client = Client::new();
        let mut product_headers = Headers::with_capacity(4);
        product_headers.set(XPlexProduct(product));
        product_headers.set(XPlexVersion(version));
        product_headers.set(XPlexClientIdentifier(identifier));
        let mut res = client
            .post("https://plex.tv/users/sign_in.json")
            .headers(product_headers.clone())
            .body(format!(
                "user[login]={}&user[password]={}",
                username,
                password
            ))
            .send()?;
        let res_struct: PlexTVAuthResponse = res.json()?;
        product_headers.set(XPlexToken(res_struct.user.clone().authentication_token));
        Ok(PlexTV {
            client,
            headers: product_headers,
            user: res_struct.user,
        })
    }
pub fn new ( product : String , version : String , identifier : String , username : & str , password : & str , ) -> Result < PlexTV , Error > { let client = Client :: new ( ) ; let mut product_headers = Headers :: with_capacity ( 4 ) ; product_headers . set ( XPlexProduct ( product ) ) ; product_headers . set ( XPlexVersion ( version ) ) ; product_headers . set ( XPlexClientIdentifier ( identifier ) ) ; let mut res = client . post ( " " ) . headers ( product_headers . clone ( ) ) . body ( format ! ( " " username password ) ) . send ( ) ? ; let res_struct : PlexTVAuthResponse = res . json ( ) ? ; product_headers . set ( XPlexToken ( res_struct . user . clone ( ) . authentication_token ) ) ; Ok ( PlexTV { client , headers : product_headers , user : res_struct . user , } ) }
Create a new client for the plex.tv API.
Create a new client for the plex . tv API .
product
String
version
String
identifier
String
username
&str
password
&str
product
String
version
String
identifier
String
username
&str
password
&str