1234567891011121314151617181920212223242526272829303132333435363738 |
- use chrono::NaiveDateTime;
- use serde::{Deserialize, Serialize};
-
- #[derive(Serialize, Deserialize, Debug)]
- pub struct OutgoingGist {
- pub title: String,
- pub body: String,
- pub filetype: Option<String>,
- }
-
- #[derive(Serialize, Deserialize, Debug)]
- pub struct IncomingGist {
- pub id: i32,
- pub title: String,
- pub body: String,
- pub created_at: NaiveDateTime,
- }
-
- pub fn create_gist(
- title: &str,
- body: &str,
- filetype: Option<&str>,
- ) -> Result<IncomingGist, Box<std::error::Error>> {
- let client = reqwest::Client::new();
- let gist = OutgoingGist {
- title: title.to_string(),
- body: body.to_string(),
- filetype: filetype.map(|ft| ft.to_string()),
- };
-
- let resp: IncomingGist = client
- .post("http://localhost:8000/api/gists")
- .json(&gist)
- .send()?
- .json()?;
-
- Ok(resp)
- }
|