1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#[allow(dead_code)]
#[allow(unused_variables)]
pub mod paste {
use serde::Deserialize;
type Error = Box<dyn std::error::Error>;
type Result<T, E = Error> = std::result::Result<T, E>;
const ENDPOINT: &str = "https://paste.myst.rs/";
const BASE_ENDPOINT: &str = "https://paste.myst.rs/api/v2/";
const GET_ENDPOINT: &str = "https://paste.myst.rs/api/v2/paste/";
pub fn get_paste(id: &str) -> Result<PasteInfo, reqwest::Error> {
let info: PasteInfo = reqwest::blocking::get(&parse_url(id))?.json()?;
Ok(info)
}
pub fn get_private_paste(id: &str, auth_token: &str) -> Result<PasteInfo, reqwest::Error> {
let info: PasteInfo = reqwest::blocking::Client::builder()
.build()?
.get(&parse_url(id))
.header("Authorization", auth_token)
.send()?
.json()?;
Ok(info)
}
pub async fn get_paste_async(id: &str) -> Result<PasteInfo, reqwest::Error> {
let info: PasteInfo = reqwest::get(&parse_url(id)).await?.json().await?;
Ok(info)
}
pub async fn get_private_paste_async(
id: &str,
auth_token: &str,
) -> Result<PasteInfo, reqwest::Error> {
let info: PasteInfo = reqwest::Client::builder()
.build()?
.get(&parse_url(&id))
.header("Authorization", auth_token)
.send()
.await?
.json()
.await?;
Ok(info)
}
fn parse_url(id: &str) -> String {
return GET_ENDPOINT.to_owned() + &id;
}
#[derive(Deserialize)]
#[allow(dead_code)]
#[allow(non_snake_case)]
pub struct PasteInfo {
pub _id: String,
pub ownerId: String,
pub title: String,
pub createdAt: u64,
pub expiresIn: String,
pub deletesAt: u64,
pub stars: u64,
pub isPrivate: bool,
pub isPublic: bool,
pub tags: Vec<String>,
pub pasties: Vec<PastyObject>,
pub edits: Vec<EditObject>,
}
#[derive(Deserialize)]
#[allow(dead_code)]
#[allow(non_snake_case)]
pub struct PastyObject {
pub _id: String,
pub language: String,
pub title: String,
pub code: String,
}
#[derive(Deserialize)]
#[allow(dead_code)]
#[allow(non_snake_case)]
pub struct EditObject {
pub _id: String,
pub editId: String,
pub editType: i32,
pub metadata: Vec<String>,
pub edit: String,
pub editedAt: i32,
}
}