api

package
v1.18.7 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2021 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const BaseURL = "https://api.wakatime.com/api/v1"

BaseURL is the base url of the wakatime api.

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 ParseSummariesResponse

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

ParseSummariesResponse 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) Summaries

func (c *Client) Summaries(startDate, endDate time.Time) ([]summary.Summary, error)

Summaries fetches summaries for the defined date range.

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 ErrRequest

type ErrRequest string

ErrRequest represents a request failure, where no response was received from the api.

func (ErrRequest) Error

func (e ErrRequest) 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 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