diff --git a/src/tests/tori/api_url.rs b/src/tests/tori/api_url.rs index 2b94ef9..cc7614b 100644 --- a/src/tests/tori/api_url.rs +++ b/src/tests/tori/api_url.rs @@ -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®ion=10"; + let expected = API_BASE.to_owned() + "&q=thinkpad"; assert_eq!(expected, vahti_to_api(url)); } @@ -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®ion=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®ion=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)); } diff --git a/src/tori/api.rs b/src/tori/api.rs index 1518a82..9b0ea61 100644 --- a/src/tori/api.rs +++ b/src/tori/api.rs @@ -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(); @@ -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!("®ion={}", arg.1); - } } else { url += &format!("&{}={}", arg.0, arg.1); }