1pub mod auth;
2pub mod follow;
3pub mod profile;
4
5pub struct LensClient {
6 pub queries: crate::graphql::queries::Queries,
7 pub endpoint: String,
8 pub chain: crate::Chain,
9 pub net: crate::Net,
10 pub access_token: Option<String>,
11 pub refresh_token: Option<String>,
12}
13
14impl LensClient {
16 pub fn new(chain: crate::Chain, net: crate::Net) -> LensClient {
23 match chain {
24 crate::Chain::Polygon => match net {
25 crate::Net::Mumbai => LensClient {
26 queries: crate::graphql::queries::Queries::new(),
27 endpoint: String::from("https://api-mumbai.lens.dev"),
28 chain: chain,
29 net: net,
30 access_token: None,
31 refresh_token: None,
32 },
33 crate::Net::Main => LensClient {
34 queries: crate::graphql::queries::Queries::new(),
35 endpoint: String::from("https://api.lens.dev"),
36 chain: chain,
37 net: net,
38 access_token: None,
39 refresh_token: None,
40 },
41 },
42 }
43 }
44
45 pub fn get_default_profile_by_address(
51 &self,
52 address: String,
53 ) -> Result<profile::default::Profile, String> {
54 let profile = crate::methods::profile::get_default_profile_by_address(self, address);
55 profile
56 }
57
58 pub fn get_profiles_by_address(
64 &self,
65 address: String,
66 ) -> Result<profile::AddressProfiles, String> {
67 let profile = crate::methods::profile::get_profiles_by_address(self, address);
68 profile
69 }
70
71 pub fn does_follow(
78 &self,
79 address: String,
80 followee: String,
81 ) -> Result<follow::DFollow, String> {
82 let follow = crate::methods::follow::does_follow(self, address, followee);
83 follow
84 }
85
86 pub fn get_following(
93 &self,
94 address: String,
95 limit: u64,
96 ) -> Result<follow::following::FollowingData, String> {
97 let follow = crate::methods::follow::get_following(self, address, limit);
98 follow
99 }
100
101 pub fn get_followers(
108 &self,
109 profile_id: String,
110 limit: u64,
111 ) -> Result<follow::followers::FollowersData, String> {
112 let follow = crate::methods::follow::get_followers_by_profile_id(self, profile_id, limit);
113 follow
114 }
115
116 pub fn challenge(&self, address: String) -> Result<auth::AuthChallenge, String> {
122 let auth = crate::methods::auth::challenge(self, address);
123 auth
124 }
125
126 pub fn login(
133 &mut self,
134 address: String,
135 signature: String,
136 ) -> Result<auth::login::Login, String> {
137 let auth = crate::methods::auth::login(self, address, signature);
138 self.access_token = Some(auth.clone().unwrap().data.authenticate.access_token);
139 self.refresh_token = Some(auth.clone().unwrap().data.authenticate.refresh_token);
140
141 auth
142 }
143
144 pub fn create_profile(
150 &self,
151 handle: String,
152 ) -> Result<crate::lens::profile::create::CreateProfileData, String> {
153 let created_profile = crate::methods::profile::create_profile(
154 self,
155 handle,
156 crate::lens::follow::FollowModule {
157 follow_type: crate::lens::follow::FollowModuleType::Free,
158 currency: None,
159 value: None,
160 recipient: None,
161 },
162 );
163 created_profile
164 }
165
166 pub fn make_request(
167 &self,
168 q: crate::graphql::Query,
169 headers: Option<Vec<serde_json::Value>>,
170 ) -> Result<surf::Response, Option<String>> {
171 let mut res = Err(None);
172 let u = self.endpoint.clone();
173 async_std::task::block_on(async {
174 let mut p = surf::post(u);
175 if headers.is_some() {
176 let hh = headers.unwrap();
177 for h in hh {
178 p = p.header(h["k"].as_str().unwrap(), h["v"].as_str().unwrap());
179 }
180 }
181 let request = p.body_json(&q).unwrap();
182 let rr = request.send().await.unwrap();
183 res = Ok(rr);
184 });
185 res
186 }
187}