Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle multitype items #118

Merged
merged 19 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copy this file as your .env
POSTGRES_DB=vinted-rs
POSTGRES_PASSWORD=postgres
POSTGRES_USER=postgres
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Cargo.lock
/**/results/
docker/query.sh

src/tests/output
src/tests/output
.env
20 changes: 16 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
# Changelog

# 0.10.0 (WIP)

## Fixed
- Re-exported Redis crate [#115](https://github.com/ThalosES/vinted-rs/pull/115)

- Added support for fields that may come as boolean or integer [#118](https://github.com/ThalosES/vinted-rs/pull/118)

## Improved

- Removed hardcoded DB strings and introduced a `.env` file required for feature `Advanced Items` [#117](https://github.com/ThalosES/vinted-rs/pull/117)

# 0.9.1 (2024-09-24) [#111](https://github.com/TuTarea/vinted-rs/pull/111/)
⚠️Not using `develop` branch any more. Leaving main as "canary"/develop channel and using releases to declare _stable_ and _experimental_ versions

⚠️Not using [`develop`](https://github.com/ThalosES/vinted-rs/tree/develop) branch any more. Leaving main as "canary"/develop channel and using releases to declare _stable_ and _experimental_ versions

## Fixed
#108 : Updated Redis to 0.27.2
#105 : Updated TypeBuilder to 0.20
#109 : Solved vulnerable dependency for Db Feeder
- Updated Redis to 0.27.2 [#108](https://github.com/ThalosES/vinted-rs/pull/108)
- Updated TypeBuilder to 0.20 [#105](https://github.com/ThalosES/vinted-rs/pull/105)
- Solved vulnerable dependency for Db Feeder [#109](https://github.com/ThalosES/vinted-rs/pull/109)

# 0.9.0 (2024-07-28) [#97](https://github.com/TuTarea/vinted-rs/pull/97/)

Expand Down
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[workspace]
members = ["examples/filter_example", "."]
[package]
name = "vinted-rs"
version = "0.9.1"
version = "0.10.0"
edition = "2021"
repository = "https://github.com/TuTarea/vinted-rs"
authors = [
Expand Down Expand Up @@ -34,10 +36,11 @@ reqwest_cookie_store = "0.8"
typed-builder = "0.20"
fang = { version = "0.10.3", features = ["asynk"], default-features = false }
redis-macros = { version = "0.4.2", optional = true }
redis = { version = "0.27.2", optional = true }
serde_json = { version = "1.0.91" }
redis = { version = "0.27.X", optional = true }
serde_json = { version = "1.0.X" }
log = "0.4.20"
lazy_static = "1.4.0"
dotenvy = "0.15"
[dev-dependencies]
env_logger = "0.11.5"
redis-macros = { version = "0.4.2" }
Expand Down
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
include .env

db:
docker run --rm -d --name postgres -p 5432:5432 \
-e POSTGRES_DB=vinted-rs \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=$(POSTGRES_DB) \
-e POSTGRES_USER=$(POSTGRES_USER) \
-e POSTGRES_PASSWORD=$(POSTGRES_PASSWORD) \
postgres:latest


diesel:
DATABASE_URL=postgres://postgres:postgres@localhost/vinted-rs diesel migration run
DATABASE_URL=postgres://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@localhost/$(POSTGRES_DB) diesel migration run
stop:
docker kill postgres

clippy:
cargo clippy --all-features
cargo clippy --all-features

env:

120 changes: 68 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,96 +1,112 @@
# Vinted-rs: A Vinted API wrapper
<div align="center">

# Vinted-rs: A Vinted API wrapper in Rust

[![github]](https://github.com/TuTarea/vinted-rs/)&ensp;[![crates-io]](https://crates.io/crates/vinted-rs)&ensp;[![docs-rs]](https://docs.rs/vinted-rs/latest/vinted_rs/)

[github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
[crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
[docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs

## Table of Contents

- [Vinted-rs: A Vinted API wrapper](#vinted-rs-a-vinted-api-wrapper)
- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [DB setup](#db-setup)
- [Create a migration](#create-a-migration)
- [Run a Docker container with PostgreSQL](#run-a-docker-container-with-postgresql)
- [Run migrations](#run-migrations)
- [Stop DB](#stop-db)
- [Running Tests](#running-tests)
</div>

## Installation

Via `cargo` you can add the library to your project's `Cargo.toml`

```toml
[dependencies]
vinted-rs = "0.9.1"
vinted-rs = { version = "0.10.0",
#features = ["advanced_filters", "redis"]
}
```

## DB setup
## Features

### Advanced filters

> This feature requires [setting up a Postgres Database](#database-set-up) <code><img width="3%" src="https://raw.githubusercontent.com/yurijserrano/Github-Profile-Readme-Logos/refs/heads/master/databases/postgresql.svg"></code>

Uses the data pulled by the [scrapping module](./scrapping/vinted-db-feeder/), which is stored in the diesel [migrations](./migrations/) folder.

#### Environment set-up

1. Copy the `.env.example`

```sh
cp .env.example .env
```

2. Modify the variables to your liking

#### Database set-up
Advanced filtering features must require this setup before running.

- First start installing diesel-cli (in order to run the migrations in PostgreSQL database)
1. ⚠️ `diesel-cli` installation may fail if you do not have `libpq` library installed. To install `libpq`, just install PostgreSQL package on your machine.

⚠️**Very important:** diesel-cli installation may fail if you do not have `libpq` library installed.
- In `Arch` based is only necessary to install this package.

To install `libpq`, just install PostgreSQL package on your machine.
```bash
sudo pacman -S postgresql-libs
```

In `Arch` based is only necessary to install this package.
- In `Debian` based distributions is only necessary to install this package.

```bash
sudo pacman -S postgresql-libs
```
```bash
sudo apt install libpq-dev
```

In `Debian` based distributions is only necessary to install this package.
2. Install `diesel-cli` in order to run the migrations in PostgreSQL database

```bash
cargo install diesel_cli --features=postgres --no-default-features
```

```bash
sudo apt install libpq-dev
```
**Available interactions** (See [Makefile](./Makefile))

```bash
cargo install diesel_cli --features=postgres --no-default-features
```
1. Create a migration

### Create a migration
```bash
mkdir -p migrations #
diesel migration generate my_migration
```

```bash
mkdir migrations
```
Program after that `up.sql` and `down.sql` scripts.

```bash
diesel migration generate my_migration
```
2. Run a Docker container with PostgreSQL

Program after that `up.sql` and `down.sql` scripts.
- See in [Makefile](https://github.com/ThalosES/vinted-rs/blob/main/Makefile)

### Run a Docker container with PostgreSQL
```bash
make db
```

- See in [Makefile](https://github.com/TuTarea/vinted-rs/blob/main/Makefile)
3. Run migrations

```bash
make db
```
```bash
make diesel
```

### Run migrations
4. Stop DB

```bash
make diesel
```
```bash
make stop
```

#### Testing set-up

### Stop DB
> This step requires completing the [DB setup](#database-set-up)

```bash
make stop
cargo test
```

## Running Tests
### Redis

⚠️**Very important:** Before running tests is important to do the [DB setup](#db-setup)
This feature allows recovered results to be cached using a Redis instance. <code><img width="4%" src="https://raw.githubusercontent.com/yurijserrano/Github-Profile-Readme-Logos/refs/heads/master/databases/redis.svg"></code>
pxp9 marked this conversation as resolved.
Show resolved Hide resolved

Then run the tests
A development instance can be created using:

```bash
cargo test
```
make cache
```
2 changes: 2 additions & 0 deletions examples/filter_example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.venv
result/
12 changes: 9 additions & 3 deletions examples/filter_example/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
[package]
name = "filter_example"
version = "0.1.0"
version = "0.10.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
vinted-rs = { path = "../../", features = ["advanced_filters"]}
bb8-postgres = {version = "0.8", features = ["with-serde_json-1" , "with-uuid-1" , "with-chrono-0_4"]}
vinted-rs = { path = "../../", features = ["advanced_filters"] }
bb8-postgres = { version = "0.8", features = [
"with-serde_json-1",
"with-uuid-1",
"with-chrono-0_4",
] }
tokio = { version = "1", features = ["full"] }
dotenvy = { version = "0.15.7" }
lazy_static = { version = "1.4.0" }
20 changes: 20 additions & 0 deletions examples/filter_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Advanced filter example project

## Rust set-up

Refer to the [main README *Install* section](../../README.md#installation) and its subsections

## Python set-up

1. Create a Virtual Environment

```bash
python -m venv .venv
```

2. Install the requirements

```bash
source .venv/bin/activate #linux
pip install -r requirements.txt
```
31 changes: 24 additions & 7 deletions examples/filter_example/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
use bb8_postgres::tokio_postgres::NoTls;

use lazy_static::lazy_static;
use std::env;
use vinted_rs::{db::DbController, queries::Host, Filter, VintedWrapper};

lazy_static! {
pub static ref POSTGRES_DB: String =
std::env::var("POSTGRES_DB").unwrap_or(String::from("vinted-rs"));
pub static ref POSTGRES_USER: String =
std::env::var("POSTGRES_USER").unwrap_or(String::from("postgres"));
pub static ref POSTGRES_PASSWORD: String =
std::env::var("POSTGRES_PASSWORD").unwrap_or(String::from("postgres"));
}

#[tokio::main]
async fn main() {
let args: Vec<String> = env::args().collect();

let _ = dotenvy::dotenv(); //Load at runtime

if args.len() < 2 {
println!("Please provide the host as a command-line parameter.");
return;
Expand All @@ -15,9 +26,19 @@ async fn main() {
let host_arg = args[1].as_str();
let host: Host = host_arg.into();

let db = DbController::new("postgres://postgres:postgres@localhost/vinted-rs", 5, NoTls)
let vinted = VintedWrapper::new_with_host(host);
println!("Host: {}", vinted.get_host());

let db_uri = &format!(
"postgres://{}:{}@localhost/{}?sslmode=disable",
POSTGRES_USER.clone(),
POSTGRES_PASSWORD.clone(),
POSTGRES_DB.clone()
);

let db = DbController::new(&db_uri, 5, NoTls)
.await
.unwrap();
.expect("Broken connection to Database, please set it up correctly");

let adidas = db.get_brand_by_name(&"Adidas").await.unwrap();
let nike = db.get_brand_by_name(&"Nike").await.unwrap();
Expand All @@ -30,10 +51,6 @@ async fn main() {
.price_to(Some(20.0))
.build();

let vinted = VintedWrapper::new_with_host(host);
pxp9 marked this conversation as resolved.
Show resolved Hide resolved

println!("Host: {}", vinted.get_host());

let items = vinted
.get_items(&filter, 10, None, None, None)
.await
Expand Down
Loading
Loading