stapi

package
v0.0.0-...-8ca5219 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorCodeGoodNotInMarketplace = 2001
	ErrorCodeInsufficientFunds    = 2004
	ErrorCodeNotFound             = 404
)

Known error codes

View Source
const (
	LocationTypeUnknown = iota
	LocationTypePlanet
	LocationTypeMoon
	LocationTypeWormhole
	LocationTypeAsteroid
	LocationTypeGasGiant
)
View Source
const (
	URLBase = "https://api.spacetraders.io/"
)

Variables

View Source
var (
	ErrorSystemNotFound   = errors.New("stapi: system not found")
	ErrorLocationNotFound = errors.New("stapi: location is not detectable or does not exist")
)
View Source
var (
	URLUserInfo = func(username string) string { return URLBase + "users/" + username }

	URLSystemLocations     = func(system string) string { return URLBase + "game/systems/" + system + "/locations" }
	URLLocationInformation = func(location string) string { return URLBase + "game/locations/" + location }

	URLMarketplaceAtLocation = func(location string) string { return URLBase + "game/locations/" + location + "/marketplace" }
	URLSubmitPurchaseOrder   = func(username string) string { return URLBase + "users/" + username + "/purchase-orders" }
	URLSubmitSellOrder       = func(username string) string { return URLBase + "users/" + username + "/sell-orders" }
	URLJettisonCargo         = func(username, ship string) string {
		return URLBase + "users/" + username + "/ships/" + ship + "/jettison"
	}

	URLSubmitFlightplan         = func(username string) string { return URLBase + "users/" + username + "/flight-plans" }
	URLGetFlightplanInformation = func(username, flightplanID string) string {
		return URLBase + "users/" + username + "/flight-plans/" + flightplanID
	}

	URLGetShipInfo = func(username, shipID string) string { return URLBase + "users/" + username + "/ships/" + shipID }
)
View Source
var (
	ErrorCannotViewMarketplace = errors.New("stapi: marketplace listings are only visible to docked ships at this location")
)
View Source
var ErrorFailedRatelimit = errors.New("stapi: unable to make request (too many responses with 429)")
View Source
var (
	ErrorUserNotFound = errors.New("stapi: user not found")
)

Functions

This section is empty.

Types

type Cargo

type Cargo struct {
	Good        string `json:"good"`
	Quantity    int    `json:"quantity"`
	TotalVolume int    `json:"totalVolume"`
}

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type Flightplan

type Flightplan struct {
	ID                  string     `json:"id"`
	ShipID              string     `json:"shipId"`
	CreatedAt           *time.Time `json:"createdAt"`
	ArrivesAt           *time.Time `json:"arrivesAt"`
	Destination         string     `json:"destination"`
	Departure           string     `json:"departure"`
	Distance            int        `json:"distance"`
	FuelConsumed        int        `json:"fuelConsumed"`
	FuelRemaining       int        `json:"fuelRemaining"`
	TerminatedAt        *time.Time `json:"terminatedAt"`
	FlightTimeRemaining int        `json:"timeRemainingInSeconds"`
}

type Loan

type Loan struct {
	ID              string     `json:"id"`
	Due             *time.Time `json:"due"`
	RepaymentAmount int        `json:"repaymentAmount"`
	Status          string     `json:"status"`
	Type            string     `json:"type"`
}

type Location

type Location struct {
	Symbol         string             `json:"symbol"`
	Type           LocationType       `json:"type"`
	Name           string             `json:"name"`
	XCoordinate    int                `json:"x"`
	YCoordinate    int                `json:"y"`
	Ships          []*Ship            `json:"ships"`
	AvailableGoods []*MarketplaceGood `json:"marketplace"`
}

func GetLocationInfo

func GetLocationInfo(location string) (*Location, error)

func GetSystemLocations

func GetSystemLocations(system string) ([]*Location, error)

type LocationType

type LocationType uint

func (*LocationType) UnmarshalJSON

func (l *LocationType) UnmarshalJSON(data []byte) error

type MarketplaceGood

type MarketplaceGood struct {
	Symbol               string `json:"symbol"`
	VolumePerUnit        int    `json:"volumePerUnit"`
	PricePerUnit         int    `json:"pricePerUnit"`
	Spread               int    `json:"spread"`
	PurchasePricePerUnit int    `json:"purchasePricePerUnit"`
	SellPricePerUnit     int    `json:"sellPricePerUnit"`
	QuantityAvailable    int    `json:"quantityAvailable"`
}

func GetMarketplaceAtLocation

func GetMarketplaceAtLocation(location string) ([]*MarketplaceGood, error)

type Order

type Order struct {
	Good         string `json:"good"`
	Quantity     int    `json:"quantity"`
	PricePerUnit int    `json:"pricePerUnit"`
	Total        int    `json:"total"`
}

type Ship

type Ship struct {
	ID             string   `json:"id"`
	Location       string   `json:"location"`
	XCoordinate    int      `json:"x"`
	YCoordinate    int      `json:"y"`
	Cargo          []*Cargo `json:"cargo"`
	SpaceAvailable int      `json:"spaceAvailable"`
	Type           string   `json:"type"`
	Class          string   `json:"class"`
	MaxCargo       int      `json:"maxCargo"`
	Speed          int      `json:"speed"`
	Manufacturer   string   `json:"manufacturer"`
	Plating        int      `json:"plating"`
	Weapons        int      `json:"weapons"`
}

func (*Ship) GetCurrentFuel

func (s *Ship) GetCurrentFuel() int

type User

type User struct {
	Username string  `json:"username"`
	Credits  int     `json:"credits"`
	Ships    []*Ship `json:"ships"`
	Loans    []*Loan `json:"loans"`
	// contains filtered or unexported fields
}

func GetUserInfo

func GetUserInfo(username string) (*User, error)

func (*User) GetFlightplan

func (u *User) GetFlightplan(flightplanID string) (*Flightplan, error)

func (*User) GetShipInfo

func (u *User) GetShipInfo(shipID string) (*Ship, error)

func (*User) JettisonCargo

func (u *User) JettisonCargo(shipID, good string, quantity int) error

func (*User) SubmitFlightplan

func (u *User) SubmitFlightplan(shipID, destination string) (*Flightplan, error)

func (*User) SubmitPurchaseOrder

func (u *User) SubmitPurchaseOrder(shipID, good string, quantity int) (*Ship, error)

func (*User) SubmitSellOrder

func (u *User) SubmitSellOrder(shipID, good string, quantity int) (*Ship, *Order, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL