datasource

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const MaxTasks = 4
View Source
const StravaAPITokenUrl = "https://www.strava.com/api/v3/oauth/token"
View Source
const StravaAPIUrl = "https://www.strava.com/api/v3"
View Source
const StravaApiQueryType = "stravaAPI"
View Source
const StravaAuthQueryType = "stravaAuth"

Variables

View Source
var ErrAlertingNotSupported = errors.New("alerting not supported")

Functions

func HashByte added in v1.5.0

func HashByte(data []byte) string

HashByte converts the given bytes to hash string

func HashDatasourceInfo

func HashDatasourceInfo(dsInfo *backend.DataSourceInstanceSettings) string

HashDatasourceInfo converts the given datasource info to hash string

func HashString

func HashString(text string) string

HashString converts the given text string to hash string

Types

type ActivityDTO added in v1.5.0

type ActivityDTO = struct {
	Id int64 `json:"id"`
}

type DSCache

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

DSCache is a abstraction over go-cache.

func NewDSCache

func NewDSCache(dsInfo *backend.DataSourceInstanceSettings, ttl time.Duration, cleanupInterval time.Duration, dataDir string) *DSCache

NewDSCache creates a go-cache with expiration(ttl) time and cleanupInterval.

func (*DSCache) Delete added in v1.4.0

func (c *DSCache) Delete(request string)

Remove item from cache

func (*DSCache) Flush added in v1.5.0

func (c *DSCache) Flush()

Delete all items from the cache.

func (*DSCache) Get

func (c *DSCache) Get(request string) (interface{}, bool)

Get the value associated with request from the cache

func (*DSCache) Load

func (c *DSCache) Load(request string) (string, error)

Load value from disk

func (*DSCache) Save

func (c *DSCache) Save(request string, response interface{}) error

Save value to disk

func (*DSCache) Set

func (c *DSCache) Set(request string, response interface{})

Add an item to the cache with default expiration time, replacing any existing item.

func (*DSCache) SetDefault

func (c *DSCache) SetDefault(request string, response interface{})

Set the value of the key "request" to "response" with default expiration time.

func (*DSCache) SetWithExpiration added in v1.5.0

func (c *DSCache) SetWithExpiration(request string, response interface{}, d time.Duration)

Save item to the cache with provided expiration time

func (*DSCache) SetWithNoExpiration added in v1.5.0

func (c *DSCache) SetWithNoExpiration(request string, response interface{})

Save item to the cache with no expiration

type PrefetchStreamTask added in v1.5.0

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

type QueryModel

type QueryModel struct {
	QueryType    string `json:"queryType"`
	ActivityStat string `json:"activityStat"`
	ActivityType string `json:"activityType"`
	Format       string `json:"format"`
	Interval     string `json:"interval"`

	// Direct from the gRPC interfaces
	TimeRange backend.TimeRange `json:"-"`
}

QueryModel model

func ReadQuery

func ReadQuery(query backend.DataQuery) (QueryModel, error)

ReadQuery will read and validate Settings from the DataSourceConfig

type StravaAPIRequest

type StravaAPIRequest struct {
	Endpoint    string                     `json:"endpoint"`
	Params      map[string]json.RawMessage `json:"params,omitempty"`
	AccessToken string
}

type StravaApiResourceResponse

type StravaApiResourceResponse struct {
	Result interface{} `json:"result,omitempty"`
}

func BuildAPIResponse

func BuildAPIResponse(apiResponse []byte) (*StravaApiResourceResponse, error)

type StravaAuthRequest

type StravaAuthRequest struct {
	AuthCode string `json:"authCode"`
}

type StravaAuthResourceResponse

type StravaAuthResourceResponse struct {
	Result interface{} `json:"result,omitempty"`
}

type StravaDatasourceInstance

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

StravaDatasourceInstance stores state about a specific datasource and provides methods to make requests to the Strava API

func (*StravaDatasourceInstance) ExchangeToken

func (ds *StravaDatasourceInstance) ExchangeToken(authCode string) (*TokenExchangeResponse, error)

ExchangeToken invokes first time when authentication required and exchange authorization code for the access and refresh tokens https://developers.strava.com/docs/authentication/#tokenexchange

func (*StravaDatasourceInstance) GetAccessToken

func (ds *StravaDatasourceInstance) GetAccessToken() (string, error)

func (*StravaDatasourceInstance) GetRefreshToken added in v1.5.1

func (ds *StravaDatasourceInstance) GetRefreshToken() (string, error)

func (*StravaDatasourceInstance) RefreshAccessToken

func (ds *StravaDatasourceInstance) RefreshAccessToken(refreshToken string) (*TokenExchangeResponse, error)

RefreshAccessToken refreshes expired Access token using refresh token https://developers.strava.com/docs/authentication/#refreshingexpiredaccesstokens

func (*StravaDatasourceInstance) ResetAccessToken added in v1.4.0

func (ds *StravaDatasourceInstance) ResetAccessToken() error

func (*StravaDatasourceInstance) ResetCache added in v1.5.0

func (ds *StravaDatasourceInstance) ResetCache()

func (*StravaDatasourceInstance) SaveRefreshToken added in v1.7.0

func (ds *StravaDatasourceInstance) SaveRefreshToken(token string) error

SaveRefreshToken saves refresh token in secureJsonData by calling update data source API endpoint

func (*StravaDatasourceInstance) StravaAPIQuery

func (*StravaDatasourceInstance) StravaAPIQueryWithCache added in v1.5.0

func (ds *StravaDatasourceInstance) StravaAPIQueryWithCache(requestHash string) func(context.Context, *StravaAPIRequest) (*StravaApiResourceResponse, error)

func (*StravaDatasourceInstance) StravaAuthQuery

type StravaDatasourcePlugin added in v1.7.0

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

func NewStravaDatasourcePlugin added in v1.7.0

func NewStravaDatasourcePlugin(dataDir string, saToken string) *StravaDatasourcePlugin

func (*StravaDatasourcePlugin) CheckHealth added in v1.7.0

CheckHealth checks if the plugin is running properly

func (*StravaDatasourcePlugin) QueryData added in v1.7.0

func (*StravaDatasourcePlugin) ResetAccessTokenHandler added in v1.7.0

func (ds *StravaDatasourcePlugin) ResetAccessTokenHandler(rw http.ResponseWriter, req *http.Request)

func (*StravaDatasourcePlugin) ResetCacheHandler added in v1.7.0

func (ds *StravaDatasourcePlugin) ResetCacheHandler(rw http.ResponseWriter, req *http.Request)

func (*StravaDatasourcePlugin) RootHandler added in v1.7.0

func (ds *StravaDatasourcePlugin) RootHandler(rw http.ResponseWriter, req *http.Request)

func (*StravaDatasourcePlugin) StravaAPIHandler added in v1.7.0

func (ds *StravaDatasourcePlugin) StravaAPIHandler(rw http.ResponseWriter, req *http.Request)

func (*StravaDatasourcePlugin) StravaAuthHandler added in v1.7.0

func (ds *StravaDatasourcePlugin) StravaAuthHandler(rw http.ResponseWriter, req *http.Request)

type StravaDatasourceSettingsDTO added in v1.5.0

type StravaDatasourceSettingsDTO struct {
	ClientID string `json:"clientID"`
	CacheTTL string `json:"cacheTTL"`
}

type StravaPrefetcher added in v1.5.0

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

func NewStravaPrefetcher added in v1.5.0

func NewStravaPrefetcher(depth int, ds *StravaDatasourceInstance) *StravaPrefetcher

func (*StravaPrefetcher) GetActivities added in v1.5.0

func (p *StravaPrefetcher) GetActivities() ([]string, error)

func (*StravaPrefetcher) PrefetchActivities added in v1.5.0

func (p *StravaPrefetcher) PrefetchActivities(activities []string)

func (*StravaPrefetcher) PrefetchActivitiesVariable added in v1.5.0

func (p *StravaPrefetcher) PrefetchActivitiesVariable(limit int)

func (*StravaPrefetcher) PrefetchActivity added in v1.5.0

func (p *StravaPrefetcher) PrefetchActivity(activityId string)

func (*StravaPrefetcher) PrefetchActivityStreams added in v1.5.0

func (p *StravaPrefetcher) PrefetchActivityStreams(activityId string)

func (*StravaPrefetcher) Run added in v1.5.0

func (p *StravaPrefetcher) Run()

Run starts background prefetcher task

type TokenExchangeResponse

type TokenExchangeResponse struct {
	AccessToken      string `json:"access_token"`
	AccessTokenExpAt int64  `json:"expires_at"`
	RefreshToken     string `json:"refresh_token"`
}

Jump to

Keyboard shortcuts

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