Documentation ¶
Index ¶
- Constants
- func CACerts(ctx context.Context) *x509.CertPool
- func LazyCreateNewTransport(c *Client) *http.Transport
- func NewTransport() *http.Transport
- func NewTransportWithHostVerificationDisabled(ctx context.Context) *http.Transport
- func ParseFileExpertsResponse(data []byte) ([]heartbeat.Result, error)
- func ParseGoalResponse(data []byte) (*goal.Goal, error)
- func ParseHeartbeatResponses(ctx context.Context, data []byte) ([]heartbeat.Result, error)
- func ParseStatusBarResponse(data []byte) (*summary.Summary, error)
- type BasicAuth
- type Client
- func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error)
- func (c *Client) FileExperts(ctx context.Context, heartbeats []heartbeat.Heartbeat) ([]heartbeat.Result, error)
- func (c *Client) Goal(ctx context.Context, id string) (*goal.Goal, error)
- func (c *Client) SendDiagnostics(ctx context.Context, plugin string, panicked bool, ...) error
- func (c *Client) SendHeartbeats(ctx context.Context, heartbeats []heartbeat.Heartbeat) ([]heartbeat.Result, error)
- func (c *Client) Today(ctx context.Context) (*summary.Summary, error)
- type Err
- type ErrAuth
- type ErrBackoff
- type ErrBadRequest
- type Option
- func WithAuth(auth BasicAuth) (Option, error)
- func WithDisableSSLVerify() Option
- func WithHostname(hostname string) Option
- func WithNTLM(creds string) (Option, error)
- func WithNTLMRequestRetry(ctx context.Context, creds string) (Option, error)
- func WithProxy(proxyURL string) (Option, error)
- func WithSSLCertFile(filepath string) (Option, error)
- func WithSSLCertPool(caCertPool *x509.CertPool) Option
- func WithTimeout(timeout time.Duration) Option
- func WithTimezone(timezone string) Option
- func WithUserAgent(ctx context.Context, plugin string) Option
Constants ¶
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
CACerts returns a root cert pool with the system's cacerts and LetsEncrypt's root certs.
func LazyCreateNewTransport ¶ added in v1.18.1
LazyCreateNewTransport uses the client's Transport if exists, or creates a new one.
func NewTransport ¶ added in v1.7.4
NewTransport initializes a new http.Transport.
func NewTransportWithHostVerificationDisabled ¶ added in v1.55.1
NewTransportWithHostVerificationDisabled initializes a new http.Transport with disabled host verification.
func ParseFileExpertsResponse ¶ added in v1.65.0
ParseFileExpertsResponse parses the wakatime api response into fileexperts.FileExperts.
func ParseGoalResponse ¶
ParseGoalResponse parses the wakatime api response into goal.Goal.
func ParseHeartbeatResponses ¶
ParseHeartbeatResponses parses the aggregated responses returned by the heartbeat bulk endpoint.
Types ¶
type BasicAuth ¶
BasicAuth contains authentication data.
func (BasicAuth) HeaderValue ¶
HeaderValue returns the value for Authorization header.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client communicates with the wakatime api.
func (*Client) Do ¶
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 ¶
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.
type Err ¶
type Err struct {
Err error
}
Err represents a general api error.
func (Err) SendDiagsOnErrors ¶ added in v1.73.3
SendDiagsOnErrors method to implement wakaerror.SendDiagsOnErrors interface.
func (Err) ShouldLogError ¶ added in v1.73.3
ShouldLogError method to implement wakaerror.ShouldLogError interface.
type ErrAuth ¶
type ErrAuth struct {
Err error
}
ErrAuth represents an authentication error.
func (ErrAuth) SendDiagsOnErrors ¶ added in v1.73.3
SendDiagsOnErrors method to implement wakaerror.SendDiagsOnErrors interface.
func (ErrAuth) ShouldLogError ¶ added in v1.73.3
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 WithDisableSSLVerify ¶
func WithDisableSSLVerify() Option
WithDisableSSLVerify disables verification of insecure certificates.
func WithHostname ¶
WithHostname sets the X-Machine-Name header to the passed in hostname.
func WithNTLMRequestRetry ¶
WithNTLMRequestRetry will, upon request failure, retry with ntlm authentication.
func WithSSLCertFile ¶
WithSSLCertFile overrides the default CA certs file to trust specified cert file.
func WithSSLCertPool ¶
WithSSLCertPool overrides the default CA cert pool to trust specified cert pool.
func WithTimeout ¶
WithTimeout configures a timeout for all requests.
func WithTimezone ¶ added in v1.31.0
WithTimezone sets the TimeZone header to the passed in timezone.