api

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2020 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package api implements a trading API client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action uint
const (
	ActionAddItem Action = iota
	ActionRemoveItem
	ActionReady
	ActionUnready
	ActionAccept

	ActionSetCurrency
	ActionChatMessage
)

type Client

type Client struct {
	LogPos  uint // not automatically updated
	Version uint // Incremented for each item change by Steam; not automatically updated.
	// contains filtered or unexported fields
}

func New

func New(sessionID, steamLogin, steamLoginSecure string, other steamid.SteamID) (*Client, error)

New creates a new Trade based on the given cookies `sessionid`, `steamLogin`, `steamLoginSecure` and the trade partner's Steam ID.

func (*Client) AddItem

func (t *Client) AddItem(slot uint, itemID, contextID uint64, appID uint32) (*Result, error)

func (*Client) Cancel

func (t *Client) Cancel() (*Result, error)

func (*Client) Chat

func (t *Client) Chat(message string) (*Result, error)

func (*Client) Confirm

func (t *Client) Confirm() (*Result, error)

func (*Client) GetForeignInventory

func (t *Client) GetForeignInventory(contextID uint64, appID uint32, start uint) (*inventory.PartialInventory, error)

Thread-safe.

func (*Client) GetMain

func (t *Client) GetMain() (*Main, error)

GetMain fetches the main HTML page and parses it. Thread-safe.

func (*Client) GetOwnInventory

func (t *Client) GetOwnInventory(contextID uint64, appID uint32) (*inventory.Inventory, error)

Thread-safe.

func (*Client) GetStatus

func (t *Client) GetStatus() (*Result, error)

func (*Client) RemoveItem

func (t *Client) RemoveItem(slot uint, itemID, contextID uint64, appID uint32) (*Result, error)

func (*Client) SetCurrency

func (t *Client) SetCurrency(amount uint, currencyID, contextID uint64, appID uint32) (*Result, error)

func (*Client) SetReady

func (t *Client) SetReady(ready bool) (*Result, error)

type Currency

type Currency struct {
	AppID      uint64 `json:",string"`
	ContextID  uint64 `json:",string"`
	CurrencyID uint64 `json:",string"`
	Amount     uint64 `json:",string"`
}

type Event

type Event struct {
	SteamID   steamid.SteamID `json:",string"`
	Action    Action          `json:",string"`
	Timestamp uint64

	AppID     uint32
	ContextID uint64 `json:",string"`
	AssetID   uint64 `json:",string"`

	Text string // only used for chat messages

	// The following is used for SetCurrency
	CurrencyID uint64 `json:",string"`
	OldAmount  uint64 `json:"old_amount,string"`
	NewAmount  uint64 `json:"amount,string"`
}

type EventList

type EventList map[uint]*Event

func (*EventList) UnmarshalJSON

func (e *EventList) UnmarshalJSON(data []byte) error

The EventList can either be an array or an object of id -> event

type Main

type Main struct {
	PartnerOnProbation bool
}

type Result

type Result struct {
	Success     bool
	Error       string
	NewVersion  bool   `json:"newversion"`
	TradeStatus Status `json:"trade_status"`
	Version     uint
	LogPos      int
	Me          User
	Them        User
	Events      EventList
}

type Status

type Status uint
const (
	StatusOpen Status = iota
	StatusComplete
	StatusEmpty // when both parties trade no items
	StatusCanceled
	StatusTimeout // the partner timed out
	StatusFailed
)

type User

type User struct {
	Ready             jsont.UintBool
	Confirmed         jsont.UintBool
	SecSinceTouch     int  `json:"sec_since_touch"`
	ConnectionPending bool `json:"connection_pending"`
	Assets            interface{}
	Currency          interface{} // either []*Currency or empty string
}

Jump to

Keyboard shortcuts

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