123456789101112131415161718192021222324252627282930313233343536373839404142 |
- use chrono::NaiveDateTime;
- use serde::{Deserialize, Serialize};
-
- #[derive(Serialize, Deserialize, Debug)]
- pub struct OutgoingGist {
- pub title: String,
- pub body: String,
- pub formatted_body: String,
- pub filetype: String,
- }
-
- #[derive(Serialize, Deserialize, Debug)]
- pub struct IncomingGist {
- pub id: i32,
- pub title: String,
- pub body: String,
- pub created_at: NaiveDateTime,
- }
-
- #[derive(Debug)]
- pub struct ServerConfig {
- pub hostname: String,
- pub protocol: String,
- pub port: i32,
- }
-
- pub fn create_gist(
- gist: OutgoingGist,
- config: &ServerConfig,
- ) -> Result<IncomingGist, Box<std::error::Error>> {
- let client = reqwest::Client::new();
- let resp: IncomingGist = client
- .post(&format!(
- "{}://{}:{}/api/gists",
- config.protocol, config.hostname, config.port,
- ))
- .json(&gist)
- .send()?
- .json()?;
-
- Ok(resp)
- }
|