Skip to content

Commit

Permalink
rename: ClientCredentialsSpotify -> ClientCredsSpotify
Browse files Browse the repository at this point in the history
  • Loading branch information
marioortizmanero committed May 13, 2021
1 parent f44d9e8 commit 1367931
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions examples/client_credentials.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rspotify::{model::Id, prelude::*, ClientCredentialsSpotify, Credentials};
use rspotify::{model::Id, prelude::*, ClientCredsSpotify, Credentials};

#[tokio::main]
async fn main() {
Expand All @@ -23,7 +23,7 @@ async fn main() {
// ```
let creds = Credentials::from_env().unwrap();

let mut spotify = ClientCredentialsSpotify::new(creds);
let mut spotify = ClientCredsSpotify::new(creds);

// Obtaining the access token. Requires to be mutable because the internal
// token will be modified. We don't need OAuth for this specific endpoint,
Expand Down
4 changes: 2 additions & 2 deletions examples/ureq/search.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use rspotify::{
model::{Country, Market, SearchType},
prelude::*,
ClientCredentialsSpotify, Credentials,
ClientCredsSpotify, Credentials,
};

fn main() {
// You can use any logger for debugging.
env_logger::init();

let creds = Credentials::from_env().unwrap();
let mut spotify = ClientCredentialsSpotify::new(creds);
let mut spotify = ClientCredsSpotify::new(creds);

// Obtaining the access token
spotify.request_token().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/auth_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use url::Url;
///
/// This includes user authorization, and thus has access to endpoints related
/// to user private data, unlike the [Client Credentials
/// Flow](crate::ClientCredentialsSpotify) client. See [`BaseClient`] and
/// Flow](crate::ClientCredsSpotify) client. See [`BaseClient`] and
/// [`OAuthClient`] for the available endpoints.
///
/// If you're developing a CLI application, you might be interested in the `cli`
Expand Down
20 changes: 10 additions & 10 deletions src/client_creds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ use maybe_async::maybe_async;
/// [reference]: https://developer.spotify.com/documentation/general/guides/authorization-guide/#client-credentials-flow
/// [example-main]: https://github.com/ramsayleung/rspotify/blob/master/examples/client_creds.rs
#[derive(Clone, Debug, Default)]
pub struct ClientCredentialsSpotify {
pub struct ClientCredsSpotify {
pub config: Config,
pub creds: Credentials,
pub token: Option<Token>,
pub(in crate) http: HttpClient,
}

/// This client has access to the base methods.
impl BaseClient for ClientCredentialsSpotify {
impl BaseClient for ClientCredsSpotify {
fn get_http(&self) -> &HttpClient {
&self.http
}
Expand All @@ -50,21 +50,21 @@ impl BaseClient for ClientCredentialsSpotify {
}
}

impl ClientCredentialsSpotify {
/// Builds a new [`ClientCredentialsSpotify`] given a pair of client
/// credentials and OAuth information.
impl ClientCredsSpotify {
/// Builds a new [`ClientCredsSpotify`] given a pair of client credentials
/// and OAuth information.
pub fn new(creds: Credentials) -> Self {
ClientCredentialsSpotify {
ClientCredsSpotify {
creds,
..Default::default()
}
}

/// Build a new [`ClientCredentialsSpotify`] from an already generated
/// token. Note that once the token expires this will fail to make requests,
/// Build a new [`ClientCredsSpotify`] from an already generated token. Note
/// that once the token expires this will fail to make requests,
/// as the client credentials aren't known.
pub fn from_token(token: Token) -> Self {
ClientCredentialsSpotify {
ClientCredsSpotify {
token: Some(token),
..Default::default()
}
Expand All @@ -73,7 +73,7 @@ impl ClientCredentialsSpotify {
/// Same as [`Self::new`] but with an extra parameter to configure the
/// client.
pub fn with_config(creds: Credentials, config: Config) -> Self {
ClientCredentialsSpotify {
ClientCredsSpotify {
config,
creds,
..Default::default()
Expand Down
6 changes: 3 additions & 3 deletions src/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn basic_auth(user: &str, password: &str) -> (String, String) {
#[cfg(test)]
mod test {
use super::*;
use crate::{scopes, ClientCredentialsSpotify, Token};
use crate::{scopes, ClientCredsSpotify, Token};
use chrono::{prelude::*, Duration};

#[test]
Expand Down Expand Up @@ -101,7 +101,7 @@ mod test {

#[test]
fn test_endpoint_url() {
let spotify = ClientCredentialsSpotify::default();
let spotify = ClientCredsSpotify::default();
assert_eq!(
spotify.endpoint_url("me/player/play"),
"https://api.spotify.com/v1/me/player/play"
Expand All @@ -126,7 +126,7 @@ mod test {
refresh_token: Some("...".to_string()),
};

let spotify = ClientCredentialsSpotify::from_token(tok);
let spotify = ClientCredsSpotify::from_token(tok);
let headers = spotify.auth_headers().unwrap();
assert_eq!(
headers.get("authorization"),
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
//! flow it is. Please refer to their documentation for more details:
//!
//! * [Client Credentials Flow](spotify-client-creds): see
//! [`ClientCredentialsSpotify`].
//! [`ClientCredsSpotify`].
//! * [Authorization Code Flow](spotify-auth-code): see [`AuthCodeSpotify`].
//! * [Authorization Code Flow with Proof Key for Code Exchange
//! (PKCE)](spotify-auth-code-pkce): see [`AuthCodePkceSpotify`].
Expand Down Expand Up @@ -132,7 +132,7 @@ pub use rspotify_http as http;
pub use rspotify_macros as macros;
pub use rspotify_model as model;
// Top-level re-exports
pub use client_creds::ClientCredentialsSpotify;
pub use client_creds::ClientCredsSpotify;
pub use auth_code::AuthCodeSpotify;
pub use auth_code_pkce::AuthCodePkceSpotify;
pub use macros::scopes;
Expand Down
8 changes: 4 additions & 4 deletions tests/test_oauth2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use chrono::prelude::*;
use chrono::Duration;
use maybe_async::maybe_async;
use rspotify::{
prelude::*, scopes, ClientCredentialsSpotify, AuthCodeSpotify, Config, Credentials, OAuth,
prelude::*, scopes, ClientCredsSpotify, AuthCodeSpotify, Config, Credentials, OAuth,
Token,
};
use std::{collections::HashMap, fs, io::Read, path::PathBuf, thread::sleep};
Expand Down Expand Up @@ -57,14 +57,14 @@ async fn test_read_token_cache() {
cache_path: PathBuf::from(".test_read_token_cache.json"),
..Default::default()
};
let mut predefined_spotify = ClientCredentialsSpotify::from_token(tok.clone());
let mut predefined_spotify = ClientCredsSpotify::from_token(tok.clone());
predefined_spotify.config = config.clone();

// write token data to cache_path
predefined_spotify.write_token_cache().unwrap();
assert!(predefined_spotify.config.cache_path.exists());

let mut spotify = ClientCredentialsSpotify::default();
let mut spotify = ClientCredsSpotify::default();
spotify.config = config;

// read token from cache file
Expand Down Expand Up @@ -96,7 +96,7 @@ fn test_write_token() {
cache_path: PathBuf::from(".test_write_token_cache.json"),
..Default::default()
};
let mut spotify = ClientCredentialsSpotify::from_token(tok.clone());
let mut spotify = ClientCredsSpotify::from_token(tok.clone());
spotify.config = config;

let tok_str = serde_json::to_string(&tok).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions tests/test_with_credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use common::maybe_async_test;
use rspotify::{
model::{AlbumType, Country, Id, Market},
prelude::*,
ClientCredentialsSpotify, Credentials,
ClientCredsSpotify, Credentials,
};

use maybe_async::maybe_async;

/// Generating a new basic client for the requests.
#[maybe_async]
pub async fn creds_client() -> ClientCredentialsSpotify {
pub async fn creds_client() -> ClientCredsSpotify {
// The credentials must be available in the environment.
let creds = Credentials::from_env().unwrap_or_else(|| {
panic!(
Expand All @@ -21,7 +21,7 @@ pub async fn creds_client() -> ClientCredentialsSpotify {
)
});

let mut spotify = ClientCredentialsSpotify::new(creds);
let mut spotify = ClientCredsSpotify::new(creds);
spotify.request_token().await.unwrap();
spotify
}
Expand Down

0 comments on commit 1367931

Please sign in to comment.