Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
sorainnosia authored Sep 3, 2023
1 parent abd3b5e commit cd6815d
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 148 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sd-req"
version = "0.2.0"
version = "0.3.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
91 changes: 91 additions & 0 deletions src/http/json.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
use serde_json::{Value, json};
use crate::http::types;

pub fn get_string(k: &Value, name: String, default: String) -> String {
match k.get(name.as_str()) {
Some(x) => {
match x.as_str() {
Some (y) => {
return y.to_string();
},
None => {}
}
},
None => {}
}

match k.get(name.as_str()) {
Some(x) => {
match x.as_bool() {
Some (y) => {
return y.to_string();
},
None => {}
}
},
None => {}
}

match k.get(name.as_str()) {
Some(x) => {
match x.as_i64() {
Some (y) => {
return y.to_string();
},
None => {}
}
},
None => {}
}

match k.get(name.as_str()) {
Some(x) => {
match x.as_object() {
Some (y) => {
return format!("{:?}", y);
},
None => {}
}
},
None => {}
}
return default;
}

pub fn get_value(key: String, o: &Value, v: String) -> Value {
let mut value = Value::Null;
if o.is_boolean() {
if v.to_lowercase() == "true".to_string() {
value = Value::Bool(true);
} else if v.to_lowercase() == "false".to_string() {
value = Value::Bool(false);
} else {
println!("Invalid bool value {{ {} : {} }}", key.as_str(), v.as_str());
return value;
}
} else if o.is_f64() {
let (b, f) = types::str_to_f64(v.clone());
if b == false {
println!("Invalid f64 value {{ {} : {} }}", key.as_str(), v.as_str());
return value;
}
value = json!(f);
} else if o.is_i64() || o.is_number() {
let (b, f) = types::str_to_i64(v.clone());
if b == false {
println!("Invalid i64 value {{ {} : {} }}", key.as_str(), v.as_str());
return value;
}
value = json!(f);
} else if o.is_string() {
value = json!(v.as_str());
} else if o.is_u64() {
let (b, f) = types::str_to_u64(v.clone());
if b == false {
println!("Invalid u64 value {{ {} : {} }}", key.as_str(), v.as_str());
return value;
}
value = json!(f);
}
return value;
}
3 changes: 2 additions & 1 deletion src/http/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod http_fast_reqwest;
pub mod stringops;
pub mod path;
pub mod types;
pub mod types;
pub mod json;
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ mod http;
use sd_req::sd_reqo;

fn main() {
let obj = sd_req::sd_reqo::new();
let mut obj = sd_req::sd_reqo::new();
obj.sdcall();
}
Loading

0 comments on commit cd6815d

Please sign in to comment.