14 releases (stable)
1.1.0 | Jun 21, 2023 |
---|---|
1.0.9 | May 24, 2023 |
1.0.3 | Mar 16, 2023 |
1.0.1 | Feb 25, 2023 |
0.1.3 | Apr 25, 2022 |
#746 in Web programming
144 downloads per month
430KB
5.5K
SLoC
spacedustrs
This is a rust API wrapper for https://spacetraders.io V2
Now generated by https://openapi-generator.tech/docs/generators/rust/
Includes patches for documentation missing from the main API docs
Quickstart
Use the following example to get started.
use spacedust::apis::agents_api::get_my_agent;
use spacedust::apis::configuration::Configuration;
use spacedust::apis::default_api::register;
use spacedust::models::register_request::{Faction, RegisterRequest};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create Configuration
let mut conf = Configuration::new();
// Create Register Request
let reg_req = RegisterRequest::new(Faction::Cosmic, "<3-14 character string>".to_string());
// Register Agent
let register_response = register(&conf, Some(reg_req)).await;
match register_response {
Ok(res) => {
println!("{:#?}", res);
// Update Config with Agent Token
conf.bearer_access_token = Some(res.data.token);
}
Err(err_res) => {
panic!("{:#?}", err_res);
}
}
// Get Agent Details to Confirm Working
match get_my_agent(&conf).await {
Ok(res) => {
println!("{:#?}", res);
// Print Symbol
println!("My Symbol: {:#?}", res.data.symbol);
}
Err(err_res) => {
panic!("{:#?}", err_res);
}
}
Ok(())
}
Generation Instructions
FIRST update the docs fork with the spacedust patches. You can just 'Sync Fork' from the github web UI unless there are merge conflicts (there haven't been so far)
Clone the project, including --recurse-submodules:
git clone --recurse-submodules git@github.com:brct-james/spacedustrs.git
Ensure submodules are initialized and updated:
git submodule update --init --recursive --remote
Clean the output directory:
sudo rm -rf client-dist
Remake the directory:
mkdir client-dist
Update your local image of openapitools/openapi-generator-cli:latest-release
docker pull openapitools/openapi-generator-cli:latest-release
Run the following command, which uses the openapi-generator-cli docker image to generate the client:
docker run --rm \
-v ${PWD}:/local openapitools/openapi-generator-cli:latest-release generate \
-i /local/spacetraders-api-docs-spacedust-patch/reference/SpaceTraders.json \
-g rust \
-o /local/client-dist \
--additional-properties=packageName=spacedust,supportAsync=true,supportMiddleware=true
Copy the client-dist/src to src
cp -r client-dist/src .
Notice: For the moment, manually check that the content-length middleware fixes (cargo.toml dependencies async-trait
and task-local-extensions
, lib.rs mod middleware
, src/middleware.rs, and src/apis/configuration.rs reqwest_middleware_builder
) are not being reverted. You will probably need to use at minimum the following:
git checkout 34a74b36e341444a8dbe6ee979bb0163cbfe3bb9 src/apis/configuration.rs
git checkout 34a74b36e341444a8dbe6ee979bb0163cbfe3bb9 src/lib.rs
Todo: Create a better merge strategy - perhaps maintain the content-length-middleware branch and merge it into the local branch after generating a new client?
Update Cargo.toml with any new dependencies, update documentation, tick version, commit changes, and publish to cargo
Dependencies
~4–17MB
~236K SLoC