Skip to content

Commit 6dd88fa

Browse files
Merge pull request #39 from Ringrev/feature/user_data
Feature/user data
2 parents 8e87766 + 9d645e0 commit 6dd88fa

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

examples/seed/src/lib.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ enum Msg {
7575
ConfigFetched(fetch::Result<Config>),
7676
GetAccount,
7777
GetAccountSuccess(Data<Accounts>),
78-
78+
GetMeDetails,
79+
GetMeDetailsSuccess(Me),
7980
AccessTokenInformation,
8081
AccessTokenInfoData(AccessTokenInformation),
8182

@@ -95,6 +96,7 @@ fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
9596
Msg::ConfigFetched(Err(fetch_error)) => error!("Config fetch failed! Be sure to have config.json at the root of your project with client_id and redirect_uri", fetch_error),
9697

9798
Msg::GetAccount => {
99+
orders.send_msg(Msg::GetMeDetails);
98100
if let Some(user_access_tokens) = model.user_tokens.clone() {
99101
let user_tokens = user_access_tokens;
100102
let client = Client::new(user_tokens, "".to_string());
@@ -111,6 +113,26 @@ fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
111113
}
112114
}
113115

116+
Msg::GetMeDetails => {
117+
if let Some(user_access_tokens) = model.user_tokens.clone() {
118+
let user_tokens = user_access_tokens;
119+
let user_token = user_tokens.long_lived_token.clone();
120+
let client = Client::new(user_tokens, "".to_string());
121+
orders.perform_cmd(async {
122+
// we are interested in the page long live token, therefore we called the long
123+
// live methed by passing "long_live_token" to the method
124+
client
125+
.me_by_short_or_long_live_token("short_live".to_string())
126+
.details()
127+
.await
128+
.map_or_else(Msg::ResponseFailed, Msg::GetMeDetailsSuccess)
129+
});
130+
}
131+
}
132+
Msg:: GetMeDetailsSuccess(resp) => {
133+
134+
}
135+
114136
Msg:: GetAccountSuccess(accounts) => {
115137
model.accounts = Some(accounts.clone());
116138
model.facebook.accounts= Some(accounts.clone());

src/graph/me/mod.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,26 @@ use serde::{Deserialize, Serialize};
1717

1818
use crate::graph::accounts::AccountsAPI;
1919
use crate::graph::data::Data;
20+
use crate::graph::prelude::Accounts;
2021

2122
/// This struct contain different data gotten as a response when a user sign in
2223
#[derive(Deserialize, Serialize)]
2324
pub struct Me {
2425
name: String,
25-
user_id: String,
26+
id: String,
27+
first_name:String,
28+
picture: FacebookPictureUserPicture,
29+
email:String,
30+
}
31+
32+
#[derive(Deserialize, Serialize)]
33+
pub struct PictureData{
34+
data: FacebookPictureUserPicture
35+
}
36+
37+
#[derive(Deserialize, Serialize)]
38+
pub struct FacebookPictureUserPicture {
39+
url: String,
2640
}
2741

2842
#[derive(Clone, Debug, Deserialize, Serialize)]
@@ -51,9 +65,11 @@ impl MeApi {
5165
/// retrieve a User's name and ID by using: The data in the response
5266
/// will depend on the "Fields" parameters you pass along the get request
5367
/// exmaple fields=id,name,email,picture.......
54-
pub async fn get(&self) -> seed::fetch::Result<Data<Me>> {
55-
log!(self.url);
56-
let request = Request::new(&self.url).method(Method::Get);
57-
fetch(request).await?.json::<Data<Me>>().await
68+
pub async fn details(&self) -> seed::fetch::Result<Me> {
69+
let fields = "&fields=id,name,picture, email,first_name,last_name,about,birthday,gender,link";
70+
let base_ur = self.url.replace("EDGE", "");
71+
let url = base_ur + fields;
72+
let request = Request::new(url).method(Method::Get);
73+
fetch(request).await?.json::<Me>().await
5874
}
5975
}

0 commit comments

Comments
 (0)