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
§country: Country
§keywords: Keywords
§lang: Lang
§property: Property
§time: String
§category: Category
§response: Value
Implementations§
source§impl Client
impl Client
sourcepub fn new(keywords: Keywords, country: Country) -> Self
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?
More examples
sourcepub fn with_keywords(self, keywords: Keywords) -> Self
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);
sourcepub fn with_lang(self, lang: Lang) -> Self
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?
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);
}
sourcepub fn with_category(self, category: Category) -> Self
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?
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);
}
sourcepub fn with_property(self, property: Property) -> Self
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?
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);
}
sourcepub fn with_period(self, period: impl ToString) -> Self
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);
sourcepub fn with_date(self, start_date: NaiveDate, end_date: NaiveDate) -> Self
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);
sourcepub fn with_filter(
self,
category: Category,
property: Property,
period: String,
lang: Lang
) -> Self
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
);
sourcepub fn build(self) -> Self
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?
More examples
Trait Implementations§
source§impl Default for Client
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);