-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from Rigellute/ramsay-support-for-async-await-5
Add async/await
- Loading branch information
Showing
75 changed files
with
4,508 additions
and
1,998 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ | |
.tern-port | ||
cmake-build-debug | ||
*/.test_token | ||
Cargo.lock | ||
Cargo.lock | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,24 @@ | ||
extern crate rspotify; | ||
|
||
use futures; | ||
use rspotify::client::Spotify; | ||
use rspotify::oauth2::SpotifyClientCredentials; | ||
use tokio; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let mut handlers = vec![]; | ||
for _ in 0..20 { | ||
let handler = tokio::spawn(async move { | ||
// Set client_id and client_secret in .env file or | ||
// export CLIENT_ID="your client_id" | ||
// export CLIENT_SECRET="secret" | ||
let client_credential = SpotifyClientCredentials::default().build(); | ||
// Set client_id and client_secret in .env file or | ||
// export CLIENT_ID="your client_id" | ||
// export CLIENT_SECRET="secret" | ||
let client_credential = SpotifyClientCredentials::default().build(); | ||
|
||
// Or set client_id and client_secret explictly | ||
// let client_credential = SpotifyClientCredentials::default() | ||
// .client_id("this-is-my-client-id") | ||
// .client_secret("this-is-my-client-secret") | ||
// .build(); | ||
let spotify = Spotify::default() | ||
.client_credentials_manager(client_credential) | ||
.build(); | ||
let birdy_uri = "spotify:artist:2WX2uTcsvV5OnS0inACecP"; | ||
let artist = spotify.artist(birdy_uri).await; | ||
println!("{:?}", artist); | ||
return; | ||
}); | ||
handlers.push(handler); | ||
} | ||
futures::future::join_all(handlers).await; | ||
// Or set client_id and client_secret explictly | ||
// let client_credential = SpotifyClientCredentials::default() | ||
// .client_id("this-is-my-client-id") | ||
// .client_secret("this-is-my-client-secret") | ||
// .build(); | ||
let spotify = Spotify::default() | ||
.client_credentials_manager(client_credential) | ||
.build(); | ||
let birdy_uri = "spotify:artist:2WX2uTcsvV5OnS0inACecP"; | ||
let artist = spotify.artist(birdy_uri).await; | ||
println!("{:?}", artist); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
extern crate rspotify; | ||
|
||
use rspotify::client::Spotify; | ||
use rspotify::oauth2::SpotifyClientCredentials; | ||
use rspotify::senum::Country; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
// Set client_id and client_secret in .env file or | ||
// export CLIENT_ID="your client_id" | ||
// export CLIENT_SECRET="secret" | ||
let client_credential = SpotifyClientCredentials::default().build(); | ||
|
||
// Or set client_id and client_secret explictly | ||
// let client_credential = SpotifyClientCredentials::default() | ||
// .client_id("this-is-my-client-id") | ||
// .client_secret("this-is-my-client-secret") | ||
// .build(); | ||
println!( | ||
"{:?}:{:?}:{:?}", | ||
&client_credential.client_id, | ||
&client_credential.client_secret, | ||
&client_credential.get_access_token().await | ||
); | ||
let spotify = Spotify::default() | ||
.client_credentials_manager(client_credential) | ||
.build(); | ||
let birdy_uri = "spotify:artist:2WX2uTcsvV5OnS0inACecP"; | ||
let tracks = spotify | ||
.artist_top_tracks(birdy_uri, Country::UnitedStates) | ||
.await; | ||
println!("{:?}", tracks.unwrap()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
extern crate chrono; | ||
extern crate rspotify; | ||
|
||
use rspotify::client::Spotify; | ||
use rspotify::oauth2::{SpotifyClientCredentials, SpotifyOAuth}; | ||
use rspotify::senum::Country; | ||
use rspotify::util::get_token; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
// Set client_id and client_secret in .env file or | ||
// export CLIENT_ID="your client_id" | ||
// export CLIENT_SECRET="secret" | ||
// export REDIRECT_URI=your-direct-uri | ||
|
||
// Or set client_id, client_secret,redirect_uri explictly | ||
// let oauth = SpotifyOAuth::default() | ||
// .client_id("this-is-my-client-id") | ||
// .client_secret("this-is-my-client-secret") | ||
// .redirect_uri("http://localhost:8888/callback") | ||
// .build(); | ||
|
||
let mut oauth = SpotifyOAuth::default().scope("user-follow-read").build(); | ||
match get_token(&mut oauth).await { | ||
Some(token_info) => { | ||
let client_credential = SpotifyClientCredentials::default() | ||
.token_info(token_info) | ||
.build(); | ||
// Or set client_id and client_secret explictly | ||
// let client_credential = SpotifyClientCredentials::default() | ||
// .client_id("this-is-my-client-id") | ||
// .client_secret("this-is-my-client-secret") | ||
// .build(); | ||
let spotify = Spotify::default() | ||
.client_credentials_manager(client_credential) | ||
.build(); | ||
|
||
let categories = spotify | ||
.categories(None, Some(Country::UnitedStates), 10, 0) | ||
.await; | ||
println!("{:?}", categories); | ||
} | ||
None => println!("auth failed"), | ||
}; | ||
} |
Oops, something went wrong.