@@ -35,6 +35,7 @@ var cookieBaseURL = &url.URL{
35
35
Host : "www.opal.com.au" ,
36
36
}
37
37
38
+ // NewClient constructs a new Client.
38
39
func NewClient (as AuthStore ) (* Client , error ) {
39
40
a , err := as .Load ()
40
41
if err != nil {
@@ -57,11 +58,13 @@ func NewClient(as AuthStore) (*Client, error) {
57
58
return c , nil
58
59
}
59
60
61
+ // WriteConfig writes the configuration to the client's AuthStore.
60
62
func (c * Client ) WriteConfig () error {
61
63
c .a .Cookies = c .hc .Jar .Cookies (cookieBaseURL )
62
64
return c .as .Save (c .a )
63
65
}
64
66
67
+ // Overview fetches the account overview.
65
68
func (c * Client ) Overview () (* Overview , error ) {
66
69
body , err := c .get ("https://www.opal.com.au/registered/index" )
67
70
if err != nil {
@@ -70,13 +73,15 @@ func (c *Client) Overview() (*Overview, error) {
70
73
return parseOverview (body )
71
74
}
72
75
76
+ // An ActivityRequest configures the operation of Activity.
73
77
type ActivityRequest struct {
74
78
CardIndex int
75
79
// Offset is how many pages into the past to fetch.
76
80
// Zero is the most recent activity.
77
81
Offset int
78
82
}
79
83
84
+ // Activity fetches a subset of the activity data for a card.
80
85
func (c * Client ) Activity (req ActivityRequest ) (* Activity , error ) {
81
86
u := fmt .Sprintf ("https://www.opal.com.au/registered/opal-card-transactions/?cardIndex=%d" , req .CardIndex )
82
87
if req .Offset > 0 {
@@ -155,13 +160,18 @@ func (c *Client) login() error {
155
160
return nil
156
161
}
157
162
163
+ // An AuthStore is an interface for loading and saving authentication information.
164
+ // See FileAuthStore for a file-based implementation.
158
165
type AuthStore interface {
159
166
Load () (* Auth , error )
160
167
Save (* Auth ) error
161
168
}
162
169
170
+ // DefaultAuthFile is a default place to store authentication information.
171
+ // Pass this to FileAuthStore if an alternate path isn't required.
163
172
var DefaultAuthFile = filepath .Join (os .Getenv ("HOME" ), ".opal" )
164
173
174
+ // FileAuthStore returns an AuthStore that stores authentication information in a named file.
165
175
func FileAuthStore (filename string ) AuthStore {
166
176
return fileAuthStore {filename }
167
177
}
0 commit comments