use crate::client::{IntoUrl, Spider};
use crate::ops::{curated_surface, first_page, Call};
use crate::response::{Outcome, Page, Pages};
use crate::transport::route;
use crate::Result;
#[derive(Debug)]
pub struct Crawl<'a> {
call: Call<'a>,
}
impl<'a> Crawl<'a> {
pub(crate) fn new(spider: &'a Spider, url: impl IntoUrl) -> Crawl<'a> {
Crawl {
call: Call::new(spider, url),
}
}
pub fn limit(mut self, pages: u32) -> Crawl<'a> {
self.call.params.limit = Some(pages);
self
}
pub fn depth(mut self, depth: u32) -> Crawl<'a> {
self.call.params.depth = Some(depth);
self
}
pub async fn send_all(mut self) -> Result<Outcome<Pages>> {
self.call.run(route::CRAWL, |params| params.clone()).await
}
pub async fn send(self) -> Result<Outcome<Page>> {
first_page(self.send_all().await?)
}
}
curated_surface!(Crawl, page_links);