Skip to content

Commit

Permalink
Better docs and some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
marioortizmanero committed Aug 16, 2020
1 parent cfc8292 commit ac2bf7f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions tests/test_with_oauth.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! These tests currently require user interaction to authenticate an account
//! where the tests can be ran. The tests are written so that no account
//! where the tests can be ran, so they are ran manually instead of with
//! Continuous Integration for now. The tests are written so that no account
//! data is modified.
//!
//! You can run them manually with `cargo test -- --ignored`.
use async_once::AsyncOnce;
use chrono::prelude::*;
Expand All @@ -18,9 +21,10 @@ lazy_static! {
// With so many tests, it's a better idea to authenticate only once at the
// beginning. The `Spotify` instance needed here is for async requests,
// so this uses `AsyncOnce` to work with `lazy_static`.
static ref SPOTIFY: AsyncOnce<Spotify> = AsyncOnce::new(async {
static ref CLIENT_CREDENTIAL: AsyncOnce<SpotifyClientCredentials> = AsyncOnce::new(async {
dotenv().ok();

// Using every possible scope
let mut oauth = SpotifyOAuth::default()
.scope(
"user-read-email user-read-private user-top-read
Expand All @@ -34,19 +38,21 @@ lazy_static! {
.build();

let token = get_token(&mut oauth).await.unwrap();
let client_credential = SpotifyClientCredentials::default()
SpotifyClientCredentials::default()
.token_info(token)
.build();
Spotify::default()
.client_credentials_manager(client_credential)
.build()
});
}

// Even easier to use and change in the future by using a macro.
macro_rules! async_client {
() => {
async { SPOTIFY.get().await }
async {
let creds = CLIENT_CREDENTIAL.get().await;
Spotify::default()
.client_credentials_manager(creds)
.build()
}
};
}

Expand Down

0 comments on commit ac2bf7f

Please sign in to comment.