From d7929e7e9fee879a28871c2195620869db291441 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 5 Sep 2022 17:57:28 +0200 Subject: feat: add authentication --- src/client.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/client.rs (limited to 'src/client.rs') diff --git a/src/client.rs b/src/client.rs new file mode 100644 index 0000000..5c6858b --- /dev/null +++ b/src/client.rs @@ -0,0 +1,50 @@ +//! Deezer client. +use std::error::Error; + +use serde::Deserialize; + +/// A user. +#[derive(Debug, Deserialize)] +pub struct User +{ + /// The user ID. + pub id: u32, + + /// The user name. + pub name: String, +} + +/// Deezer client. +#[derive(Default)] +pub struct DeezerClient +{ + client: reqwest::Client, + api_url: &'static str, +} + +impl DeezerClient +{ + /// Creates a new Deezer client. + #[must_use] + pub fn new() -> Self + { + Self { + client: reqwest::Client::new(), + api_url: "https://api.deezer.com", + } + } + + /// Returns the authenticated user. + pub async fn get_me(&self) -> Result> + { + let user = self + .client + .get(format!("{}/user/me", self.api_url)) + .send() + .await? + .json::() + .await?; + + Ok(user) + } +} -- cgit v1.2.3-18-g5258