Struct rtrend::client::Client

source ·
pub struct Client {
    pub client: Client,
    pub cookie: Cookie,
    pub country: Country,
    pub keywords: Keywords,
    pub lang: Lang,
    pub property: Property,
    pub time: String,
    pub category: Category,
    pub response: Value,
}

Fields§

§client: Client§cookie: Cookie§country: Country§keywords: Keywords§lang: Lang§property: Property§time: String§category: Category§response: Value

Implementations§

source§

impl Client

source

pub fn new(keywords: Keywords, country: Country) -> Self

Create a new Client.

Returns a Client.

Example
let keywords = Keywords::new(vec!["rust"]);
let country = Country::FR;

let client = Client::new(keywords, country);
Panics

Will panic if the client can’t be built. This can happen if the cookie can not be set or if the request time out.

Examples found in repository?
examples/related_topics.rs (line 7)
3
4
5
6
7
8
9
10
11
fn main() {
    let keywords = Keywords::new(vec!["Pasta"]);
    let country = Country::IT;

    let client = Client::new(keywords, country).build();

    let search_interest = RelatedTopics::new(client).get();
    println!("{}", search_interest);
}
More examples
Hide additional examples
examples/related_queries.rs (line 7)
3
4
5
6
7
8
9
10
11
fn main() {
    let keywords = Keywords::new(vec!["Cinema"]);
    let country = Country::ALL;

    let client = Client::new(keywords, country).build();

    let search_interest = RelatedQueries::new(client).get();
    println!("{}", search_interest);
}
examples/search_interest.rs (line 7)
3
4
5
6
7
8
9
10
11
fn main() {
    let keywords = Keywords::new(vec!["Cinema"]);
    let country = Country::ALL;

    let client = Client::new(keywords, country).build();

    let search_interest = SearchInterest::new(client).get();
    println!("{}", search_interest);
}
examples/region_interest.rs (line 7)
3
4
5
6
7
8
9
10
11
fn main() {
    let country = Country::US;
    let keywords = Keywords::new(vec!["Instagram", "Facebook"]);
    
    let client = Client::new(keywords, country).build();
    
    let region_interest = RegionInterest::new(client).get();
    println!("{}", region_interest);
}
examples/select_keyword.rs (line 7)
3
4
5
6
7
8
9
10
11
fn main() {
    let country = Country::US;
    let keywords = Keywords::new(vec!["Instagram", "Facebook", "Pinterest"]);
    
    let client = Client::new(keywords, country).build();
    
    let region_interest_pinterest = RegionInterest::new(client).get_for("Pinterest");
    println!("{}", region_interest_pinterest);
}
examples/simple.rs (line 7)
3
4
5
6
7
8
9
10
11
12
fn main(){
    let country = Country::US;
    let keywords = Keywords::new(vec!["Instagram","Facebook"]);
    
    let client = Client::new(keywords, country).build();
    
    // Then select the data you want. The interest of your keywords filtered by region for example:
    let region_interest = RegionInterest::new(client).get();
    println!("{}", region_interest);
}
source

pub fn with_keywords(self, keywords: Keywords) -> Self

Set keywords and replace the ones setup during the client creation.

Returns a client instance.

Example
let keywords = Keywords::new(vec!["rust"]);
let country = Country::FR;
let client = Client::new(keywords, country);

// ...

let new_keywords = Keywords::new(vec!["python", "c++"]);
let modified_client = client.with_keywords(new_keywords);
source

pub fn with_lang(self, lang: Lang) -> Self

Set in which langage the response will be. The input need to be set in lowercase.

By default, the response is set to english (en).

Returns a client instance.

Example
let keywords = Keywords::new(vec!["rust"]);
let country = Country::ALL;
let lang = Lang::FR;

// Set response langage to french
let client = Client::new(keywords, country).with_lang(lang);
Examples found in repository?
examples/filter.rs (line 12)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fn main() {
    let keywords = Keywords::new(vec!["Pasta"]);
    let country = Country::IT;

    // Set response lang to french and search on Google Image
    let lang = Lang::FR;
    let property = Property::Web;

    let client = Client::new(keywords, country)
        .with_lang(lang)
        .with_property(property)
        .with_category(Category::FoodAndDrink)
        .build();
    let related_queries = RelatedQueries::new(client).get();
    println!("{}", related_queries);
}
source

pub fn with_category(self, category: Category) -> Self

Set the category google trend will search on.

By default, any category is set.

Returns a client instance.

Example
let keywords = Keywords::new(vec!["hacking"]);
let country = Country::ALL;
let category = Category::EngineeringAndTechnology;

// Set category to "Engineering & Technology"
let client = Client::new(keywords, country).with_category(category);
Examples found in repository?
examples/filter.rs (line 14)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fn main() {
    let keywords = Keywords::new(vec!["Pasta"]);
    let country = Country::IT;

    // Set response lang to french and search on Google Image
    let lang = Lang::FR;
    let property = Property::Web;

    let client = Client::new(keywords, country)
        .with_lang(lang)
        .with_property(property)
        .with_category(Category::FoodAndDrink)
        .build();
    let related_queries = RelatedQueries::new(client).get();
    println!("{}", related_queries);
}
source

pub fn with_property(self, property: Property) -> Self

Set the property google trend will search on.

By default, the search will be made on Google Search (web) The available property are :

  • web, images, news, froogle (Google Shopping), youtube

Returns a client instance.

Example
let keywords = Keywords::new(vec!["vlog"]);
let country = Country::ALL;

// The response will be retrieve from youtube data
let property = Property::Youtube;

let client = Client::new(keywords, country).with_property(property);
Examples found in repository?
examples/filter.rs (line 13)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fn main() {
    let keywords = Keywords::new(vec!["Pasta"]);
    let country = Country::IT;

    // Set response lang to french and search on Google Image
    let lang = Lang::FR;
    let property = Property::Web;

    let client = Client::new(keywords, country)
        .with_lang(lang)
        .with_property(property)
        .with_category(Category::FoodAndDrink)
        .build();
    let related_queries = RelatedQueries::new(client).get();
    println!("{}", related_queries);
}
source

pub fn with_period(self, period: impl ToString) -> Self

Set the period google trend will search on.

Period are preset set by Google Trend. By default, the search will be made on 1 year (starting by today).

Returns a client instance.

Example
let keywords = Keywords::new(vec!["vlog"]);
let country = Country::ALL;

// response will concern data from this week
let client = Client::new(keywords, country).with_period(Period::SevenDay);
source

pub fn with_date(self, start_date: NaiveDate, end_date: NaiveDate) -> Self

Set the “start date” and “end date” google trend will search on. By default, the search will be made on 1 year (starting by today).

Returns a client instance.

Example
let keywords = Keywords::new(vec!["vlog"]);
let country = Country::ALL;

// response will concern data from April 25, 2020 to July 30, 2021
let start_date: NaiveDate = NaiveDate::from_ymd_opt(2017, 4, 25).unwrap();
let end_date: NaiveDate = NaiveDate::from_ymd_opt(2020, 7, 30).unwrap();

let client = Client::new(keywords, country).with_date(start_date, end_date);
source

pub fn with_filter( self, category: Category, property: Property, period: String, lang: Lang ) -> Self

Allow to set options in one shot.

For now I don’t think it’s very useful but if it is, I will make it public

Returns a client instance.

Example
let keywords = Keywords::new(vec!["cat"]);
let country = Country::ALL;

let client = Client::new(keywords, country).with_filter(
    Category::PetsAndAnimals,
    Property::Images,           // Search on Google Images
    "today 3-m".to_string(),    // 90 previous days
    Lang::IT                    // in italian
);
source

pub fn build(self) -> Self

Build client and send request.

A response will be retrieve and available through the response field. This field will serve for making next requests.

Example
let keywords = Keywords::new(vec!["Cat"]);
let country = Country::US;

let client = Client::new(keywords, country).build();

println!("{}", client.response);
Examples found in repository?
examples/related_topics.rs (line 7)
3
4
5
6
7
8
9
10
11
fn main() {
    let keywords = Keywords::new(vec!["Pasta"]);
    let country = Country::IT;

    let client = Client::new(keywords, country).build();

    let search_interest = RelatedTopics::new(client).get();
    println!("{}", search_interest);
}
More examples
Hide additional examples
examples/related_queries.rs (line 7)
3
4
5
6
7
8
9
10
11
fn main() {
    let keywords = Keywords::new(vec!["Cinema"]);
    let country = Country::ALL;

    let client = Client::new(keywords, country).build();

    let search_interest = RelatedQueries::new(client).get();
    println!("{}", search_interest);
}
examples/search_interest.rs (line 7)
3
4
5
6
7
8
9
10
11
fn main() {
    let keywords = Keywords::new(vec!["Cinema"]);
    let country = Country::ALL;

    let client = Client::new(keywords, country).build();

    let search_interest = SearchInterest::new(client).get();
    println!("{}", search_interest);
}
examples/region_interest.rs (line 7)
3
4
5
6
7
8
9
10
11
fn main() {
    let country = Country::US;
    let keywords = Keywords::new(vec!["Instagram", "Facebook"]);
    
    let client = Client::new(keywords, country).build();
    
    let region_interest = RegionInterest::new(client).get();
    println!("{}", region_interest);
}
examples/select_keyword.rs (line 7)
3
4
5
6
7
8
9
10
11
fn main() {
    let country = Country::US;
    let keywords = Keywords::new(vec!["Instagram", "Facebook", "Pinterest"]);
    
    let client = Client::new(keywords, country).build();
    
    let region_interest_pinterest = RegionInterest::new(client).get_for("Pinterest");
    println!("{}", region_interest_pinterest);
}
examples/simple.rs (line 7)
3
4
5
6
7
8
9
10
11
12
fn main(){
    let country = Country::US;
    let keywords = Keywords::new(vec!["Instagram","Facebook"]);
    
    let client = Client::new(keywords, country).build();
    
    // Then select the data you want. The interest of your keywords filtered by region for example:
    let region_interest = RegionInterest::new(client).get();
    println!("{}", region_interest);
}

Trait Implementations§

source§

impl Clone for Client

source§

fn clone(&self) -> Client

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Client

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Client

Default value for client

Returns a Default Client.

By default,

  • The requested period is 1 year
  • The Country is all the countries supported by google trend
  • The Langage is English
  • The Category is 0
  • The response is empty (but valid json)

Example

let keywords = Keywords::new(vec!["rust"]);
let country = Country::FR;

let client = Client::new(keywords, country);

println!("{:#?}", client);
source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more