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
mod response;
use response::{CommentRoot, CommentsRoot};

use crate::{
    utils::{http_get, http_get_with_params},
    VtClient, VtResult,
};

impl VtClient {
    pub fn get_comments(
        self,
        limit: Option<&str>,
        filter: Option<&str>,
        cursor: Option<&str>,
    ) -> VtResult<CommentsRoot> {
        //! Retrieves information about the latest comments.
        //!
        //! ## Example Usage
        //! ```rust
        //! use vt3::VtClient;
        //!
        //! let vt = VtClient::new("Your API Key");
        //! vt.get_comments(Some("10"), Some("tag%3Amalware"), None);
        //! ```
        let url = format!("{}/comments", self.endpoint);
        let mut query_params: Vec<(&str, &str)> = Vec::new();
        if let Some(l) = limit {
            query_params.push(("limit", l))
        }
        if let Some(f) = filter {
            query_params.push(("filter", f))
        }
        if let Some(c) = cursor {
            query_params.push(("cursor", c))
        }

        http_get_with_params(
            &self.api_key,
            &self.user_agent,
            &url,
            &query_params.as_slice(),
        )
    }

    pub fn get_comment(self, comment_id: &str) -> VtResult<CommentRoot> {
        //! Retrieve a comment information.
        //!
        //! ## Example Usage
        //! ```rust
        //! use vt3::VtClient;
        //!
        //! let vt = VtClient::new("Your API Key");
        //! let comment_id = "u-011915942db556bbab5137f761efe61fed2b00598fea900360b800b193a7bf31-d94d7c8a";
        //! vt.get_comment(comment_id);
        //! ```
        let url = format!("{}/comments/{}", self.endpoint, comment_id);
        http_get(&self.api_key, &self.user_agent, &url)
    }
}