gwelle 0.1.0

Lightweight Rust client for the Google Trends API
Documentation
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExploreRequest {
    pub keywords: Vec<String>,
    pub geo: String,
    pub timeframe: String,
    pub category: u32,
    pub property: String,
}

impl Default for ExploreRequest {
    fn default() -> Self {
        Self {
            keywords: vec![],
            geo: "".to_string(),
            timeframe: "today 12-m".to_string(),
            category: 0,
            property: "".to_string(),
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExploreTokens {
    pub interest_over_time: Option<WidgetToken>,
    pub interest_by_region: Option<WidgetToken>,
    pub related_topics: Option<WidgetToken>,
    pub related_queries: Option<WidgetToken>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WidgetToken {
    pub token: String,
    pub request: serde_json::Value,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InterestOverTime {
    pub timeline_data: Vec<TimelinePoint>,
    pub averages: Vec<u32>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimelinePoint {
    pub time: String,
    pub formatted_time: String,
    pub values: Vec<u32>,
    pub is_partial: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InterestByRegion {
    pub geo_map_data: Vec<GeoPoint>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GeoPoint {
    #[serde(rename = "geoCode")]
    pub geo_code: String,
    #[serde(rename = "geoName")]
    pub geo_name: String,
    pub values: Vec<u32>,
    pub coordinates: Option<Coordinates>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Coordinates {
    pub lat: f64,
    pub lng: f64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum GeoResolution {
    Country,
    Region,
    City,
    DMA,
}

impl GeoResolution {
    pub fn as_str(&self) -> &'static str {
        match self {
            GeoResolution::Country => "COUNTRY",
            GeoResolution::Region => "REGION",
            GeoResolution::City => "CITY",
            GeoResolution::DMA => "DMA",
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RelatedQueries {
    pub top: Vec<RelatedItem>,
    pub rising: Vec<RelatedItem>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RelatedItem {
    pub query: String,
    pub value: String,
    pub link: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RealtimeTrend {
    pub title: Vec<String>,
    pub entity_names: Vec<String>,
    pub articles: Vec<TrendArticle>,
    pub image: Option<TrendImage>,
    pub share_url: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TrendArticle {
    #[serde(rename = "articleTitle")]
    pub article_title: String,
    pub url: String,
    pub source: String,
    #[serde(rename = "timeAgo")]
    pub time_ago: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TrendImage {
    #[serde(rename = "newsUrl")]
    pub news_url: String,
    pub source: String,
    #[serde(rename = "imgUrl")]
    pub img_url: String,
}