pub struct CustomSearchAPI<C> {
pub client: Client<C>,
pub auth: Box<dyn GetToken>,
/* private fields */
}Expand description
Central instance to access all CustomSearchAPI related resource activities
§Examples
Instantiate a new hub
extern crate hyper;
extern crate hyper_rustls;
extern crate google_customsearch1 as customsearch1;
use customsearch1::{Result, Error};
use customsearch1::{CustomSearchAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
// Get an ApplicationSecret instance by some means. It contains the `client_id` and
// `client_secret`, among other things.
let secret: yup_oauth2::ApplicationSecret = Default::default();
// Instantiate the authenticator. It will choose a suitable authentication flow for you,
// unless you replace `None` with the desired Flow.
// Provide your own `AuthenticatorDelegate` to adjust the way it operates and get feedback about
// what's going on. You probably want to bring in your own `TokenStorage` to persist tokens and
// retrieve them from storage.
let connector = hyper_rustls::HttpsConnectorBuilder::new()
.with_native_roots()
.unwrap()
.https_only()
.enable_http2()
.build();
let executor = hyper_util::rt::TokioExecutor::new();
let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
secret,
yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
yup_oauth2::client::CustomHyperClientBuilder::from(
hyper_util::client::legacy::Client::builder(executor).build(connector),
),
).build().await.unwrap();
let client = hyper_util::client::legacy::Client::builder(
hyper_util::rt::TokioExecutor::new()
)
.build(
hyper_rustls::HttpsConnectorBuilder::new()
.with_native_roots()
.unwrap()
.https_or_http()
.enable_http2()
.build()
);
let mut hub = CustomSearchAPI::new(client, auth);
// You can configure optional parameters by calling the respective setters at will, and
// execute the final call using `doit()`.
// Values shown here are possibly random and not representative !
let result = hub.cse().siterestrict_list()
.start(25)
.sort("invidunt")
.snippet_length(-65)
.site_search_filter("vero")
.site_search("elitr")
.search_type("Lorem")
.safe("diam")
.rights("no")
.related_site("ipsum")
.q("accusam")
.or_terms("takimata")
.num(-46)
.lr("voluptua.")
.low_range("et")
.link_site("erat")
.img_type("consetetur")
.img_size("amet.")
.img_dominant_color("sed")
.img_color_type("takimata")
.hq("dolores")
.hl("gubergren")
.high_range("et")
.googlehost("accusam")
.gl("voluptua.")
.filter("dolore")
.file_type("dolore")
.exclude_terms("dolore")
.exact_terms("voluptua.")
.enable_alternate_search_handler(false)
.date_restrict("Lorem")
.cx("invidunt")
.cr("no")
.c2coff("est")
.doit().await;
match result {
Err(e) => match e {
// The Error enum provides details about what exactly happened.
// You can also just use its `Debug`, `Display` or `Error` traits
Error::HttpError(_)
|Error::Io(_)
|Error::MissingAPIKey
|Error::MissingToken(_)
|Error::Cancelled
|Error::UploadSizeLimitExceeded(_, _)
|Error::Failure(_)
|Error::BadRequest(_)
|Error::FieldClash(_)
|Error::JsonDecodeError(_, _) => println!("{}", e),
},
Ok(res) => println!("Success: {:?}", res),
}Fields§
§client: Client<C>§auth: Box<dyn GetToken>Implementations§
Source§impl<'a, C> CustomSearchAPI<C>
impl<'a, C> CustomSearchAPI<C>
pub fn new<A: 'static + GetToken>( client: Client<C>, auth: A, ) -> CustomSearchAPI<C>
pub fn cse(&'a self) -> CseMethods<'a, C>
Sourcepub fn user_agent(&mut self, agent_name: String) -> String
pub fn user_agent(&mut self, agent_name: String) -> String
Set the user-agent header field to use in all requests to the server.
It defaults to google-api-rust-client/7.0.0.
Returns the previously set user-agent.
Trait Implementations§
Source§impl<C: Clone> Clone for CustomSearchAPI<C>
impl<C: Clone> Clone for CustomSearchAPI<C>
Source§fn clone(&self) -> CustomSearchAPI<C>
fn clone(&self) -> CustomSearchAPI<C>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<C> Hub for CustomSearchAPI<C>
Auto Trait Implementations§
impl<C> Freeze for CustomSearchAPI<C>where
C: Freeze,
impl<C> !RefUnwindSafe for CustomSearchAPI<C>
impl<C> Send for CustomSearchAPI<C>where
C: Send,
impl<C> Sync for CustomSearchAPI<C>where
C: Sync,
impl<C> Unpin for CustomSearchAPI<C>where
C: Unpin,
impl<C> !UnwindSafe for CustomSearchAPI<C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more