Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion examples/seed/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ enum Msg {
ConfigFetched(fetch::Result<Config>),
GetAccount,
GetAccountSuccess(Data<Accounts>),

GetMeDetails,
GetMeDetailsSuccess(Me),
AccessTokenInformation,
AccessTokenInfoData(AccessTokenInformation),

Expand All @@ -95,6 +96,7 @@ fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
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),

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

Msg::GetMeDetails => {
if let Some(user_access_tokens) = model.user_tokens.clone() {
let user_tokens = user_access_tokens;
let user_token = user_tokens.long_lived_token.clone();
let client = Client::new(user_tokens, "".to_string());
orders.perform_cmd(async {
// we are interested in the page long live token, therefore we called the long
// live methed by passing "long_live_token" to the method
client
.me_by_short_or_long_live_token("short_live".to_string())
.details()
.await
.map_or_else(Msg::ResponseFailed, Msg::GetMeDetailsSuccess)
});
}
}
Msg:: GetMeDetailsSuccess(resp) => {

}

Msg:: GetAccountSuccess(accounts) => {
model.accounts = Some(accounts.clone());
model.facebook.accounts= Some(accounts.clone());
Expand Down
26 changes: 21 additions & 5 deletions src/graph/me/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,26 @@ use serde::{Deserialize, Serialize};

use crate::graph::accounts::AccountsAPI;
use crate::graph::data::Data;
use crate::graph::prelude::Accounts;

/// This struct contain different data gotten as a response when a user sign in
#[derive(Deserialize, Serialize)]
pub struct Me {
name: String,
user_id: String,
id: String,
first_name:String,
picture: FacebookPictureUserPicture,
email:String,
}

#[derive(Deserialize, Serialize)]
pub struct PictureData{
data: FacebookPictureUserPicture
}

#[derive(Deserialize, Serialize)]
pub struct FacebookPictureUserPicture {
url: String,
}

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