[−][src]Struct soundcloud::Client
Implementations
impl Client
[src]
pub fn new(client_id: &str) -> Client
[src]
Constructs a new Client
with the provided client_id
.
Examples
use soundcloud::Client; let client = Client::new(env!("SOUNDCLOUD_CLIENT_ID"));
pub fn client_id(&self) -> &str
[src]
Returns the client id.
pub fn authenticate_with_token(&mut self, token: String)
[src]
pub async fn get<'_, '_, I, K, V>(
&'_ self,
path: &'_ str,
params: Option<I>
) -> Result<Response> where
I: IntoIterator,
I::Item: Borrow<(K, V)>,
K: AsRef<str>,
V: AsRef<str>,
[src]
&'_ self,
path: &'_ str,
params: Option<I>
) -> Result<Response> where
I: IntoIterator,
I::Item: Borrow<(K, V)>,
K: AsRef<str>,
V: AsRef<str>,
Creates and sends a HTTP GET request to the API endpoint.
A client_id
parameter will automatically be added to the request.
Returns the HTTP response on success, an error otherwise.
Examples
use std::io::Read; use soundcloud::Client; #[tokio::main] async fn main() { let client = Client::new(env!("SOUNDCLOUD_CLIENT_ID")); let response = client.get("/resolve", Some(&[("url", "https://soundcloud.com/firepowerrecs/afk-shellshock-kamikaze-promo-mix-lock-load-series-vol-20")])).await; let buffer = response.unwrap().text().await.unwrap(); assert!(!buffer.is_empty()); }
pub async fn stream<'_, '_, W: AsyncWrite + Unpin>(
&'_ self,
track: &'_ Track,
__arg2: W
) -> Result<u64>
[src]
&'_ self,
track: &'_ Track,
__arg2: W
) -> Result<u64>
Starts streaming the track provided in the track's stream_url
to the writer
if the track
is streamable via the API.
Returns: Number of bytes written if the track was streamed successfully, an error otherwise.
Examples
use std::path::Path; use soundcloud::Client; use tokio::fs::File; use tokio_util::compat::Tokio02AsyncWriteCompatExt; #[tokio::main] async fn main() { let client = Client::new(env!("SOUNDCLOUD_CLIENT_ID")); let path = Path::new("hi.mp3"); let track = client.tracks().id(263801976).get().await.unwrap(); let mut outfile = File::create(path).await.unwrap().compat_write(); let num_bytes = client.stream(&track, &mut outfile).await.unwrap(); assert!(num_bytes > 0); }
pub async fn download<'_, '_, W: AsyncWrite + Unpin>(
&'_ self,
track: &'_ Track,
__arg2: W
) -> Result<u64>
[src]
&'_ self,
track: &'_ Track,
__arg2: W
) -> Result<u64>
Starts downloading the track provided in the tracks download_url
to the writer
if the track
is downloadable via the API.
Returns: Number of bytes written if the track was downloaded successfully, an error otherwise.
Examples
use std::path::Path; use soundcloud::Client; use tokio::fs::File; use tokio_util::compat::Tokio02AsyncWriteCompatExt; #[tokio::main] async fn main() { let client = Client::new(env!("SOUNDCLOUD_CLIENT_ID")); let path = Path::new("hi.mp3"); let track = client.tracks().id(263801976).get().await.unwrap(); let mut outfile = File::create(path).await.unwrap().compat_write(); let num_bytes = client.download(&track, &mut outfile).await.unwrap(); assert!(num_bytes > 0); }
pub async fn resolve<'_, '_>(&'_ self, url: &'_ str) -> Result<Url>
[src]
Resolves any soundcloud resource and returns it as a Url
.
pub fn track(&self, id: usize) -> SingleTrackRequestBuilder
[src]
Returns a builder for a single track-by-id request.
Examples
use soundcloud::Client; #[tokio::main] async fn main() { let client = Client::new(env!("SOUNDCLOUD_CLIENT_ID")); let track = client.track(262681089).get().await; assert_eq!(track.unwrap().id, 262681089); }
pub fn tracks(&self) -> TrackRequestBuilder
[src]
Returns a builder for searching tracks with multiple criteria.
Examples
use soundcloud::Client; #[tokio::main] async fn main() { let client = Client::new(env!("SOUNDCLOUD_CLIENT_ID")); let tracks = client.tracks().genres(Some(["HipHop"])).get().await; assert!(tracks.unwrap().len() > 0); }
pub fn playlist(&self, id: usize) -> SinglePlaylistRequestBuilder
[src]
Returns a builder for a single playlist-by-id request.
Examples
use soundcloud::Client; #[tokio::main] async fn main() { let client = Client::new(env!("SOUNDCLOUD_CLIENT_ID")); let playlist = client.playlist(965640322).get().await; assert_eq!(playlist.unwrap().id, 965640322); }
pub fn playlists(&self) -> PlaylistRequestBuilder
[src]
Returns a builder for searching playlists with multiple criteria.
Examples
use soundcloud::Client; #[tokio::main] async fn main() { let client = Client::new(env!("SOUNDCLOUD_CLIENT_ID")); let playlists = client.playlists().query("Monstercat").get().await; assert!(playlists.unwrap().len() > 0); }
pub async fn my_playlists<'_>(&'_ self) -> Result<Vec<Playlist>>
[src]
Returns list of playlists of the authenticated user
pub fn users(&self) -> UserRequestBuilder
[src]
Returns a builder for searching users
pub async fn likes<'_>(&'_ self) -> Result<Vec<Track>>
[src]
pub fn user(&self, user_id: usize) -> SingleUserRequestBuilder
[src]
Returns details about the given user
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,