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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
use crate::api_core::common::ServiceIdentifier;
use crate::api_core::Endpoint;
use serde::Serialize;
use std::collections::HashMap;
pub static URL_TYPE_POST: u8 = 0;
pub static URL_TYPE_FILE: u8 = 1;
pub static URL_TYPE_GALLERY: u8 = 2;
pub static URL_TYPE_WATCHABLE: u8 = 4;
pub static URL_TYPE_UNKNOWN: u8 = 5;
#[derive(Clone, Debug, Deserialize)]
pub struct GetUrlFilesResponse {
pub normalised_url: String,
pub url_file_statuses: Vec<UrlFileStatus>,
}
#[derive(Clone, Debug, Deserialize)]
pub struct UrlFileStatus {
pub status: u8,
pub hash: String,
pub note: String,
}
pub struct GetUrlFiles;
impl Endpoint for GetUrlFiles {
type Request = ();
type Response = GetUrlFilesResponse;
fn path() -> String {
String::from("add_urls/get_url_files")
}
}
#[derive(Clone, Debug, Deserialize)]
pub struct GetUrlInfoResponse {
pub normalised_url: String,
pub url_type: u8,
pub url_type_string: String,
pub match_name: String,
pub can_parse: bool,
}
pub struct GetUrlInfo;
impl Endpoint for GetUrlInfo {
type Request = ();
type Response = GetUrlInfoResponse;
fn path() -> String {
String::from("add_urls/get_url_info")
}
}
#[derive(Clone, Default, Debug, Serialize)]
pub struct AddUrlRequest {
pub url: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub destination_page_key: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub destination_page_name: Option<String>,
pub show_destination_page: bool,
pub service_names_to_additional_tags: HashMap<String, Vec<String>>,
pub service_keys_to_additional_tags: HashMap<String, Vec<String>>,
pub filterable_tags: Vec<String>,
}
#[derive(Default)]
pub struct AddUrlRequestBuilder {
inner: AddUrlRequest,
}
impl AddUrlRequestBuilder {
pub fn url<S: ToString>(mut self, url: S) -> Self {
self.inner.url = url.to_string();
self
}
pub fn destination_page_key<S: ToString>(mut self, page_key: S) -> Self {
self.inner.destination_page_key = Some(page_key.to_string());
self
}
pub fn destination_page_name<S: ToString>(mut self, page_name: S) -> Self {
self.inner.destination_page_name = Some(page_name.to_string());
self
}
pub fn show_destination_page(mut self, show: bool) -> Self {
self.inner.show_destination_page = show;
self
}
pub fn add_tags(mut self, service_id: ServiceIdentifier, mut tags: Vec<String>) -> Self {
let (service, mappings) = match service_id {
ServiceIdentifier::Name(name) => {
(name, &mut self.inner.service_names_to_additional_tags)
}
ServiceIdentifier::Key(key) => (key, &mut self.inner.service_keys_to_additional_tags),
};
if let Some(entry) = mappings.get_mut(&service) {
entry.append(&mut tags);
} else {
mappings.insert(service, tags);
}
self
}
pub fn add_filter_tags(mut self, mut filter_tags: Vec<String>) -> Self {
self.inner.filterable_tags.append(&mut filter_tags);
self
}
pub fn build(self) -> AddUrlRequest {
self.inner
}
}
#[derive(Clone, Debug, Deserialize)]
pub struct AddUrlResponse {
pub human_result_text: String,
pub normalised_url: String,
}
pub struct AddUrl;
impl Endpoint for AddUrl {
type Request = AddUrlRequest;
type Response = AddUrlResponse;
fn path() -> String {
String::from("add_urls/add_url")
}
}
#[derive(Clone, Debug, Serialize)]
pub struct AssociateUrlRequest {
pub urls_to_add: Vec<String>,
pub urls_to_delete: Vec<String>,
pub hashes: Vec<String>,
}
pub struct AssociateUrl;
impl Endpoint for AssociateUrl {
type Request = AssociateUrlRequest;
type Response = ();
fn path() -> String {
String::from("add_urls/associate_url")
}
}