Skip to content

Commit

Permalink
Merge pull request #46 from TuTarea/develop
Browse files Browse the repository at this point in the history
impl From<VintedWrapperError> for FangError (#45)
  • Loading branch information
pxp9 authored Jul 26, 2023
2 parents 06a8359 + e363f4e commit fb9ed36
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 19 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.3.3 (2023-07-26) [#45](https://github.com/TuTarea/vinted-rs/pull/45/)

## Added

- Convert VintedWrapperError to FangError support.

## 0.3.2 (2023-07-17) [#44](https://github.com/TuTarea/vinted-rs/pull/44/)

## Added
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vinted-rs"
version = "0.3.2"
version = "0.3.3"
edition = "2021"
repository = "https://github.com/TuTarea/vinted-rs"
authors = ["Pepe Márquez <[email protected]>" , "Álvaro Cabo <[email protected]>"]
Expand Down Expand Up @@ -29,6 +29,7 @@ once_cell = "1.18"
rand = "0.8"
reqwest_cookie_store = "0.6"
typed-builder = "0.15"
fang = { version = "0.10.3" , features = ["asynk"], default-features = false }

[dependencies.bb8-postgres]
version = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Via `cargo` you can add the library to your project's `Cargo.toml`

```toml
[dependencies]
vinted-rs = "0.3.2"
vinted-rs = "0.3.3"
```

## DB setup
Expand Down
38 changes: 28 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,43 @@ const POOL_SIZE: u32 = 5;
#[tokio::main]
async fn main() {
let vinted = VintedWrapper::new();
l let args: Vec<String> = env::args().collect();
let filter: Filter = Filter::builder().search_text(String::from("shoes")).build();
if args.len() < 2 {
println!("Please provide the host as a command-line parameter.");
return;
}
let items = vinted.get_items(&filter, 5).await.unwrap();
let host_arg = args[1].as_str();
let host: Host = host_arg.into();
print!("{items:?}");
let db = DbController::new("postgres://postgres:postgres@localhost/vinted-rs", 5, NoTls)
.await
.unwrap();
let db: DbController<NoTls> = DbController::new(DB_URL, POOL_SIZE, NoTls).await.unwrap();
let adidas = db.get_brand_by_name(&"Adidas").await.unwrap();
let nike = db.get_brand_by_name(&"Nike").await.unwrap();
let brand_name: String = String::from("adidas");
let brands = format!("{},{}", adidas.id, nike.id);
let b: Brand = db.get_brand_by_name(&brand_name).await.unwrap();
let filter = Filter::builder()
.brand_ids(brands)
.price_from(15)
.price_to(20)
.build();
let brands = db.get_brands_by_name(&brand_name).await.unwrap();
let vinted = VintedWrapper::new_with_host(host);
println!("\n\n\n\nBrand {b:?}\n\n\n\n");
println!("Host: {}", vinted.get_host());
let items = vinted.get_items(&filter, 10).await.unwrap();
if items.items.is_empty() {
println!("No items found");
}
println!("{}", items);
println!("Brands: {brands:?}");
}
```
Expand Down
10 changes: 10 additions & 0 deletions src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use crate::vinted_rs::model::filter::Filter;
use crate::vinted_rs::queries::VintedWrapper;
use crate::vinted_rs::queries::VintedWrapperError;
use fang::FangError;
async fn get_items_example() {
let wrapper = VintedWrapper::new();
Expand All @@ -28,6 +29,7 @@
}
```
*/
use fang::FangError;
use once_cell::sync::OnceCell;
use rand::Rng;
use reqwest::Client;
Expand Down Expand Up @@ -63,6 +65,14 @@ impl From<reqwest::Error> for VintedWrapperError {
}
}

impl From<VintedWrapperError> for FangError {
fn from(value: VintedWrapperError) -> FangError {
FangError {
description: format!("{value:?}"),
}
}
}

const DOMAINS: [&str; 18] = [
"fr", "be", "es", "lu", "nl", "lt", "de", "at", "it", "co.uk", "pt", "com", "cz", "sk", "pl",
"se", "ro", "hu",
Expand Down
14 changes: 7 additions & 7 deletions src/tests/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async fn test_get_item_query_text() {
match vinted.get_items(&filter, 1).await {
// Limitado el numero de elementos a 1
Ok(items) => {
assert_eq!(items.items.len(), 1);
assert!(items.items.len() <= 1);
}
Err(err) => match err {
VintedWrapperError::ItemNumberError => unreachable!(),
Expand Down Expand Up @@ -99,7 +99,7 @@ async fn test_get_items_catalogs_no_db() {

match vinted.get_items(&filter, 10).await {
Ok(items) => {
assert_eq!(items.items.len(), 10);
assert!(items.items.len() < 10);
items.items.iter().for_each(|item| {
let url_item: &str = &item.url;
let category = url_item.split('/').nth(3).unwrap();
Expand Down Expand Up @@ -128,7 +128,7 @@ async fn test_get_items_by_price() {

match vinted.get_items(&filter, 10).await {
Ok(items) => {
assert_eq!(items.items.len(), 10);
assert!(items.items.len() <= 10);
let ok: bool = items.items.iter().all(|item| {
let price: f32 = item.price.parse().unwrap();
price <= max as f32 && price >= min as f32
Expand All @@ -153,7 +153,7 @@ async fn test_get_items_by_size() {

match vinted.get_items(&filter, 20).await {
Ok(items) => {
assert_eq!(items.items.len(), 20);
assert!(items.items.len() <= 20);
let ok: bool = items.items.iter().all(|item| item.size_title == size_title);

assert!(ok);
Expand All @@ -175,7 +175,7 @@ async fn test_get_items_by_material() {

match vinted.get_items(&filter, num as u32).await {
Ok(items) => {
assert_eq!(items.items.len(), num);
assert!(items.items.len() <= num);
}
Err(err) => match err {
VintedWrapperError::ItemNumberError => unreachable!(),
Expand All @@ -198,7 +198,7 @@ async fn test_get_items_by_color() {

match vinted.get_items(&filter, num as u32).await {
Ok(items) => {
assert_eq!(items.items.len(), num);
assert!(items.items.len() <= num);
}
Err(err) => match err {
VintedWrapperError::ItemNumberError => unreachable!(),
Expand All @@ -217,7 +217,7 @@ async fn test_get_items_by_currency() {

match vinted.get_items(&filter, num as u32).await {
Ok(items) => {
assert_eq!(items.items.len(), num);
assert!(items.items.len() <= num);
let ok: bool = items.items.iter().all(|item| {
let c: &str = Currency::CZK.into();
item.currency == c
Expand Down

0 comments on commit fb9ed36

Please sign in to comment.