api

package
v1.42.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: BSD-3-Clause Imports: 20 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"
	// 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() *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 ParseGoalResponse

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

ParseGoalResponse parses the wakatime api response into goal.Goal.

func ParseHeartbeatResponses

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

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

func ParseSummaryResponse added in v1.21.0

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

ParseSummaryResponse 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(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) Goal

func (c *Client) Goal(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(plugin string, diagnostics ...diagnostic.Diagnostic) error

SendDiagnostics sends diagnostics to the WakaTime api.

func (*Client) SendHeartbeats added in v1.18.1

func (c *Client) SendHeartbeats(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() (*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 string

Err represents a general api error.

func (Err) Error

func (e Err) Error() string

Error method to implement error interface.

type ErrAuth

type ErrAuth string

ErrAuth represents an authentication error.

func (ErrAuth) Error

func (e ErrAuth) Error() string

Error method to implement error interface.

type ErrBadRequest added in v1.28.6

type ErrBadRequest string

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.

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(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, error)

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(plugin string) Option

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

func WithUserAgentUnknownPlugin

func WithUserAgentUnknownPlugin() Option

WithUserAgentUnknownPlugin sets the User-Agent header on all requests, including default value for plugin.

Jump to

Keyboard shortcuts

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