use serde_json::Value;
use solagent_core::SolanaAgentKit;
use std::error::Error;
pub async fn get_agent_by_ca(
agent: &SolanaAgentKit,
contract_address: &str,
interval: Option<u32>,
) -> Result<Value, Box<dyn Error>> {
let api_key = match agent.config.cookie_api_key.as_ref() {
Some(key) => key,
None => return Err("Missing Cookie API key in agent.config.cookie_api_key".into()),
};
let api_url = "https://api.cookie.fun/v2/agents/contractAddress";
let url = format!("{}/{}?interval=_{}Days", api_url, contract_address, interval.unwrap_or(7));
let client = reqwest::Client::new();
let response = client.get(&url).header("x-api-key", api_key).send().await?;
let json: Value = response.json().await?;
Ok(json)
}
pub async fn get_agent_by_name(
agent: &SolanaAgentKit,
twitter_name: &str,
interval: Option<u32>,
) -> Result<Value, Box<dyn Error>> {
let api_key = match agent.config.cookie_api_key.as_ref() {
Some(key) => key,
None => return Err("Missing Cookie API key in agent.config.cookie_api_key".into()),
};
let api_url = "https://api.cookie.fun/v2/agents/twitterUsername";
let url = format!("{}/{}?interval=_{}Days", api_url, twitter_name, interval.unwrap_or(7));
let client = reqwest::Client::new();
let response = client.get(&url).header("x-api-key", api_key).send().await?;
let json: Value = response.json().await?;
Ok(json)
}
pub async fn search_tweets(
agent: &SolanaAgentKit,
tweets: &str,
from: &str,
to: &str,
) -> Result<Value, Box<dyn Error>> {
let api_key = match agent.config.cookie_api_key.as_ref() {
Some(key) => key,
None => return Err("Missing Cookie API key in agent.config.cookie_api_key".into()),
};
let api_url = "https://api.cookie.fun/v1/hackathon/search";
let url = format!("{}/{}?from={}&to={}", api_url, tweets, from, to);
let client = reqwest::Client::new();
let response = client.get(&url).header("x-api-key", api_key).send().await?;
let json: Value = response.json().await?;
Ok(json)
}