aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Edgecumbe <git@esotericnonsense.com>2019-10-25 06:47:12 +0200
committerDaniel Edgecumbe <git@esotericnonsense.com>2019-10-25 06:47:12 +0200
commitdfbda24cbd337c6e3dafcbbaec5d1dcd5bf3762b (patch)
treeff71a5536d6bc63970a8913438af45b493f52506
parent9927425c06c925c2210be742e1a14884b9d6764e (diff)
First actual test
-rwxr-xr-xgenapi/main.py6
-rw-r--r--src/json_rpc.rs6
-rw-r--r--src/main.rs16
3 files changed, 18 insertions, 10 deletions
diff --git a/genapi/main.py b/genapi/main.py
index e639e16..f1d7177 100755
--- a/genapi/main.py
+++ b/genapi/main.py
@@ -518,7 +518,7 @@ def generate_rust_types(simple_types: List[SimpleType]) -> str:
for value in simple_type.values
)
types.append(
- f"""#[derive(Deserialize, Serialize)]
+ f"""#[derive(Debug, Deserialize, Serialize)]
pub enum {simple_type.name} {{ {formatted_values} }}"""
)
continue
@@ -550,7 +550,7 @@ def generate_rust_data_types(data_types: List[DataType]) -> str:
types.append(f"/// {data_type.description}")
types.append(
- f"""#[derive(Deserialize, Serialize)]
+ f"""#[derive(Debug, Deserialize, Serialize)]
pub struct {data_type.name} {{ {formatted_params} }}"""
)
@@ -591,7 +591,7 @@ def generate_rust_functions(operations: List[Operation]) -> str:
)
functions.append(
- f"""#[derive(Deserialize, Serialize)]
+ f"""#[derive(Serialize)]
pub struct {struct_name} {{ {formatted_params_struct} }}"""
)
diff --git a/src/json_rpc.rs b/src/json_rpc.rs
index eb18b76..b7d3755 100644
--- a/src/json_rpc.rs
+++ b/src/json_rpc.rs
@@ -27,6 +27,12 @@ impl<T> RpcRequest<T> {
}
}
+impl<T> RpcResponse<T> {
+ pub fn into_inner(self) -> T {
+ self.result
+ }
+}
+
// listEventTypes Request
// [
// {
diff --git a/src/main.rs b/src/main.rs
index a4a66c1..d4924c5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -27,6 +27,8 @@ mod json_rpc;
const CERTLOGIN_URI: &str =
"https://identitysso-cert.betfair.com/api/certlogin";
+const JSONRPC_URI: &str =
+ "https://api.betfair.com/exchange/betting/json-rpc/v1";
const PFXFILE: &str = "/home/esotericnonsense/betfair/identity.pfx";
const APPKEYFILE: &str = "/home/esotericnonsense/betfair/betfair-app-key";
const USERFILE: &str = "/home/esotericnonsense/betfair/betfair-user";
@@ -93,14 +95,13 @@ fn get_session_token() -> Result<String, AnyError> {
use generated_api::{listMarketBookRequest, MarketBook};
use json_rpc::{RpcRequest, RpcResponse};
-//fn try_lmb(token: String) -> Result<Vec<MarketBook>, AnyError> {
-fn try_lmb(session_token: String) -> Result<(), AnyError> {
+fn try_lmb(session_token: String) -> Result<Vec<MarketBook>, AnyError> {
let app_key = fs::read_to_string(APPKEYFILE)?.replace("\n", "");
let cl: Client = Client::new();
let method = "SportsAPING/v1.0/listMarketBook".to_owned();
let params = listMarketBookRequest {
- marketIds: vec!["x".to_owned()],
+ marketIds: vec!["1.164123879".to_owned()],
priceProjection: None,
orderProjection: None,
matchProjection: None,
@@ -115,15 +116,15 @@ fn try_lmb(session_token: String) -> Result<(), AnyError> {
let rpc_request = RpcRequest::new(method, params);
// TODO handle exceptions
- let rpc_response: RpcResponse<listMarketBookRequest> = cl
- .post(CERTLOGIN_URI)
+ let rpc_response: RpcResponse<Vec<MarketBook>> = cl
+ .post(JSONRPC_URI)
.header("X-Application", app_key)
.header("X-Authentication", session_token)
.json(&rpc_request)
.send()?
.json()?;
- Ok(())
+ Ok(rpc_response.into_inner())
}
fn main() -> Result<(), AnyError> {
@@ -134,7 +135,8 @@ fn main() -> Result<(), AnyError> {
match get_session_token() {
Ok(x) => {
info!("got token {}", x);
- try_lmb(x);
+ let books: Vec<MarketBook> = try_lmb(x)?;
+ println!("{:?}", books);
Ok(())
}
Err(e) => {