polyoxide_gamma/api/
user.rs1use polyoxide_core::{HttpClient, QueryBuilder, Request};
2use serde::{Deserialize, Serialize};
3
4use crate::{error::GammaError, types::Profile};
5
6#[derive(Clone)]
8pub struct User {
9 pub(crate) http_client: HttpClient,
10}
11
12impl User {
13 pub fn get(&self, signer_address: impl Into<String>) -> Request<UserResponse, GammaError> {
15 Request::new(self.http_client.clone(), "/public-profile")
16 .query("address", signer_address.into())
17 }
18
19 pub fn get_by_address(&self, address: impl Into<String>) -> Request<Profile, GammaError> {
26 Request::new(
27 self.http_client.clone(),
28 format!(
29 "/profiles/user_address/{}",
30 urlencoding::encode(&address.into())
31 ),
32 )
33 }
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(rename_all = "camelCase")]
39pub struct UserResponse {
40 #[serde(rename = "proxyWallet")]
42 pub proxy: Option<String>,
43 pub address: Option<String>,
45 pub id: Option<String>,
47 pub name: Option<String>,
49 pub created_at: Option<String>,
51 pub profile_image: Option<String>,
53 pub display_username_public: Option<bool>,
55 pub bio: Option<String>,
57 pub pseudonym: Option<String>,
59 pub x_username: Option<String>,
61 pub verified_badge: Option<bool>,
63 #[serde(default)]
65 pub users: Vec<UserInfo>,
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(rename_all = "camelCase")]
71pub struct UserInfo {
72 pub id: Option<String>,
74 #[serde(default)]
76 pub creator: bool,
77 #[serde(rename = "mod")]
79 #[serde(default)]
80 pub moderator: bool,
81}
82
83#[cfg(test)]
84mod tests {
85 use crate::Gamma;
86
87 fn gamma() -> Gamma {
88 Gamma::new().unwrap()
89 }
90
91 #[test]
92 fn test_get_by_address_accepts_str_and_string() {
93 let _r1 = gamma().user().get_by_address("0xdeadbeef");
94 let _r2 = gamma().user().get_by_address(String::from("0xdeadbeef"));
95 }
96}