-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
362 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use crate::prelude::*; | ||
|
||
pub struct Crawler {} | ||
|
||
impl Crawler { | ||
pub fn new() -> Result<Self> { | ||
todo!() | ||
} | ||
|
||
pub async fn run(&self) -> Result { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use reqwest::Url; | ||
use tracing::instrument; | ||
|
||
use crate::{ | ||
marktplaats::models::{Listing, SearchResponse}, | ||
prelude::*, | ||
}; | ||
|
||
mod models; | ||
|
||
pub struct Marktplaats(reqwest::Client); | ||
|
||
impl Marktplaats { | ||
pub fn new() -> Result<Self> { | ||
Ok(Self( | ||
reqwest::ClientBuilder::new() | ||
.user_agent("Googlebot/2.1 (+http://www.google.com/bot.html)") | ||
.build() | ||
.context("failed to build Marktplaats client")?, | ||
)) | ||
} | ||
|
||
/// Search for a single listing. | ||
/// | ||
/// If multiple listings match the query, only the first one is returned. | ||
#[instrument(skip_all, level = "debug", fields(query))] | ||
pub async fn find_one(&self, query: &str) -> Result<Option<Listing>> { | ||
let url = Url::parse_with_params( | ||
"https://www.marktplaats.nl/lrp/api/search?limit=1", | ||
&[("query", query)], | ||
)?; | ||
let response = self | ||
.0 | ||
.get(url) | ||
.send() | ||
.await | ||
.with_context(|| format!("failed to search `{query}`"))? | ||
.error_for_status() | ||
.with_context(|| format!("failed to search `{query}` (bad status code)"))? | ||
.json::<SearchResponse>() | ||
.await | ||
.with_context(|| format!("failed to deserialize search response for `{query}`"))? | ||
.listings | ||
.pop(); | ||
Ok(response) | ||
} | ||
} |
Oops, something went wrong.