Use Self instead of hard coded url
arn-the-long-beard opened this issue Β· comments
Hello π
In this method we do use :
pub async fn account_id(self) -> seed::fetch::Result<InstaAccount> {
let base_url = self.base_url.replace("EDGE", "?");
let url = base_url
+ "fields=instagram_business_account"
+ "&access_token="
+ &self.page_access_token;
let request = Request::new(url).method(Method::Get);
fetch(request).await?.json::<InstaAccount>().await
}
We do use the self.base_url
, but it is hard coded in this one.
pub async fn account_details(self) -> seed::fetch::Result<InstagramAccount> {
let base_url = "https://graph.facebook.com/v11.0/";
let self_data = self.clone();
let result = self.account_id().await;
if result.is_ok(){
let instagram_id = result.unwrap();
let mut url = base_url.to_owned()
+ &instagram_id.instagram_business_account.id.as_str();
// added required filed needed
let mut fields_count = Fields::default().fields.len();
let mut url_fields = "".to_string();
for (count, field) in Fields::default().fields.into_iter().enumerate() {
if count < fields_count - 1 {
url_fields = url_fields+ &field + ",";
} else {
url_fields= url_fields+ &field; // remove the comma in the last filed
}
}
url_fields = String::from(encode(url_fields.as_str()));
let mut request_url = url
+ "?fields="
+url_fields.as_str()
+ "&access_token="
+ &self_data.page_access_token;
log!(request_url);
let request = Request::new(request_url).method(Method::Get);
fetch(request).await?.json::<InstagramAccount>().await
}else {
let err = JsValue::from_str("The first get request call to fetch the instagram id was not successful,\
therefore the request to get instagram account failed. Try making the request again.");
Err(FetchError::RequestError(err)) // try to generate a customer
// error
}
Also the format of the code needs to be improved.
Is there a particular reason for this ? π
We forgot about this one. The code is not formatted neither.