wakatime

package module
v0.0.0-...-df09de9 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2015 License: MIT Imports: 12 Imported by: 0

README

Build Status GoDoc

go.wakatime

A Golang library for accessing the WakaTime API.

Usage

Please see the GoDoc and the examples in example_test.go.

Tests

go test

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Make sure golint and go vet run successfully.
  4. go fmt your code!
  5. Commit your changes (git commit -am "Add some feature")
  6. Push to the branch (git push origin my-new-feature)
  7. Create a new Pull Request

License

MIT

Documentation

Overview

Package wakatime provides a Golang interface for accessing the WakaTime API

Index

Examples

Constants

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

APIBaseURL is the Base API URL.

Variables

This section is empty.

Functions

This section is empty.

Types

type BestDay

type BestDay struct {
	CreatedAt    *time.Time `json:"created_at,omitempty"`
	Date         string     `json:"date,omitempty"`
	ID           string     `json:"id,omitempty"`
	ModifiedAt   *time.Time `json:"modified_at,omitempty"`
	TotalSeconds int        `json:"total_seconds,omitempty"`
}

BestDay is the user's best day for the given time period.

type CurrentUser

type CurrentUser struct {
	RunningTotal RunningTotal `json:"running_total,omitempty"`
	User         User         `json:"user,omitempty"`
}

CurrentUser is the user making the leaders request.

type Duration

type Duration struct {
	Dependencies string     `json:"dependencies,omitempty"`
	Duration     float64    `json:"duration,omitempty"`
	IsDebugging  bool       `json:"is_debugging,omitempty"`
	Project      string     `json:"project,omitempty"`
	Time         *timestamp `json:"time,omitempty"`
}

Duration is a user's logged time for the given day as an array of duration blocks.

type DurationParameters

type DurationParameters struct {
	Date     *time.Time
	Project  string
	Branches string

	User string
}

DurationParameters are the query parameters used for GetDurations.

type Editor

type Editor struct {
	CreatedAt    *time.Time `json:"created_at,omitempty"`
	ID           string     `json:"id,omitempty"`
	ModifiedAt   *time.Time `json:"modified_at,omitempty"`
	Name         string     `json:"name,omitempty"`
	Percent      float64    `json:"percent,omitempty"`
	TotalSeconds int        `json:"total_seconds,omitempty"`
}

Editor describes a text editor

type GrandTotal

type GrandTotal struct {
	Digital      string `json:"digital,omitempty"`
	Hours        int    `json:"hours,omitempty"`
	Minutes      int    `json:"minutes,omitempty"`
	Text         string `json:"text,omitempty"`
	TotalSeconds int    `json:"total_seconds,omitempty"`
}

GrandTotal is the total amount of time logged for this summary.

type Heartbeat

type Heartbeat struct {
	Branch      string     `json:"branch,omitempty"`
	Entity      string     `json:"entity,omitempty"`
	ID          string     `json:"id,omitempty"`
	IsDebugging bool       `json:"is_debugging,omitempty"`
	IsWrite     bool       `json:"is_write,omitempty"`
	Language    string     `json:"language,omitempty"`
	Project     string     `json:"project,omitempty"`
	Time        *timestamp `json:"time,omitempty"`
	Type        string     `json:"type,omitempty"`
}

Heartbeat is a user's heartbeats sent from plugins for the given day.

type HeartbeatParameters

type HeartbeatParameters struct {
	Date *time.Time
	Show []string // Possible options: time,entity,type,project,language,branch,is_write,is_debugging

	User string
}

HeartbeatParameters are the query parameters used for GetHeartbeats.

type Language

type Language struct {
	CreatedAt    *time.Time `json:"created_at,omitempty"`
	ID           string     `json:"id,omitempty"`
	ModifiedAt   *time.Time `json:"modified_at,omitempty"`
	Name         string     `json:"name,omitempty"`
	Percent      float64    `json:"percent,omitempty"`
	TotalSeconds int        `json:"total_seconds,omitempty"`
}

Language describes a programming language

type Leader

type Leader struct {
	Rank         int          `json:"rank,omitempty"`
	RunningTotal RunningTotal `json:"running_total,omitempty"`
	User         User         `json:"user,omitempty"`
}

Leader is a user on the leaderboard.

type Leaders

type Leaders struct {
	CurrentUser CurrentUser `json:"current_user"`
	Data        []Leader    `json:"data"`
	Language    string      `json:"language"`
	ModifiedAt  string      `json:"modified_at"`
	Range       string      `json:"range"`
}

Leaders is a list of users ranked by logged time in descending order. Same as the public leaderboards.

type OperatingSystem

type OperatingSystem struct {
	CreatedAt    *time.Time `json:"created_at,omitempty"`
	ID           string     `json:"id,omitempty"`
	ModifiedAt   *time.Time `json:"modified_at,omitempty"`
	Name         string     `json:"name,omitempty"`
	Percent      float64    `json:"percent,omitempty"`
	TotalSeconds int        `json:"total_seconds,omitempty"`
}

OperatingSystem describes an operating system

type Project

type Project struct {
	CreatedAt    *time.Time `json:"created_at,omitempty"`
	ID           string     `json:"id,omitempty"`
	ModifiedAt   *time.Time `json:"modified_at,omitempty"`
	Name         string     `json:"name,omitempty"`
	Percent      float64    `json:"percent,omitempty"`
	TotalSeconds int        `json:"total_seconds,omitempty"`
}

Project describes a project

type Range

type Range struct {
	Date      string     `json:"date,omitempty"`
	DateHuman string     `json:"date_human,omitempty"`
	End       *timestamp `json:"end,omitempty"`
	Start     *timestamp `json:"start,omitempty"`
	Text      string     `json:"text,omitempty"`
	Timezone  string     `json:"timezone,omitempty"`
}

Range is the time range this summary covers.

type Response

type Response struct {
	Result       interface{} `json:"data,omitempty"`
	Start        *timestamp  `json:"start,omitempty"`
	End          *timestamp  `json:"end,omitempty"`
	Timezone     string      `json:"timezone,omitempty"`
	Branches     []string    `json:"branches,omitempty"`
	ErrorMessage string      `json:"error,omitempty"`
	Range        string      `json:"range,omitempty"`
	Language     string      `json:"language,omitempty"`
	ModifiedAt   *time.Time  `json:"modified_at,omitempty"`
	CurrentUser  CurrentUser `json:"current_user,omitempty"`
}

Response is a response from WakaTime.

type RunningTotal

type RunningTotal struct {
	DailyAverage              int        `json:"daily_average,omitempty"`
	HumanReadableDailyAverage string     `json:"human_readable_daily_average,omitempty"`
	HumanReadableTotal        string     `json:"human_readable_total,omitempty"`
	Languages                 []Language `json:"languages,omitempty"`
	TotalSeconds              int        `json:"total_seconds,omitempty"`
}

RunningTotal is the total time logged for this user or leader.

type Stats

type Stats struct {
	BestDay                   BestDay           `json:"best_day,omitempty"`
	CreatedAt                 string            `json:"created_at,omitempty"`
	DailyAverage              int               `json:"daily_average,omitempty"`
	Editors                   []Editor          `json:"editors,omitempty"`
	End                       *timestamp        `json:"end,omitempty"`
	Holidays                  int               `json:"holidays,omitempty"`
	HumanReadableDailyAverage string            `json:"human_readable_daily_average,omitempty"`
	HumanReadableTotal        string            `json:"human_readable_total,omitempty"`
	ID                        string            `json:"id,omitempty"`
	IsUpToDate                bool              `json:"is_up_to_date,omitempty"`
	Languages                 []Language        `json:"languages,omitempty"`
	ModifiedAt                string            `json:"modified_at,omitempty"`
	OperatingSystems          []OperatingSystem `json:"operating_systems,omitempty"`
	Project                   Project           `json:"project,omitempty"`
	Projects                  []Project         `json:"projects,omitempty"`
	Range                     string            `json:"range,omitempty"`
	Start                     *timestamp        `json:"start,omitempty"`
	Status                    string            `json:"status,omitempty"`
	Timeout                   int               `json:"timeout,omitempty"`
	Timezone                  string            `json:"timezone,omitempty"`
	TotalSeconds              int               `json:"total_seconds,omitempty"`
	UserID                    string            `json:"user_id,omitempty"`
	Username                  string            `json:"username,omitempty"`
	WritesOnly                bool              `json:"writes_only,omitempty"`
}

Stats is a user's logged time for the given time range.

type StatsParameters

type StatsParameters struct {
	Timeout    int
	WritesOnly bool `parameter_name:"writes_only"`
	Project    string

	Range string
	User  string
}

StatsParameters are the query parameters used for GetStats.

type Summary

type Summary struct {
	Editors          []SummaryItem `json:"editors,omitempty"`
	Entities         []SummaryItem `json:"entities,omitempty"`
	GrandTotal       GrandTotal    `json:"grand_total,omitempty"`
	Languages        []SummaryItem `json:"languages,omitempty"`
	OperatingSystems []SummaryItem `json:"operating_systems,omitempty"`
	Projects         []SummaryItem `json:"projects,omitempty"`
	Range            Range         `json:"range,omitempty"`
}

Summary is a user's logged time for the given time range.

type SummaryItem

type SummaryItem struct {
	Digital      string  `json:"digital,omitempty"`
	Hours        int     `json:"hours,omitempty"`
	Minutes      int     `json:"minutes,omitempty"`
	Name         string  `json:"name,omitempty"`
	Percent      float64 `json:"percent,omitempty"`
	Seconds      int     `json:"seconds,omitempty"`
	Text         string  `json:"text,omitempty"`
	TotalSeconds int     `json:"total_seconds,omitempty"`
	Type         string  `json:"type,omitempty"`
}

SummaryItem is an object in a summary

type SummaryParameters

type SummaryParameters struct {
	Start    *time.Time
	End      *time.Time
	Project  string
	Branches string

	User string
}

SummaryParameters are the query parameters used for GetSummaries.

type User

type User struct {
	CreatedAt            *time.Time `json:"created_at,omitempty"`
	Email                string     `json:"email,omitempty"`
	EmailPublic          bool       `json:"email_public,omitempty"`
	FullName             string     `json:"full_name,omitempty"`
	HumanReadableWebsite string     `json:"human_readable_website,omitempty"`
	ID                   string     `json:"id,omitempty"`
	LastHeartbeat        *time.Time `json:"last_heartbeat,omitempty"`
	LastPlugin           string     `json:"last_plugin,omitempty"`
	LastPluginName       string     `json:"last_plugin_name,omitempty"`
	LastProject          string     `json:"last_project,omitempty"`
	Location             string     `json:"location,omitempty"`
	LoggedTimePublic     bool       `json:"logged_time_public,omitempty"`
	ModifiedAt           *time.Time `json:"modified_at,omitempty"`
	Photo                string     `json:"photo,omitempty"`
	PhotoPublic          bool       `json:"photo_public,omitempty"`
	Plan                 string     `json:"plan,omitempty"`
	Timezone             string     `json:"timezone,omitempty"`
	Username             string     `json:"username,omitempty"`
	Website              string     `json:"website,omitempty"`
}

User is a single user.

type UserAgent

type UserAgent struct {
	CreatedAt *time.Time `json:"created_at,omitempty"`
	Editor    string     `json:"editor,omitempty"`
	ID        string     `json:"id,omitempty"`
	LastSeen  *time.Time `json:"last_seen,omitempty"`
	OS        string     `json:"os,omitempty"`
	Value     string     `json:"value,omitempty"`
	Version   string     `json:"version,omitempty"`
}

A UserAgent is a plugins which has sent data for this user.

type WakaTime

type WakaTime struct {
	APIKey string
}

The WakaTime struct, containing the APIKey.

func NewWakaTime

func NewWakaTime(key string) *WakaTime

NewWakaTime returns a WakaTime struct with the key filled in

func (*WakaTime) GetDurations

func (waka *WakaTime) GetDurations(durationParameters *DurationParameters) ([]Duration, error)

GetDurations returns durations for the given user and parameters.

Example

This example gets the durations for the authenticated user.

client := wakatime.NewWakaTime(os.Getenv("WAKATIME_API_KEY"))
yesterday := time.Now().AddDate(0, 0, -1)
response, err := client.GetDurations(&wakatime.DurationParameters{Date: &yesterday})
if err != nil {
	panic(err)
}
fmt.Println(response)
Output:

func (*WakaTime) GetHeartbeats

func (waka *WakaTime) GetHeartbeats(heartbeatParameters *HeartbeatParameters) ([]Heartbeat, error)

GetHeartbeats returns heartbeats for the given user and parameters.

Example

This example gets the heartbeats for the authenticated user.

client := wakatime.NewWakaTime(os.Getenv("WAKATIME_API_KEY"))
yesterday := time.Now().AddDate(0, 0, -1)
response, err := client.GetHeartbeats(&wakatime.HeartbeatParameters{
	Date: &yesterday,
	Show: []string{"time", "entity", "type", "project", "language", "branch", "is_write", "is_debugging"},
})
if err != nil {
	panic(err)
}
fmt.Println(response)
Output:

func (*WakaTime) GetLeaders

func (waka *WakaTime) GetLeaders(language string) (Leaders, error)

GetLeaders returns the leaderboard. If a language is given, it returns the leaderboard for only that language.

Example

This example gets the leaders for the authenticated user.

client := wakatime.NewWakaTime(os.Getenv("WAKATIME_API_KEY"))
response, err := client.GetLeaders("")
if err != nil {
	panic(err)
}
fmt.Println(response)
Output:

func (*WakaTime) GetStats

func (waka *WakaTime) GetStats(statsParameters *StatsParameters) (Stats, error)

GetStats returns stats for the given user and parameters.

Example

This example gets the stats for the authenticated user.

client := wakatime.NewWakaTime(os.Getenv("WAKATIME_API_KEY"))
response, err := client.GetStats(&wakatime.StatsParameters{})
if err != nil {
	panic(err)
}
fmt.Println(response)
Output:

func (*WakaTime) GetSummaries

func (waka *WakaTime) GetSummaries(summaryParameters *SummaryParameters) ([]Summary, error)

GetSummaries returns summaries for the given user and parameters.

Example

This example gets the summaries for the authenticated user.

client := wakatime.NewWakaTime(os.Getenv("WAKATIME_API_KEY"))
now := time.Now()
yesterday := time.Now().AddDate(0, 0, -1)
response, err := client.GetSummaries(&wakatime.SummaryParameters{
	Start: &yesterday,
	End:   &now,
})
if err != nil {
	panic(err)
}
fmt.Println(response)
Output:

func (*WakaTime) GetUser

func (waka *WakaTime) GetUser(username string) (User, error)

GetUser returns the user for the given username.

Example

This example gets the user for the authenticated user.

client := wakatime.NewWakaTime(os.Getenv("WAKATIME_API_KEY"))
response, err := client.GetUser("")
if err != nil {
	panic(err)
}
fmt.Println(response)
Output:

func (*WakaTime) GetUserAgents

func (waka *WakaTime) GetUserAgents(username string) ([]UserAgent, error)

GetUserAgents returns the user agents for the given username.

Example

This example gets the userAgents for the authenticated user.

client := wakatime.NewWakaTime(os.Getenv("WAKATIME_API_KEY"))
response, err := client.GetUserAgents("")
if err != nil {
	panic(err)
}
fmt.Println(response)
Output:

Jump to

Keyboard shortcuts

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