snm_brightdata_client/
client.rs

1// src/client.rs - Cleaned up version (removed duplicate tool execution)
2use crate::{config::BrightDataConfig, error::BrightDataError};
3use reqwest::Client;
4use serde_json::Value;
5use anyhow::{Result, anyhow};
6
7pub struct BrightDataClient {
8    config: BrightDataConfig,
9    client: Client,
10}
11
12impl BrightDataClient {
13    pub fn new(config: BrightDataConfig) -> Self {
14        Self {
15            config,
16            client: Client::new(),
17        }
18    }
19
20    /// Direct BrightData API call for basic scraping
21    pub async fn get(&self, target_url: &str) -> Result<Value, BrightDataError> {
22        let payload = serde_json::json!({
23            "url": target_url,
24        });
25
26        let res = self
27            .client
28            .post(&self.config.endpoint)
29            .header("Authorization", format!("Bearer {}", self.config.token))
30            .json(&payload)
31            .send()
32            .await?
33            .json::<Value>()
34            .await?;
35
36        Ok(res)
37    }
38}