Documentation
¶
Overview ¶
Package irdata provides simplified access to the [iRacing /data API]
- Authentication is handled internally and credentials can be saved in an encrypted credentials file protected by a secure key file.
- The iRacing /data API returns data in the form of S3 links. This package delivers the S3 results directly handling all the redirection.
- If an API endpoint returns chunked data, irdata will handle the chunk fetching and return a merged object (note, it could be *huge*)
- An optional caching layer is provided to minimize direct calls to the /data endpoints themselves as those are rate limited.
[iRacing /data API] https://forums.iracing.com/discussion/15068/general-availability-of-data-api/p1
Index ¶
- Constants
- Variables
- type AuthTokenT
- type CredsFromTerminal
- type CredsProvider
- type Irdata
- func (i *Irdata) AuthAndSaveProvidedCredsToFile(keyFilename string, authFilename string, authSource CredsProvider) error
- func (i *Irdata) AuthWithCredsFromFile(keyFilename string, authFilename string) error
- func (i *Irdata) AuthWithProvideCreds(authSource CredsProvider) error
- func (i *Irdata) Close()
- func (i *Irdata) EnableCache(cacheDir string) error
- func (i *Irdata) Get(uri string) ([]byte, error)
- func (i *Irdata) GetWithCache(uri string, ttl time.Duration) ([]byte, error)
- func (i *Irdata) SetAuthTokenFile(filename string)
- func (i *Irdata) SetLogLevel(logLevel LogLevel)
- func (i *Irdata) SetRateLimitHandler(handler RateLimitHandler)
- func (i *Irdata) SetRetries(retries int)
- func (i *Irdata) SetS3LinkCallback(callback func(link string))
- type LogLevel
- type RateLimitExceededError
- type RateLimitHandler
- type TokenResponse
Constants ¶
const ChunkDataKey = "_chunk_data"
Variables ¶
var TokenURL = "https://oauth.iracing.com/oauth2/token"
Functions ¶
This section is empty.
Types ¶
type AuthTokenT ¶ added in v0.6.3
type CredsFromTerminal ¶
type CredsFromTerminal struct{}
type CredsProvider ¶
type Irdata ¶
type Irdata struct {
// Auth Data used for Refreshing
AccessToken string
RefreshToken string
TokenExpiry time.Time
ClientID string
ClientSecret string
// S3 Link callback
S3LinkCallback func(link string)
// contains filtered or unexported fields
}
func (*Irdata) AuthAndSaveProvidedCredsToFile ¶ added in v0.4.3
func (i *Irdata) AuthAndSaveProvidedCredsToFile(keyFilename string, authFilename string, authSource CredsProvider) error
AuthAndSaveProvidedCredsToFile calls the provided function for the credentials, verifies auth, and then saves them to authFilename using the key in keyFilename
func (*Irdata) AuthWithCredsFromFile ¶
AuthWithCredsFromFile loads the username and password from a file at authFilename and encrypted with the key in keyFilename.
func (*Irdata) AuthWithProvideCreds ¶
func (i *Irdata) AuthWithProvideCreds(authSource CredsProvider) error
AuthWithProvideCreds calls the provided function for the credentials
func (*Irdata) Close ¶
func (i *Irdata) Close()
Close Calling Close when done is important when using caching - this will compact the cache.
func (*Irdata) EnableCache ¶
EnableCache enables on the optional caching layer which will use the directory path provided as cacheDir
func (*Irdata) Get ¶
Get returns the result value for the uri provided (e.g. "/data/member/info")
The value returned is a JSON byte array and a potential error.
func (*Irdata) GetWithCache ¶
GetWithCache will first check the local cache for an unexpired result and will the call Get with the uri provided.
The ttl defines for how long the results should be cached.
You must call EnableCache before calling GetWithCache NOTE: If data is fetched this will return the data even if it can't be written to the cache (along with an error)
func (*Irdata) SetAuthTokenFile ¶ added in v0.6.3
SetAuthTokenFile sets the filename where the authentication token will be persisted. The token is encrypted using the same key as the credentials file.
func (*Irdata) SetLogLevel ¶ added in v0.4.0
SetLogLevel sets the loging level using the logrus module
func (*Irdata) SetRateLimitHandler ¶ added in v0.4.6
func (i *Irdata) SetRateLimitHandler(handler RateLimitHandler)
SetRateLimitHandler sets the desired behavior for handling API rate limits. The default is RateLimitError.
func (*Irdata) SetRetries ¶ added in v0.4.6
SetRetries sets the number of times a get will be retried if a retriable error is encountered (e.g. a 5xx)
func (*Irdata) SetS3LinkCallback ¶ added in v0.6.2
SetS3LinkCallback sets a callback function to be invoked when an S3 link is identified and followed.
type RateLimitExceededError ¶ added in v0.4.6
RateLimitExceededError is returned when the iRacing API rate limit has been exceeded. It includes the time when the rate limit is expected to reset.
func (*RateLimitExceededError) Error ¶ added in v0.4.6
func (e *RateLimitExceededError) Error() string
type RateLimitHandler ¶ added in v0.4.6
type RateLimitHandler int
RateLimitHandler defines the behavior when a rate limit is encountered.
const ( // RateLimitError (default) will cause Get methods to return a RateLimitExceededError. RateLimitError RateLimitHandler = iota // RateLimitWait will cause the Get method to pause and wait until the rate limit resets. RateLimitWait )
type TokenResponse ¶ added in v0.6.0
type TokenResponse struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
Scope string `json:"scope"`
}
TokenResponse maps the JSON response from the /token endpoint