A Simple API wrapper for https://spacetraders.io
Features:
- Covers all endpoints
- Automatic rate limiting to avoid overloading the servers and getting banned
- Fields deserialized into native types
SpaceMongers can be installed by adding space_mongers
to your list of dependencies in mix.exs
:
def deps do
[
{:space_mongers, "~> 0.3.0"}
]
end
For most requests, you will need an authenticated client which requires you to pass a username and token. You can claim a username and token with the following code:
{:ok, %{user: %{username: username}, token: token}} = SpaceMongers.claim_username("my_username")
You will need an authenticated client in order to make requests.
client = SpaceMongers.ApiClient.new(username, token)
A variety of requests can be found in the root SpaceMongers
module. These mostly require having an authenticated API client as the first argument.
Get the status of the servers:
> SpaceMongers.status()
{:ok, "spacetraders is currently online and available to play"}
View your user:
> SpaceMongers.current_user(client)
{:ok,
%SpaceMongers.Models.UserData{
credits: 106229,
loans: [
%SpaceMongers.Models.OwnedLoan{
due: ~U[2021-03-10 17:06:49.801Z],
id: "ckm0u713e104098v3890qzwcfrp",
repayment_amount: 280000,
status: "CURRENT",
type: "STARTUP"
}
],
ships: [
%SpaceMongers.Models.OwnedShip{
cargo: [
%SpaceMongers.Models.OwnedShip.ContainedGood{
good: "FUEL",
quantity: 43,
total_volume: 43
}
],
class: "MK-I",
id: "ckm0ud8bj107610v389eljwsx9d",
location: "OE-PM",
manufacturer: "Jackshaw",
max_cargo: 100,
plating: 5,
space_available: 57,
speed: 2,
type: "JW-MK-I",
weapons: 5,
x: 20,
y: -25
}
],
username: "my_username"
}}
Full docs for SpaceMonger can be found at https://hexdocs.pm/space_mongers.
API docs for spacetraders.io can be found at https://api.spacetraders.io
Please submit any issues you run into via GitHub. Pull Requests are accepted but I would appreciate if you messaged me in discord beforehand to avoid duplicated effort.