Skip to content

Commit

Permalink
fix(tori/api): remove misunderstood ca argument
Browse files Browse the repository at this point in the history
  • Loading branch information
lajp committed Aug 24, 2023
1 parent 1ad91b5 commit 2c9741f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
15 changes: 8 additions & 7 deletions src/tests/tori/api_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ fn query_with_area() {
}

#[test]
fn query_with_caregion() {
fn query_with_ca() {
let url = "https://www.tori.fi/koko_suomi?q=thinkpad&ca=10";
let expected = API_BASE.to_owned() + "&q=thinkpad&region=10";
let expected = API_BASE.to_owned() + "&q=thinkpad";
assert_eq!(expected, vahti_to_api(url));
}

Expand All @@ -115,16 +115,17 @@ fn query_with_different_base() {

#[test]
fn multiquery1() {
let url = "https://www.tori.fi/pohjanmaa?q=yoga-matto&cg=0&w=1&st=s&st=k&st=u&st=h&st=g&ca=5&l=0&md=th";
let url =
"https://www.tori.fi/pohjanmaa?q=yoga-matto&cg=0&w=1&st=s&st=k&st=u&st=h&st=g&l=0&md=th";
let expected = API_BASE.to_owned()
+ "&q=yoga-matto&ad_type=s&ad_type=k&ad_type=u&ad_type=h&ad_type=g&region=5&l=0&md=th";
+ "&q=yoga-matto&ad_type=s&ad_type=k&ad_type=u&ad_type=h&ad_type=g&l=0&md=th";
assert_eq!(expected, vahti_to_api(url));
}

#[test]
fn multiquery2() {
let url = "https://www.tori.fi/uusimaa?q=vinkulelu+koiralle&cg=0&w=1&st=s&st=k&st=u&st=h&st=g&ca=18&l=0&md=th";
let expected =
API_BASE.to_owned() + "&q=vinkulelu+koiralle&ad_type=s&ad_type=k&ad_type=u&ad_type=h&ad_type=g&region=18&l=0&md=th";
let url = "https://www.tori.fi/uusimaa?q=vinkulelu+koiralle&cg=0&w=1&st=s&st=k&st=u&st=h&st=g&l=0&md=th";
let expected = API_BASE.to_owned()
+ "&q=vinkulelu+koiralle&ad_type=s&ad_type=k&ad_type=u&ad_type=h&ad_type=g&l=0&md=th";
assert_eq!(expected, vahti_to_api(url));
}
9 changes: 1 addition & 8 deletions src/tori/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub fn vahti_to_api(vahti: &str) -> String {
let mut url = "https://api.tori.fi/api/v1.2/public/ads?".to_owned();
let args = &vahti[vahti.find('?').unwrap() + 1..];
let mut price_set = false;
let mut region_defined = false;
let mut startprice = "";
let mut endprice = "";
let mut api_args = Vec::<(String, String)>::new();
Expand Down Expand Up @@ -45,22 +44,16 @@ pub fn vahti_to_api(vahti: &str) -> String {
"w" => {
let reg: i32 = parts[1].parse().unwrap();
if reg >= 100 {
region_defined = true;
api_args.push(("region".to_string(), (reg - 100).to_string()));
}
}
"ca" => api_args.push(("caregion".to_string(), parts[1].to_string())),
"ca" => {}
_ => api_args.push((parts[0].to_string(), parts[1].to_string())),
}
}
for arg in api_args {
if arg.0.is_empty() {
continue;
}
if arg.0 == "caregion" {
if !region_defined {
url += &format!("&region={}", arg.1);
}
} else {
url += &format!("&{}={}", arg.0, arg.1);
}
Expand Down

0 comments on commit 2c9741f

Please sign in to comment.