1use reqwest::blocking::Client;
2use std::time::Duration;
3use teaql_tool_core::{Result, TeaQLToolError};
4
5pub struct HttpTool {
6 client: Client,
7}
8
9impl HttpTool {
10 pub fn new() -> Self {
11 let client = Client::builder()
12 .timeout(Duration::from_secs(10))
13 .build()
14 .unwrap();
15 Self { client }
16 }
17
18 pub fn get(&self, url: &str) -> Result<String> {
19 self.client
20 .get(url)
21 .send()
22 .map_err(|e| TeaQLToolError::ExecutionError(format!("Http get failed: {}", e)))?
23 .text()
24 .map_err(|e| TeaQLToolError::ExecutionError(format!("Http read text failed: {}", e)))
25 }
26}
27
28impl Default for HttpTool {
29 fn default() -> Self {
30 Self::new()
31 }
32}