Skip to main content

subscan/interfaces/
requester.rs

1use async_trait::async_trait;
2use enum_dispatch::enum_dispatch;
3use reqwest::Url;
4
5use crate::{
6    enums::{content::Content, dispatchers::RequesterDispatcher},
7    requesters::{chrome::ChromeBrowser, client::HTTPClient},
8    types::{config::requester::RequesterConfig, core::Result},
9};
10
11/// Generic HTTP client trait definition to implement different HTTP requester objects
12/// with a single interface compatible
13///
14/// Other requesters that will be implemented in the future must conform to this interface.
15/// Mostly uses to get string content from any URL with a single stupid `get_content` method
16#[async_trait]
17#[enum_dispatch]
18pub trait RequesterInterface: Sync + Send {
19    /// Returns requester configurations as a [`RequesterConfig`] object
20    async fn config(&mut self) -> &mut RequesterConfig;
21    /// Configure current requester object by using new [`RequesterConfig`] object
22    async fn configure(&mut self, config: RequesterConfig);
23    /// HTTP GET method implementation to fetch HTML content from given source [`Url`]
24    async fn get_content(&self, url: Url) -> Result<Content>;
25}