Struct Spider

Source
pub struct Spider {
    pub api_key: String,
    pub client: Client,
}
Expand description

Represents a Spider with API key and HTTP client.

Fields§

§api_key: String

The Spider API key.

§client: Client

The Spider Client to re-use.

Implementations§

Source§

impl Spider

Source

pub fn new(api_key: Option<String>) -> Result<Self, &'static str>

Creates a new instance of Spider.

§Arguments
  • api_key - An optional API key. Defaults to using the ‘SPIDER_API_KEY’ env variable.
§Returns

A new instance of Spider or an error string if no API key is provided.

Source

pub fn new_with_client( api_key: Option<String>, client: Client, ) -> Result<Self, &'static str>

Creates a new instance of Spider.

§Arguments
  • api_key - An optional API key. Defaults to using the ‘SPIDER_API_KEY’ env variable.
  • client - A custom client to pass in.
§Returns

A new instance of Spider or an error string if no API key is provided.

Source

pub async fn scrape_url( &self, url: &str, params: Option<RequestParams>, content_type: &str, ) -> Result<Value, Error>

Scrapes a URL.

§Arguments
  • url - The URL to scrape.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API as a JSON value.

Source

pub async fn crawl_url( &self, url: &str, params: Option<RequestParams>, stream: bool, content_type: &str, callback: Option<impl Fn(Value) + Send>, ) -> Result<Value, Error>

Crawls a URL.

§Arguments
  • url - The URL to crawl.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
  • callback - Optional callback function to handle each streamed chunk.
§Returns

The response from the API as a JSON value.

Fetches links from a URL.

§Arguments
  • url - The URL to fetch links from.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API as a JSON value.

Source

pub async fn screenshot( &self, url: &str, params: Option<RequestParams>, _stream: bool, content_type: &str, ) -> Result<Value, Error>

Takes a screenshot of a URL.

§Arguments
  • url - The URL to take a screenshot of.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API as a JSON value.

Source

pub async fn search( &self, q: &str, params: Option<SearchRequestParams>, _stream: bool, content_type: &str, ) -> Result<Value, Error>

Searches for a query.

§Arguments
  • q - The query to search for.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API as a JSON value.

Source

pub async fn transform( &self, data: Vec<HashMap<&str, &str>>, params: Option<TransformParams>, _stream: bool, content_type: &str, ) -> Result<Value, Error>

Transforms data.

§Arguments
  • data - The data to transform.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API as a JSON value.

Source

pub async fn extract_contacts( &self, url: &str, params: Option<RequestParams>, _stream: bool, content_type: &str, ) -> Result<Value, Error>

Extracts contacts from a URL.

§Arguments
  • url - The URL to extract contacts from.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API as a JSON value.

Source

pub async fn label( &self, url: &str, params: Option<RequestParams>, _stream: bool, content_type: &str, ) -> Result<Value, Error>

Labels data from a URL.

§Arguments
  • url - The URL to label data from.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns

The response from the API as a JSON value.

Source

pub async fn download( &self, url: Option<&str>, options: Option<HashMap<&str, i32>>, ) -> Result<Response, Error>

Download a record from storage.

§Arguments
  • url - Optional exact url of the file in storage.
  • options - Optional options.
  • stream - Whether streaming is enabled.
§Returns

The response from the API.

Source

pub async fn create_signed_url( &self, url: Option<&str>, options: Option<HashMap<&str, i32>>, ) -> Result<Value, Error>

Creates a signed URL of a file from storage.

§Arguments
  • url - Optional exact url of the file in storage.
  • options - Optional options.
  • stream - Whether streaming is enabled.
§Returns

The response from the API.

Source

pub async fn get_crawl_state( &self, url: &str, params: Option<RequestParams>, content_type: &str, ) -> Result<Value, Error>

Gets the crawl state of a URL.

§Arguments
  • url - The URL to get the crawl state of.
  • params - Optional request parameters.
  • stream - Whether streaming is enabled.
  • content_type - The content type of the request.
§Returns
Source

pub async fn get_credits(&self) -> Result<Value, Error>

Get the account credits left.

Source

pub async fn data_post( &self, table: &str, data: Option<RequestParams>, ) -> Result<Value, Error>

Send a request for a data record.

Source

pub async fn query(&self, params: &QueryRequest) -> Result<Value, Error>

Query a record from the global DB.

Source

pub async fn data_get( &self, table: &str, params: Option<RequestParams>, ) -> Result<Value, Error>

Get a table record.

Source

pub async fn data_delete( &self, table: &str, params: Option<RequestParams>, ) -> Result<Value, Error>

Delete a record.

Trait Implementations§

Source§

impl Debug for Spider

Source§

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

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

impl Default for Spider

Source§

fn default() -> Spider

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

Auto Trait Implementations§

§

impl Freeze for Spider

§

impl !RefUnwindSafe for Spider

§

impl Send for Spider

§

impl Sync for Spider

§

impl Unpin for Spider

§

impl !UnwindSafe for Spider

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> 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 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> 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
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T