Struct GSBClient

Source
pub struct GSBClient<'b> { /* private fields */ }
Expand description

A client for interacting with the Google Safe Browsing Lookup API

Implementations§

Source§

impl<'b> GSBClient<'b>

Source

pub fn new(key: String) -> GSBClient<'b>

Creates a new GSBClient that will use ‘key’ as the GSB API key

§Arguments
  • key - A String that represents the API key for Google Safe Browsing Lookup
§Example
use gsbrs::GSBClient;
let key : String = "example_api_key".into();
let gsb = GSBClient::new(key);
Source

pub fn change_client_name(&mut self, client_name: &'b str)

Sets the GSBClient client_name to ‘client_name’ GSBClient uses ‘gsbrs’ as the client_name by default.

§Arguments
  • client_name - A string slice that holds the name of the org/person using the client
§Example
let key : String = "example_api_key".into();
let mut gsb = gsbrs::GSBClient::new(key);

gsb.change_client_name("new_name");
Source

pub fn get_client_mut(&mut self) -> &mut Client

Returns a mutable reference to the hyper::Client used for connections

Source

pub fn lookup(&self, url: &str) -> Result<Vec<Status>, GSBError>

Queries GSB API with ‘url’, returns Vec of Status for ‘url’

§Arguments
  • url - A string slice that holds the url to be queried
§Example
let key : String = "example_api_key".into();
let gsb = gsbrs::GSBClient::new(key);

let url = "https://google.com/";
if let Ok(statuses) = gsb.lookup(url) {
    assert_eq!(statuses[0], Status::Ok)
};
Source

pub fn lookup_all<'a, I>(&self, urls: I) -> Result<Vec<Vec<Status>>, GSBError>
where I: Iterator<Item = &'a str>,

Perform a bulk lookup on an iterable of urls. Returns a Vector of Vectors containing Statuses. Returns GSBError::TooManyUrls if > 500 urls are pased in

§Arguments
  • urls - An iterable of string slices representing URLs to query
§Example
let key : String = "example_api_key".into();
let gsb = GSBClient::new(key);

let urls = vec!["https://google.com/", "https://example.com"];
gsb.lookup_all(urls.iter());

Auto Trait Implementations§

§

impl<'b> Freeze for GSBClient<'b>

§

impl<'b> !RefUnwindSafe for GSBClient<'b>

§

impl<'b> Send for GSBClient<'b>

§

impl<'b> Sync for GSBClient<'b>

§

impl<'b> Unpin for GSBClient<'b>

§

impl<'b> !UnwindSafe for GSBClient<'b>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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, U> Into<U> for T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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> Typeable for T
where T: Any,

Source§

fn get_type(&self) -> TypeId

Get the TypeId of this object.