alejandro-ap00 / space-traders-php-sdk
A Space Traders SDK for PHP
Fund package maintenance!
AlejandroAPorras
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.8
Requires (Dev)
- laravel/pint: ^1.0
- pestphp/pest: ^2.20
- spatie/ray: ^1.28
README
An PHP SDK for the SpaceTraders API this package provides an expressive way to interact with all endpoints available.
Installation
You can install the package via composer:
composer require alejandro-ap00/space-traders-php-sdk
Usage
To get started, please create an instance of the SDK
use AlejandroAPorras\SpaceTraders; $space_traders = new SpaceTraders('Your JWT bearer token');
Handling Pagination
There are several methods, such as agents()
, contracts()
and ships()
to will return paginated results. To
get the next page of results just call next() on a result. If there are no more results, that method returns null.
On paginated results, there are also some more convenience methods:
results()
: get the results. A results object is also iterable, so you can also get to the results by simply using the object in a loopnext()
: fetch the next page of resultsprevious()
: fetch the previous page of resultscurrentPage()
: get the current page numbertotal()
: get the total number of results across all pagestotalPages()
: get the total number of pagesnextPage()
: get the page number for the next page of resultspreviousPage()
: get the page number for the previous page of results
Registering
You can generate a new token using the register method
use AlejandroAPorras\SpaceTraders\Enums\FactionSymbol; $space_traders->register(FactionSymbol::COSMIC, 'T3ST_US3R', 'your@email.com')
Getting API status
$space_traders->getStatus();
Managing Contracts
$space_traders->contracts(['page' => 1]); $space_traders->contract(string $contractId); $space_traders->acceptContract(string $contractId); $space_traders->deliverContract(string $contractId, string $shipSymbol, TradeGoodSymbol $tradeSymbol, int $units); $space_traders->fulfillContract(string $contractId);
On a Contract
instance you can call
$contract->accept(); $contract->deliver(string $shipSymbol, TradeGoodSymbol $tradeSymbol, int $units); $contract->fulfill();
Managing Agents
$space_traders->agent(); $space_traders->agents(['page' => 1]); $space_traders->publicAgent(string $agent);
Managing Factions
$space_traders->factions(['page' => 1]); $space_traders->faction();
Managing Fleet
$space_traders->ships(['page' => 1]); $space_traders->purchaseShip(ShipType $shipType, string $waypointSymbol); $space_traders->ship(string $shipSymbol); $space_traders->shipCargo(string $shipSymbol); $space_traders->orbitShip(string $shipSymbol); $space_traders->refineShip(string $shipSymbol, ProduceType $produce); $space_traders->chartShip(string $shipSymbol); $space_traders->shipCooldown(string $shipSymbol); $space_traders->dockShip(string $shipSymbol); $space_traders->createSurvey(string $shipSymbol); $space_traders->extractResources(string $shipSymbol); $space_traders->createSurvey(string $shipSymbol); $space_traders->siphonResources(string $shipSymbol); $space_traders->extractResourcesWithSurvey(string $shipSymbol, Survey $survey); $space_traders->jettisonCargo(string $shipSymbol, TradeGoodSymbol $symbol, int $units); $space_traders->jumpShip(string $shipSymbol, string $waypointSymbol); $space_traders->navigateShip(string $shipSymbol, string $waypointSymbol); $space_traders->patchShipNav(string $shipSymbol, ShipNavFlightMode $flightMode); $space_traders->shipNav(string $shipSymbol); $space_traders->warpShip(string $shipSymbol, string $waypointSymbol); $space_traders->sellCargo(string $shipSymbol, TradeGoodSymbol $symbol, int $units); $space_traders->scanSystems(string $shipSymbol); $space_traders->scanWaypoints(string $shipSymbol); $space_traders->scanShips(string $shipSymbol); $space_traders->refuelShip(string $shipSymbol, int $units, bool $fromCargo = false); $space_traders->purchaseCargo(string $shipSymbol, TradeGoodSymbol $symbol, int $units); $space_traders->transferCargo(string $shipSymbol, TradeGoodSymbol $symbol, int $units, string $transferShipSymbol); $space_traders->negotiateContract(string $shipSymbol); $space_traders->shipMounts(string $shipSymbol); $space_traders->installShipMount(string $shipSymbol, string $mountSymbol); $space_traders->removeShipMount(string $shipSymbol, string $mountSymbol); $space_traders->scrapShipValue(string $shipSymbol); $space_traders->scrapShip(string $shipSymbol); $space_traders->repairShipValue(string $shipSymbol); $space_traders->repairShip(string $shipSymbol);
On a Ship
instance you can call
$ship->cargo(); $ship->orbit(); $ship->refine(ProduceType $produce); $ship->chart(); $ship->cooldown(); $ship->dock(); $ship->survey(); $ship->extractResources(); $ship->siphonResources(); $ship->extractResourcesWithSurvey(Survey $survey); $ship->jettisonCargo(TradeGoodSymbol $tradeGoodSymbol, int $units); $ship->jump(string $waypointSymbol); $ship->navigate(string $waypointSymbol); $ship->patchNav(ShipNavFlightMode $flightMode); $ship->nav(); $ship->warp(string $waypointSymbol); $ship->sellCargo(TradeGoodSymbol $tradeGoodSymbol, int $units); $ship->scanSystems(); $ship->scanWaypoints(); $ship->scanShips(); $ship->refuel(int $units, bool $fromCargo = false); $ship->purchaseCargo(TradeGoodSymbol $tradeGoodSymbol, int $units); $ship->transferCargo(TradeGoodSymbol $tradeGoodSymbol, int $units, string $transferShipSymbol); $ship->negotiateContract(); $ship->mounts(); $ship->installMount(string $mountSymbol); $ship->removeMount(string $mountSymbol); $ship->scrapValue(); $ship->scrap(); $ship->repairValue(); $ship->repair();
Managing Systems
$space_traders->systems(['page' => 1]); $space_traders->system(string $systemSymbol); $space_traders->waypoints(string $systemSymbol, ['page' => 1]); $space_traders->waypoint(string $systemSymbol, string $waypointSymbol); $space_traders->market(string $systemSymbol, string $waypointSymbol); $space_traders->shipyard(string $systemSymbol, string $waypointSymbol); $space_traders->jumpGate(string $systemSymbol, string $waypointSymbol); $space_traders->construction(string $systemSymbol, string $waypointSymbol); $space_traders->supplyConstruction(string $systemSymbol, string $waypointSymbol, string $shipSymbol, TradeGoodSymbol $tradeSymbol, int $units);
On a System
instance you can call
$system->waypoints();
and in a Waypoint
instance you can call
$waypoint->market(); $waypoint->shipyard(); $waypoint->jumpGate(); $waypoint->construction(); $waypoint->supplyConstruction(string $shipSymbol, TradeGoodSymbol $tradeSymbol, int $units);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.