44 lines
1.4 KiB
Rust
44 lines
1.4 KiB
Rust
use std::collections::HashMap;
|
|
use reqwest::header::HeaderMap;
|
|
use crate::models::{CookieRequest, Submission, SubmissionRequest};
|
|
|
|
const FA_API_BASE_ORIGIN: &str = "https://furaffinity-api.herokuapp.com";
|
|
|
|
pub struct Client {
|
|
request_client: reqwest::Client,
|
|
cookies: HashMap<String, String>
|
|
}
|
|
|
|
impl Client {
|
|
pub fn new(cookies: HashMap<String, String>) -> anyhow::Result<Self> {
|
|
let headers = HeaderMap::from_iter(vec![
|
|
(reqwest::header::ACCEPT, "application/json".try_into()?),
|
|
(reqwest::header::CONTENT_TYPE, "application/json".try_into()?)
|
|
].into_iter());
|
|
let request_client = reqwest::ClientBuilder::new()
|
|
.default_headers(headers)
|
|
.build()?;
|
|
|
|
Ok(Self {
|
|
request_client,
|
|
cookies
|
|
})
|
|
}
|
|
|
|
pub async fn get_submission<S>(&mut self, submission_id: S) -> anyhow::Result<Submission> where S: Into<String> {
|
|
let url = format!("{FA_API_BASE_ORIGIN}/submission/{}", submission_id.into());
|
|
let res = self.request_client
|
|
.post(url)
|
|
.json(&SubmissionRequest {
|
|
cookies: vec![
|
|
],
|
|
bbcode: false
|
|
})
|
|
.send().await?;
|
|
|
|
println!("{:?}", res.status());
|
|
//File::create("./out.json")?.write(res.text().await?.as_bytes())?;
|
|
let submission: Submission = res.json().await?;
|
|
Ok(submission)
|
|
}
|
|
}
|