1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-05 19:42:03 +02:00

update examples

Re-add default impl to SessionConfig and make Credentials::with_password generic over Into<String>

add docs for Credential

reintroduce old Default impl for SessionConfig

use the third argument for the track-to-play rather than a testing id
This commit is contained in:
ThouCheese 2021-03-06 01:29:08 +01:00
parent 963d50e725
commit ec1ec59b8a
7 changed files with 67 additions and 48 deletions

View file

@ -10,6 +10,7 @@ use sha1::{Digest, Sha1};
use crate::protocol::authentication::AuthenticationType;
/// The credentials are used to log into the Spotify API.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Credentials {
pub username: String,
@ -25,11 +26,22 @@ pub struct Credentials {
}
impl Credentials {
pub fn with_password(username: String, password: String) -> Credentials {
/// Intialize these credentials from a username and a password.
///
/// ### Example
/// ```rust
/// use librespot_core::authentication::Credentials;
///
/// let creds = Credentials::with_password("my account", "my password");
/// ```
pub fn with_password(
username: impl Into<String>,
password: impl Into<String>,
) -> Credentials {
Credentials {
username,
username: username.into(),
auth_type: AuthenticationType::AUTHENTICATION_USER_PASS,
auth_data: password.into_bytes(),
auth_data: password.into().into_bytes(),
}
}

View file

@ -10,6 +10,18 @@ pub struct SessionConfig {
pub ap_port: Option<u16>,
}
impl Default for SessionConfig {
fn default() -> SessionConfig {
let device_id = uuid::Uuid::new_v4().to_hyphenated().to_string();
SessionConfig {
user_agent: crate::version::version_string(),
device_id,
proxy: None,
ap_port: None,
}
}
}
#[derive(Clone, Copy, Debug, Hash, PartialOrd, Ord, PartialEq, Eq)]
pub enum DeviceType {
Unknown = 0,