new Client(options)
Constructs a new Fantasy Client. Each client is tied to a single account.
For most applications, you will only need to instantiate one client.
Parameters:
Name | Type | Description |
---|---|---|
options |
ClientOptions | The optional client settings |
Members
-
_cookie :Map
-
The cookie that we are sending to make requests.
Type:
- Map
-
<private> _cookieString :String
-
The stringified cookie to make requests with
Type:
- String
-
<constant> API_URL :String
-
The base url for the API
Type:
- String
-
circuits :Map.<String, Circuit>
-
The circuits cache, keyed by the short name (short_name)
Type:
- Map.<String, Circuit>
-
constructors :Map.<String, Constructor>
-
The constructor cache, keyed by numeric ID
Type:
- Map.<String, Constructor>
-
currentGrandPrix :GrandPrix
-
The current Grand Prix for this week
Type:
-
debug :Boolean
-
Whether to enable debug mode
Type:
- Boolean
-
drivers :Map.<String, Driver>
-
The driver cache, keyed by numeric ID
Type:
- Map.<String, Driver>
-
grandsPrix :Map.<String, GrandPrix>
-
The Grand Prix cache, keyed by the short name (short_name)
Type:
- Map.<String, GrandPrix>
-
league :Map.<Number, League>
-
The leagues cache, keyed by their numeric league ID
Type:
- Map.<Number, League>
-
<private> loginSession :Object
-
Login session data
Type:
- Object
Properties:
Name Type Description data
Object The data object that contains the subscriptionToken -
loginSessionExpiry :Date
-
Expiry date for the current login session
Type:
- Date
-
races :Map.<String, Race>
-
The races cache
Type:
- Map.<String, Race>
-
user :ClientUser
-
The user for this client
Type:
-
userID :Number
-
The numeric ID of the logged-in user
Type:
- Number
-
users :Map.<T, User>
-
The Fantasy F1 player cache
Type:
- Map.<T, User>
Methods
-
<private> _decodeJWT(jwt)
-
Base64 decodes a JSON web token
Parameters:
Name Type Description jwt
String The string-based JSON web token to decode Returns:
Array of 3 parts, the first 2 base64 decoded- Type
- Array
-
<private> _getPlayOnSession(loginSession)
-
Creates a PlayOn session for authenticated requests
Parameters:
Name Type Description loginSession
Object The login session returned from the authentication by-password endpoint Returns:
The PlayOn session cookie- Type
- Promise.<String>
-
<private> _loginWithPassword(username, password)
-
Logs in with a password
Parameters:
Name Type Description username
String The email of the account password
String The password of the account Returns:
An array containing the login session object, the login session expiry, and the numeric player ID- Type
- Promise.<Array>
-
<private> _request(options)
-
Makes an HTTP request to an endpoint
Parameters:
Name Type Description options
RequestOptions Extra options for the HTTP request -
fetchClientUser(forceUpdate)
-
Fetch the client user and add it to the cache
Parameters:
Name Type Description forceUpdate
Boolean Whether to ignore the cache and update the list directly Returns:
The client user- Type
- Promise.<User>
-
fetchDriversAndConstructors(forceUpdate)
-
Fetch all drivers and constructors and add them to cache
Parameters:
Name Type Description forceUpdate
Boolean Whether to ignore the cache and update the list directly Returns:
Map -
init()
-
Fetches the Grand Prix list, the Driver list, the Constructor list, and the ClientUser
Returns:
- Type
- Promise.<Client>
-
login(username, password)
-
Logs in using a username and password and calls Client#init
Parameters:
Name Type Description username
String Account username to the F1 Fantasy API password
String Account password to the F1 Fantasy API