opal

package module
v0.0.0-...-10628ed Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2015 License: Apache-2.0 Imports: 16 Imported by: 0

README

This is a Go package for accessing data about an Opal card.

GoDoc

It is not anything particularly useful for users (yet); it is currently intended for programmers to use as a building block.

To get it,

go get github.com/dsymonds/opal

You will need to put auth information in $HOME/.opal that looks like

{"Username":"xxx","Password":"yyy"}

Don't forget to chmod 600 $HOME/.opal. I plan to make it easier to pass to this package programmatically.

To do a quick test that will access your card information and print out its balance and recent transactions,

go test -v github.com/dsymonds/opal

Documentation

Overview

Package opal provides programmatic access to Opal card information.

Index

Constants

This section is empty.

Variables

View Source
var DefaultAuthFile = filepath.Join(os.Getenv("HOME"), ".opal")

DefaultAuthFile is a default place to store authentication information. Pass this to FileAuthStore if an alternate path isn't required.

Functions

This section is empty.

Types

type Activity

type Activity struct {
	CardName     string
	Transactions []*Transaction
}

Activity represents a subset of activity for a single card.

type ActivityRequest

type ActivityRequest struct {
	CardIndex int
	// Offset is how many pages into the past to fetch.
	// Zero is the most recent activity.
	Offset int
}

An ActivityRequest configures the operation of Activity.

type Auth

type Auth struct {
	Username, Password string
	Cookies            []*http.Cookie
}

Auth holds the authentication information for accessing Opal.

type AuthStore

type AuthStore interface {
	Load() (*Auth, error)
	Save(*Auth) error
}

An AuthStore is an interface for loading and saving authentication information. See FileAuthStore for a file-based implementation.

func FileAuthStore

func FileAuthStore(filename string) AuthStore

FileAuthStore returns an AuthStore that stores authentication information in a named file.

type Card

type Card struct {
	Name    string // either a name or number
	Balance int    // in cents
}

Card represents a single Opal card.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an interface to the online Opal system.

func NewClient

func NewClient(as AuthStore) (*Client, error)

NewClient constructs a new Client.

func (*Client) Activity

func (c *Client) Activity(req ActivityRequest) (*Activity, error)

Activity fetches a subset of the activity data for a card.

func (*Client) Overview

func (c *Client) Overview() (*Overview, error)

Overview fetches the account overview.

func (*Client) WriteConfig

func (c *Client) WriteConfig() error

WriteConfig writes the configuration to the client's AuthStore.

type Overview

type Overview struct {
	Cards []Card
}

Overview represents an overview of an Opal account.

type Transaction

type Transaction struct {
	Number        int
	When          time.Time
	Mode          string // "train", etc., if known
	Details       string
	JourneyNumber int // if known; numbered within the week

	FareApplied            string // e.g. "Off-peak", "Travel Reward"
	Fare, Discount, Amount int    // in cents
}

Transaction represents a single transaction on a card. This may be a single journey, or a top-up. Not all fields may be set.

func (*Transaction) String

func (t *Transaction) String() string

Jump to

Keyboard shortcuts

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