statx

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2016 License: MIT Imports: 8 Imported by: 0

README

go-statx

Installation

The the CLI

go get -u github.com/mdp/go-statx/...

Just the library

go get -u github.com/mdp/go-statx

Usage

CLI

statx login +14158675309
Enter verification code from StatX and if successful you will receive API keys

Get a list of groups
statx list --apikey 12345abcdef --authtoken yourauthtoken

Get a list of Stats in a group
statx list --apikey 12345abcdef --authtoken yourauthtoken --group groupid

Update the value of a Stat
statx update --apikey 12345abcdef --authtoken yourauthtoken --group groupid --stat statid --value 47

Library
client := statx.NewAuthenticatedClient(nil, "apikey", "authtoken")
statList, _, err := client.Stats.List("GroupID")

# Update a stat
stat := &statx.Stat{Value: "47"}
updatedStat, _, err := client.Stats.Update("GroupID", statList[0].ID, stat)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.

Types

type AuthResponse

type AuthResponse struct {
	ClientID    *string `json:"clientId"`
	ClientName  *string `json:"clientName"`
	PhoneNumber *string `json:"phoneNumber"`
}

AuthResponse the reponse back from /auth/login

type AuthService

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

AuthService handles calls to /groups

func (*AuthService) Login

func (s *AuthService) Login(phoneNumber, clientName string) (*AuthResponse, *Response, error)

Login to a users account

func (*AuthService) Verify

func (s *AuthService) Verify(verificationCode string, auth *AuthResponse) (*Credentials, *Response, error)

Verify to a users account

type Client

type Client struct {

	// Base URL for API requests.  Defaults to the public GitHub API, but can be
	// set to a domain endpoint to use with GitHub Enterprise.  BaseURL should
	// always be specified with a trailing slash.
	BaseURL *url.URL

	// User agent used when communicating with the GitHub API.
	UserAgent string

	Credentials *Credentials

	Groups *GroupsService
	Auth   *AuthService
	Stats  *StatsService
	// contains filtered or unexported fields
}

A Client manages communication with the GitHub API.

func NewAuthenticatedClient

func NewAuthenticatedClient(httpClient *http.Client, apiKey, authToken string) *Client

NewAuthenticatedClient returns a new Authenticted Statx API client

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new Statx API client. If a nil httpClient is provided, http.DefaultClient will be used.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*Response, error)

Do - Send the request

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

type Credentials

type Credentials struct {
	APIKey    *string `json:"apiKey"`
	AuthToken *string `json:"authToken"`
}

Credentials is the response from /auth/verifyCode

type Group

type Group struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

Group holds the group info

type GroupList

type GroupList struct {
	Data []Group `json:"data"`
}

GroupList holds the list of groups from GET /groups

type GroupsService

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

GroupsService handles calls to /groups

func (*GroupsService) Get

func (s *GroupsService) Get(groupID string) (*Group, *Response, error)

Get - gets information about a single group

func (*GroupsService) List

func (s *GroupsService) List() (*GroupList, *Response, error)

List gets the lists of StatX Groups

type Response

type Response struct {
	*http.Response
}

Response is a GitHub API response. This wraps the standard http.Response returned from GitHub and provides convenient access to things like pagination links.

type Stat

type Stat struct {
	ID                       string     `json:"id,omitempty"`
	Title                    string     `json:"title,omitempty"`
	VisualType               string     `json:"visualType,omitempty"`
	Notes                    string     `json:"notes,omitempty"`
	Value                    string     `json:"value,omitempty"`
	DueDateTime              *time.Time `json:"dueDateTime,omitempty"`
	LastUpdatedDateTime      *time.Time `json:"lastUpdatedDateTime,omitempty"`
	NotesLastUpdatedDateTime *time.Time `json:"notesLastUpdatedDateTime,omitempty"`
}

Stat holds generic stat data

func (*Stat) UpdateTimestamps

func (stat *Stat) UpdateTimestamps()

UpdateTimestamps - Populate the timestamps for a stat before saving

type StatList

type StatList struct {
	Data []Stat `json:"data"`
}

StatList holds stats

type StatsService

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

StatsService handles calls to /stats

func (*StatsService) Get

func (s *StatsService) Get(groupID, statID string) (*Stat, *Response, error)

Get - gets information about a single group

func (*StatsService) List

func (s *StatsService) List(groupID string) (*StatList, *Response, error)

List gets the lists of StatX Groups

func (*StatsService) Update

func (s *StatsService) Update(groupID, statID string, stat *Stat) (*Stat, *Response, error)

Update - gets information about a single group

Directories

Path Synopsis
cmd
statx command

Jump to

Keyboard shortcuts

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