api

package
v1.106.1 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: BSD-3-Clause Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BaseURL is the base url of the wakatime api.
	BaseURL = "https://api.wakatime.com/api/v1"
	// BaseIPAddrv4 is the base ip address v4 of the wakatime api.
	BaseIPAddrv4 = "143.244.210.202"
	// BaseIPAddrv6 is the base ip address v6 of the wakatime api.
	BaseIPAddrv6 = "2604:a880:4:1d0::2a7:b000"
	// DefaultTimeoutSecs is the default timeout used for requests to the wakatime api.
	DefaultTimeoutSecs = 120
)

Variables

This section is empty.

Functions

func CACerts added in v1.7.4

func CACerts(ctx context.Context) *x509.CertPool

CACerts returns a root cert pool with the system's cacerts and LetsEncrypt's root certs.

func LazyCreateNewTransport added in v1.18.1

func LazyCreateNewTransport(c *Client) *http.Transport

LazyCreateNewTransport uses the client's Transport if exists, or creates a new one.

func NewTransport added in v1.7.4

func NewTransport() *http.Transport

NewTransport initializes a new http.Transport.

func NewTransportWithHostVerificationDisabled added in v1.55.1

func NewTransportWithHostVerificationDisabled(ctx context.Context) *http.Transport

NewTransportWithHostVerificationDisabled initializes a new http.Transport with disabled host verification.

func ParseFileExpertsResponse added in v1.65.0

func ParseFileExpertsResponse(data []byte) ([]heartbeat.Result, error)

ParseFileExpertsResponse parses the wakatime api response into fileexperts.FileExperts.

func ParseGoalResponse

func ParseGoalResponse(data []byte) (*goal.Goal, error)

ParseGoalResponse parses the wakatime api response into goal.Goal.

func ParseHeartbeatResponses

func ParseHeartbeatResponses(ctx context.Context, data []byte) ([]heartbeat.Result, error)

ParseHeartbeatResponses parses the aggregated responses returned by the heartbeat bulk endpoint.

func ParseStatusBarResponse added in v1.64.1

func ParseStatusBarResponse(data []byte) (*summary.Summary, error)

ParseStatusBarResponse parses the wakatime api response into summary.Summary.

Types

type BasicAuth

type BasicAuth struct {
	User   string
	Secret string
}

BasicAuth contains authentication data.

func (BasicAuth) HeaderValue

func (a BasicAuth) HeaderValue() (string, error)

HeaderValue returns the value for Authorization header.

type Client

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

Client communicates with the wakatime api.

func NewClient

func NewClient(baseURL string, opts ...Option) *Client

NewClient creates a new Client. Any number of Options can be provided.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error)

Do executes c.doFunc(), which in turn allows wrapping c.client.Do() and manipulating the request behavior of the api client.

func (*Client) FileExperts added in v1.65.0

func (c *Client) FileExperts(ctx context.Context, heartbeats []heartbeat.Heartbeat) ([]heartbeat.Result, error)

FileExperts fetches file experts for Today.

ErrRequest is returned upon request failure with no received response from api. ErrAuth is returned upon receiving a 401 Unauthorized api response. Err is returned on any other api response related error.

func (*Client) Goal

func (c *Client) Goal(ctx context.Context, id string) (*goal.Goal, error)

Goal fetches goal for the given goal id.

ErrRequest is returned upon request failure with no received response from api. ErrAuth is returned upon receiving a 401 Unauthorized api response. Err is returned on any other api response related error.

func (*Client) SendDiagnostics added in v1.18.1

func (c *Client) SendDiagnostics(
	ctx context.Context,
	plugin string,
	panicked bool,
	diagnostics ...diagnostic.Diagnostic,
) error

SendDiagnostics sends diagnostics to the WakaTime api.

func (*Client) SendHeartbeats added in v1.18.1

func (c *Client) SendHeartbeats(ctx context.Context, heartbeats []heartbeat.Heartbeat) ([]heartbeat.Result, error)

SendHeartbeats sends a bulk of heartbeats to the wakatime api and returns the result. The API does not guarantuee the setting of the Heartbeat property of the result. On certain errors, like 429/too many heartbeats, this is omitted and not set.

ErrRequest is returned upon request failure with no received response from api. ErrAuth is returned upon receiving a 401 Unauthorized api response. Err is returned on any other api response related error.

func (*Client) Today added in v1.21.0

func (c *Client) Today(ctx context.Context) (*summary.Summary, error)

Today fetches code stats for Today.

ErrRequest is returned upon request failure with no received response from api. ErrAuth is returned upon receiving a 401 Unauthorized api response. Err is returned on any other api response related error.

type Err

type Err struct {
	Err error
}

Err represents a general api error.

func (Err) Error

func (e Err) Error() string

Error method to implement error interface.

func (Err) ExitCode added in v1.53.2

func (Err) ExitCode() int

ExitCode method to implement wakaerror.Error interface.

func (Err) Message added in v1.53.2

func (e Err) Message() string

Message method to implement wakaerror.Error interface.

func (Err) SendDiagsOnErrors added in v1.73.3

func (Err) SendDiagsOnErrors() bool

SendDiagsOnErrors method to implement wakaerror.SendDiagsOnErrors interface.

func (Err) ShouldLogError added in v1.73.3

func (Err) ShouldLogError() bool

ShouldLogError method to implement wakaerror.ShouldLogError interface.

type ErrAuth

type ErrAuth struct {
	Err error
}

ErrAuth represents an authentication error.

func (ErrAuth) Error

func (e ErrAuth) Error() string

Error method to implement error interface.

func (ErrAuth) ExitCode added in v1.53.2

func (ErrAuth) ExitCode() int

ExitCode method to implement wakaerror.Error interface.

func (ErrAuth) Message added in v1.53.2

func (e ErrAuth) Message() string

Message method to implement wakaerror.Error interface.

func (ErrAuth) SendDiagsOnErrors added in v1.73.3

func (ErrAuth) SendDiagsOnErrors() bool

SendDiagsOnErrors method to implement wakaerror.SendDiagsOnErrors interface.

func (ErrAuth) ShouldLogError added in v1.73.3

func (ErrAuth) ShouldLogError() bool

ShouldLogError method to implement wakaerror.ShouldLogError interface.

type ErrBackoff added in v1.49.0

type ErrBackoff struct {
	Err error
}

ErrBackoff means we send later because currently rate limited.

func (ErrBackoff) Error added in v1.49.0

func (e ErrBackoff) Error() string

Error method to implement error interface.

func (ErrBackoff) ExitCode added in v1.53.2

func (ErrBackoff) ExitCode() int

ExitCode method to implement wakaerror.Error interface.

func (ErrBackoff) LogLevel added in v1.106.0

func (ErrBackoff) LogLevel() int8

LogLevel method to implement wakaerror.LogLevel interface.

func (ErrBackoff) Message added in v1.53.2

func (e ErrBackoff) Message() string

Message method to implement wakaerror.Error interface.

func (ErrBackoff) SendDiagsOnErrors added in v1.73.3

func (ErrBackoff) SendDiagsOnErrors() bool

SendDiagsOnErrors method to implement wakaerror.SendDiagsOnErrors interface.

func (ErrBackoff) ShouldLogError added in v1.73.3

func (ErrBackoff) ShouldLogError() bool

ShouldLogError method to implement wakaerror.ShouldLogError interface.

type ErrBadRequest added in v1.28.6

type ErrBadRequest struct {
	Err error
}

ErrBadRequest represents a 400 response from the API.

func (ErrBadRequest) Error added in v1.28.6

func (e ErrBadRequest) Error() string

Error method to implement error interface.

func (ErrBadRequest) ExitCode added in v1.53.2

func (ErrBadRequest) ExitCode() int

ExitCode method to implement wakaerror.Error interface.

func (ErrBadRequest) Message added in v1.53.2

func (e ErrBadRequest) Message() string

Message method to implement wakaerror.Error interface.

func (ErrBadRequest) SendDiagsOnErrors added in v1.73.3

func (ErrBadRequest) SendDiagsOnErrors() bool

SendDiagsOnErrors method to implement wakaerror.SendDiagsOnErrors interface.

func (ErrBadRequest) ShouldLogError added in v1.73.3

func (ErrBadRequest) ShouldLogError() bool

ShouldLogError method to implement wakaerror.ShouldLogError interface.

type Option

type Option func(*Client)

Option is a functional option for Client.

func WithAuth

func WithAuth(auth BasicAuth) (Option, error)

WithAuth adds authentication via Authorization header.

func WithDisableSSLVerify

func WithDisableSSLVerify() Option

WithDisableSSLVerify disables verification of insecure certificates.

func WithHostname

func WithHostname(hostname string) Option

WithHostname sets the X-Machine-Name header to the passed in hostname.

func WithNTLM

func WithNTLM(creds string) (Option, error)

WithNTLM allows authentication via ntlm protocol.

func WithNTLMRequestRetry

func WithNTLMRequestRetry(ctx context.Context, creds string) (Option, error)

WithNTLMRequestRetry will, upon request failure, retry with ntlm authentication.

func WithProxy

func WithProxy(proxyURL string) (Option, error)

WithProxy configures the client to proxy outgoing requests to the specified url.

func WithSSLCertFile

func WithSSLCertFile(filepath string) (Option, error)

WithSSLCertFile overrides the default CA certs file to trust specified cert file.

func WithSSLCertPool

func WithSSLCertPool(caCertPool *x509.CertPool) Option

WithSSLCertPool overrides the default CA cert pool to trust specified cert pool.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout configures a timeout for all requests.

func WithTimezone added in v1.31.0

func WithTimezone(timezone string) Option

WithTimezone sets the TimeZone header to the passed in timezone.

func WithUserAgent

func WithUserAgent(ctx context.Context, plugin string) Option

WithUserAgent sets the User-Agent header on all requests, including the passed in value for plugin.

Jump to

Keyboard shortcuts

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