Did a lot of things.
This commit is contained in:
+19
-13
@@ -3,7 +3,6 @@ use log::debug;
|
||||
use regex::Regex;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::context::Context;
|
||||
use crate::probe::{self, Entry, Probe};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
@@ -97,23 +96,23 @@ fn from_html(document: &str) -> Result<Entry, ()> {
|
||||
pub struct Hitta;
|
||||
|
||||
impl Probe for Hitta {
|
||||
fn provider(&self) -> &'static str {
|
||||
"hitta.se"
|
||||
}
|
||||
|
||||
fn uri(&self, number: &str) -> String {
|
||||
format!("https://www.hitta.se/vem-ringde/{}", number)
|
||||
}
|
||||
|
||||
fn search(&mut self, ctx: &mut Context, number: &str) -> Result<Entry, ()> {
|
||||
let body = if let Some(cache) = ctx.cache_get("hitta", &number) {
|
||||
String::from_utf8(cache.data).unwrap()
|
||||
} else {
|
||||
let body = reqwest::get(&self.uri(number)).unwrap().text().unwrap();
|
||||
fn fetch(&self, number: &str) -> Result<String, ()> {
|
||||
reqwest::get(&self.uri(number))
|
||||
.map_err(|_| ())?
|
||||
.text()
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
ctx.cache_set("hitta", &number, body.as_bytes())
|
||||
.expect("wut?! why not?!");
|
||||
|
||||
body
|
||||
};
|
||||
|
||||
from_html(&body)
|
||||
fn parse(&self, data: &str) -> Result<Entry, ()> {
|
||||
from_html(&data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,4 +281,11 @@ mod tests {
|
||||
history: []
|
||||
comments: []"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_0701807618() {
|
||||
let document = include_str!("../../fixtures/hitta/0701807618.html");
|
||||
|
||||
assert_yaml_snapshot_matches!(from_html(&document), @"Err: ~");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user