Skip to content

Commit

Permalink
Merge pull request #8 from emreyalvac/refactor-v2
Browse files Browse the repository at this point in the history
Review
  • Loading branch information
emreyalvac authored Dec 22, 2021
2 parents 95380ab + 11182ed commit c25a6a3
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 152 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "firebase-rs"
edition = "2021"
version = "2.0.0"
version = "2.0.1"
description = "Rust based Firebase library"
readme = "README.md"
repository = "https://github.com/emreyalvac/firebase-rs"
documentation = "https://docs.rs/firebase-rs/1.0.3/firebase_rs/"
documentation = "https://docs.rs/firebase-rs/2.0.1/firebase_rs/"
license = "MIT"
authors = ["Emre YALVAÇ <[email protected]>"]
exclude = ["examples/*", "tests/*"]
Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,33 @@ let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().at("u
#### Read data as string
````rust
let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().at("users");
let users = firebase.get().await;
let users = firebase.get_as_string().await;
````

#### Read data with generic type (Single record)

#### Read data with generic type (All)
````rust
#[derive(Serialize, Deserialize, Debug)]
struct User {
name: String
}

let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().at("users").at("USER_ID");
let user = firebase.get_generic::<User>().await;
let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().at("users");
let user = firebase.get::<HashMap<String, User>>().await;
````

#### Read data with generic type (All)
#### Read data with generic type (Single record)
````rust
#[derive(Serialize, Deserialize, Debug)]
struct User {
name: String
}

let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().at("users");
let user = firebase.get_generic::<HashMap<String, User>>().await;
let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().at("users").at("USER_ID");
let user = firebase.get::<User>().await;
````


---

### Set Data
Expand All @@ -75,7 +77,7 @@ struct User {

let user = User { name: String::default() };
let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().at("users");
let users = firebase.set(&user).await;
firebase.set(&user).await;
````

---
Expand All @@ -89,7 +91,7 @@ struct User {

let user = User { name: String::default() };
let firebase = Firebase::new("https://myfirebase.firebaseio.com").unwrap().at("users").at("USER_ID");
let users = firebase.update(&user).await;
firebase.update(&user).await;
````

---
Expand Down
1 change: 0 additions & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub const EXPORT: &str = "export";
pub enum Method {
GET,
POST,
PUT,
DELETE,
PATCH,
}
Expand Down
6 changes: 5 additions & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::fmt::{Display, Formatter};

pub type UrlParseResult<T> = Result<T, UrlParseError>;

#[derive(Debug)]
pub enum UrlParseError {
NoPath,
Expand All @@ -17,6 +19,8 @@ impl Display for UrlParseError {
}
}

pub type RequestResult<T> = Result<T, RequestError>;

#[derive(Debug)]
pub enum RequestError {
NotJSON,
Expand All @@ -31,7 +35,7 @@ impl Display for RequestError {
match self {
RequestError::NotJSON => write!(f, "Invalid JSON"),
RequestError::NoUTF8 => write!(f, "Utf8 error"),
RequestError::NetworkError => write!(f, "Curl error"),
RequestError::NetworkError => write!(f, "Network error"),
RequestError::SerializeError => write!(f, "Serialize error"),
RequestError::NotFoundOrNullBody => write!(f, "Body is null or record is not found"),
}
Expand Down
Loading

0 comments on commit c25a6a3

Please sign in to comment.