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
/// VirusTotal API v3
/// Clean & Simple interface to access the VirusTotal v3 REST api's
/// ## Usage
/// ```toml
/// [dependencies]
/// vt3 = "0.1.0"
/// ```
/// ```rust
/// use vt3;
///
/// let vt_client = vt3::VtClient::new("YOUR API KEY");
/// ```
///
mod file;
mod ip;
mod url;
mod domain;
mod enterprise;
pub use self::enterprise::retrohunt::SubmitJobRoot;

mod utils;
pub mod error;


#[derive(Copy, Clone)]
pub struct VtClient<'a> {
    api_key: &'a str,
    endpoint: &'a str,
    user_agent: &'a str,
}

impl<'a> VtClient<'a> {
    pub fn new(api_key: &'a str) -> Self {
        //! Creates a new VirusTotal API Client to access the VirusTotal REST API v3
        //!
        //! ## Example usage
        //! ```rust
        //! use vt3::VtClient;
        //!
        //! let vt_client = VtClient::new("YOUR API KEY");
        //! ```
        VtClient {
            api_key,
            endpoint: "https://www.virustotal.com/api/v3",
            user_agent: "rust-client/vt3-rs+https://github.com/marirs/vt3-rs",
        }
    }

    /// Sets a new user-agent that from the default
    pub fn user_agent(&'a mut self, user_agent: &'a str) -> &'a mut VtClient {
        self.user_agent = user_agent;
        self
    }
}

#[cfg(test)]
mod tests {
    use super::VtClient;

    #[test]
    fn test_vtclient() {
        let vt_client = VtClient::new("someapikey");
        assert_eq!(vt_client.api_key, "someapikey");
        assert_eq!(vt_client.endpoint, "https://www.virustotal.com/api/v3")
    }
}