simple_notion/
notion.rs

1#[derive(Default, Debug, Clone)]
2pub struct NotionURL {
3    pub base: String,
4    pub name: String,
5    pub is_https: bool,
6    pub data_base_id: String,
7    pub page_id: String,
8}
9
10impl NotionURL {
11    pub fn new(url: &str) -> Self {
12        
13        let mut tmp = Self::default();
14        
15        let mut slash_count = 0;
16        let mut buffer = String::new();
17        for i in url.chars() {
18            if i == '/' {
19                match slash_count {
20                    0 => {
21                        tmp.is_https = buffer.contains("https"); 
22                    }
23                    2 => {
24                        tmp.base = buffer.clone();
25                    }
26                    3 => {
27                        tmp.name = buffer.clone();
28                    }
29                    _ => (),
30                }
31                if slash_count != 4 {
32                    buffer = String::new();
33                    slash_count += 1;
34                }
35            } else {
36                buffer.push(i);
37            }
38        }
39        
40        if buffer.contains("?v=") {
41            for i in buffer.chars() {
42                if i == '?' {
43                    break;
44                } else {
45                    tmp.data_base_id.push(i);
46                }
47            }
48        } else {
49            tmp.page_id = buffer;
50        }
51        
52        tmp
53    }
54    
55    pub fn is_page(&self) -> bool {
56        !self.page_id.is_empty()
57    }
58    
59    pub fn is_data_base(&self) -> bool {
60        !self.is_page()
61    }
62}