aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Edgecumbe <git@esotericnonsense.com>2019-10-25 07:12:37 +0200
committerDaniel Edgecumbe <git@esotericnonsense.com>2019-10-25 07:12:37 +0200
commit10b5b166ccf6bc2b55ee80233f55a8bcd0f6de72 (patch)
tree9fddf350d4d16a426be4faaf410135bd088c4616
parent45eb1b9faafc4f32b68a16d1bf2f0eca5047380d (diff)
Use proxy; do not serialize nulls
-rw-r--r--Cargo.lock14
-rw-r--r--Cargo.toml3
-rwxr-xr-xgenapi/main.py26
-rw-r--r--src/main.rs23
4 files changed, 52 insertions, 14 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 0a0c7ea..1c3dc89 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -987,6 +987,7 @@ dependencies = [
"serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "socks 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1063,6 +1064,7 @@ dependencies = [
"rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -1161,6 +1163,17 @@ version = "0.6.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "socks"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "sourcefile"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1774,6 +1787,7 @@ dependencies = [
"checksum serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "642dd69105886af2efd227f75a520ec9b44a820d65bc133a9131f7d229fd165a"
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
"checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7"
+"checksum socks 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e6a64cfa9346d26e836a49fcc1ddfcb4d3df666b6787b6864db61d4918e1cbc2"
"checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3"
"checksum spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
"checksum string 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d"
diff --git a/Cargo.toml b/Cargo.toml
index eeb6ead..3ae88da 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,7 +7,8 @@ edition = "2018"
[dependencies]
log = "0.4"
env_logger = "0.7"
-reqwest = { "version" = "0.9", "features" = ["rustls-tls"] }
+reqwest = { "version" = "0.9", "features" = ["rustls-tls", "socks"] }
rand = "0.7"
serde = "1"
+serde_json = "1"
chrono = { "version" = "0.4", "features" = ["serde"] }
diff --git a/genapi/main.py b/genapi/main.py
index f1d7177..9fd1a4f 100755
--- a/genapi/main.py
+++ b/genapi/main.py
@@ -506,7 +506,7 @@ def generate_rust_types(simple_types: List[SimpleType]) -> str:
# TODO: document the descriptions along with the type/enum
if simple_type.values is None:
rust_type: str = python_type_to_rust_type(simple_type._type)
- types.append(f"type {simple_type.name} = {rust_type};")
+ types.append(f"pub type {simple_type.name} = {rust_type};")
continue
else:
assert simple_type._type == "string"
@@ -543,8 +543,16 @@ def generate_rust_data_types(data_types: List[DataType]) -> str:
_type: str = python_type_to_rust_type(param._type, param.mandatory)
params_converted.append((name, _type))
- formatted_params: str = ", ".join(
- f"{x[0]}: {x[1]}" for x in params_converted
+ def format_param(x):
+ # TODO: this is super ugly. seriously?
+ if x[1].startswith("Option<"):
+ return f"""#[serde(skip_serializing_if = "Option::is_none")]
+{x[0]}: {x[1]}"""
+
+ return f"{x[0]}: {x[1]}"
+
+ formatted_params: str = ", \n".join(
+ format_param(x) for x in params_converted
)
if data_type.description is not None:
types.append(f"/// {data_type.description}")
@@ -586,8 +594,16 @@ def generate_rust_functions(operations: List[Operation]) -> str:
# TODO these should probably not be public, just for now
# so that we can test outside of jsonrpc
- formatted_params_struct: str = ", ".join(
- f"pub {x[0]}: {x[1]}" for x in params_converted
+ def format_param(x):
+ # TODO: this is super ugly. seriously?
+ if x[1].startswith("Option<"):
+ return f"""#[serde(skip_serializing_if = "Option::is_none")]
+pub {x[0]}: {x[1]}"""
+
+ return f"pub {x[0]}: {x[1]}"
+
+ formatted_params_struct: str = ", \n".join(
+ format_param(x) for x in params_converted
)
functions.append(
diff --git a/src/main.rs b/src/main.rs
index d4924c5..a67f930 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -70,9 +70,10 @@ fn get_session_token() -> Result<String, AnyError> {
let username = fs::read_to_string(USERFILE)?.replace("\n", "");
let password = fs::read_to_string(PASSFILE)?.replace("\n", "");
+ let proxy = reqwest::Proxy::all("socks5h://127.0.0.1:40001")?;
let ident =
Identity::from_pkcs12_der(std::fs::read(PFXFILE)?.as_slice(), "")?;
- let cl: Client = Client::builder().identity(ident).build()?;
+ let cl: Client = Client::builder().identity(ident).proxy(proxy).build()?;
let appheader = format!("{}", rand::random::<u128>());
@@ -93,15 +94,20 @@ fn get_session_token() -> Result<String, AnyError> {
}
}
-use generated_api::{listMarketBookRequest, MarketBook};
+use generated_api::{listMarketBookRequest, MarketBook, MarketId};
use json_rpc::{RpcRequest, RpcResponse};
-fn try_lmb(session_token: String) -> Result<Vec<MarketBook>, AnyError> {
+fn try_lmb(
+ session_token: String,
+ market_id: MarketId,
+) -> Result<Vec<MarketBook>, AnyError> {
let app_key = fs::read_to_string(APPKEYFILE)?.replace("\n", "");
- let cl: Client = Client::new();
+
+ let proxy = reqwest::Proxy::all("socks5h://127.0.0.1:40001")?;
+ let cl: Client = Client::builder().proxy(proxy).build()?;
let method = "SportsAPING/v1.0/listMarketBook".to_owned();
let params = listMarketBookRequest {
- marketIds: vec!["1.164123879".to_owned()],
+ marketIds: vec![market_id],
priceProjection: None,
orderProjection: None,
matchProjection: None,
@@ -134,9 +140,10 @@ fn main() -> Result<(), AnyError> {
match get_session_token() {
Ok(x) => {
- info!("got token {}", x);
- let books: Vec<MarketBook> = try_lmb(x)?;
- println!("{:?}", books);
+ let books: Vec<MarketBook> = try_lmb(x, "1.156586178".to_owned())?;
+ info!("{:?}", books);
+ let s: String = serde_json::to_string(&books).expect("whatever");
+ println!("{}", s);
Ok(())
}
Err(e) => {