summaryrefslogtreecommitdiff
path: root/examples/playlists
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-09-08 21:08:48 +0200
committerHampusM <hampus@hampusmat.com>2022-09-08 21:08:48 +0200
commit8a02d3386d4ce0b58de943fcf42bd072af1e0b42 (patch)
tree6656b72ce309ae993029d8cdae26604098d92ba7 /examples/playlists
parentb44463d533ba9b789e3423d670e2ddcc32c1112c (diff)
refactor: move get access token to DeezerClient
Diffstat (limited to 'examples/playlists')
-rw-r--r--examples/playlists/main.rs15
1 files changed, 8 insertions, 7 deletions
diff --git a/examples/playlists/main.rs b/examples/playlists/main.rs
index fed5b73..81d3cf2 100644
--- a/examples/playlists/main.rs
+++ b/examples/playlists/main.rs
@@ -2,7 +2,7 @@ use std::error::Error;
use anyhow::Context;
use config::Config;
-use deez::auth::{request_access_token, AuthPromptHandler};
+use deez::auth::AuthPromptHandler;
use deez::client::DeezerClient;
use serde::Deserialize;
@@ -40,8 +40,11 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>>
println!("Retrieved authentication code '{}'", auth_code);
- let access_token =
- request_access_token(settings.app_id, settings.secret_key, auth_code).await?;
+ let client = DeezerClient::new();
+
+ let access_token = client
+ .get_access_token(settings.app_id, settings.secret_key, auth_code)
+ .await?;
println!(
"Retrieved access token '{}' which expires in {} seconds",
@@ -49,13 +52,11 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>>
access_token.expires.as_secs()
);
- let client = DeezerClient::new(access_token);
-
- let me = client.get_me().await?;
+ let me = client.get_me(access_token.clone()).await?;
println!("{:#?}", me);
- let playlists = client.get_user_playlists(me.id).await?;
+ let playlists = client.get_user_playlists(me.id, access_token).await?;
println!("Playlists: {:#?}", playlists);