api

package
v0.0.0-...-f149eba Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var Companies = &CompaniesList{}

Companies stores the companies we have in cache or fetched from the server.

View Source
var Contracts = &ContractsList{}

Contracts stores the contracts we have in cache or fetched from the server.

View Source
var Models = &models{}

Models represents all the lists we can view, edit, etc

View Source
var Performances = &PerformancesList{}

Performances stores the performances as we get them from the ninetofiver server

View Source
var PerformancesColumns = []string{"day", "contract", "description", "duration", "multiplier", "type", "id"}

PerformancesColumns are all the columns we can show for performances.

View Source
var PerformancesColumnsDefault = []bool{true, true, true, true, false, false, false}

PerformancesColumnsDefault is a list of booleans. true means column will be shown by default. Each boolean represents the column at the same place in the PerformancesColumns list.

View Source
var PerformancesRates = &PerformanceRatesList{}

PerformancesRates stores the performances rates we get from the cache or the remote server

View Source
var Users = &UsersList{}

Users is used to cache the list of Users

Functions

This section is empty.

Types

type Client

type Client struct {
	Endpoint string
	Username string
	Password string
	CacheDir string
	NoCache  bool
}

Client is the nine-to-fiver client, responsible for fetching and update items

func (*Client) DeleteByID

func (c *Client) DeleteByID(m Model) error

DeleteByID returns the model from the server

func (*Client) DeleteRequest

func (c *Client) DeleteRequest(url string) (*http.Response, error)

DeleteRequest will make a DELETE request for a given model and expect error code to be 204

func (*Client) FetchCache

func (c *Client) FetchCache() error

FetchCache will fill the cache with content from localdisk or ninetofiver instance

func (*Client) FetchIfNeeded

func (c *Client) FetchIfNeeded(m ModelList, args []string) error

FetchIfNeeded fetches a list if it is empty

func (*Client) FetchList

func (c *Client) FetchList(m ModelList, args []string) error

FetchList fetches a list of objects from the backend

func (*Client) GetByID

func (c *Client) GetByID(m Model) error

GetByID returns the model from the server by its id

func (*Client) GetRequest

func (c *Client) GetRequest(url string) (*http.Response, error)

GetRequest will make a GET request for a given model and expect error code to be 200

func (*Client) PatchRequest

func (c *Client) PatchRequest(url string, i interface{}) (*http.Response, error)

PatchRequest will make a PATCH request for a given model and expect error code to be 200

func (*Client) PostRequest

func (c *Client) PostRequest(url string, i interface{}) (*http.Response, error)

PostRequest will make a POST request for a given model and expect error code to be 201

func (*Client) Request

func (c *Client) Request(verb, url string, code int, payload io.Reader) (*http.Response, error)

Request makes a requests, sets the correct headers, and checks the return code of the response.

type CompaniesList

type CompaniesList struct {
	Companies []Company `json:"results"`
}

CompaniesList is a list of companies in the ninetofiver api

func (*CompaniesList) GetColumns

func (cs *CompaniesList) GetColumns() []string

GetColumns returns an empty list because companies are not displayed as a table

func (*CompaniesList) GetDefaultColumns

func (cs *CompaniesList) GetDefaultColumns() []string

GetDefaultColumns returns an empty list because companies are not displayed as a table

func (*CompaniesList) HasPorcelain

func (cs *CompaniesList) HasPorcelain() bool

HasPorcelain returns false because companies do not support PorcelainPrettyPrint

func (*CompaniesList) PorcelainPrettyPrint

func (cs *CompaniesList) PorcelainPrettyPrint()

PorcelainPrettyPrint does nothing for this model

func (*CompaniesList) PrettyPrint

func (cs *CompaniesList) PrettyPrint(columns []string)

PrettyPrint prints companies in a nice way to the console

Example
t := &CompaniesList{
	Companies: []Company{
		Company{
			Name:    "Inuits",
			Country: "BE",
		},
		Company{
			Name:    "Eskimo",
			Country: "NL",
		},
	},
}
t.PrettyPrint(*new([]string))
Output:

Inuits [BE]
Eskimo [NL]

func (*CompaniesList) Slug

func (cs *CompaniesList) Slug() string

Slug is used to represent the model in cli

type Company

type Company struct {
	ID      int    `json:"id"`
	Name    string `json:"name"`
	Country string `json:"country"`
}

Company is a company as seen in the ninetofiver api

func (*Company) Augment

func (c *Company) Augment(cl *Client)

Augment populates extra fields for a company

func (*Company) DeleteArg

func (c *Company) DeleteArg() string

DeleteArg returns the arg needed to delete the company

func (*Company) Get

func (c *Company) Get(client Client) error

Get returns the Company from the server

func (*Company) GetByID

func (c *Company) GetByID(client Client) error

GetByID returns the Company from the server

func (*Company) GetID

func (c *Company) GetID() int

GetID returns the ID of a company

func (*Company) PrettyPrint

func (c *Company) PrettyPrint()

PrettyPrint prints company in a nice way to the console

Example
t := &Company{
	Name:    "Inuits",
	Country: "BE",
}
t.PrettyPrint()
Output:

Inuits [BE]

func (*Company) SetID

func (c *Company) SetID(i int)

SetID sets the ID of a company

func (*Company) Slug

func (c *Company) Slug() string

Slug returns the short name for the company model

type Contract

type Contract struct {
	ID         int    `json:"id"`
	Label      string `json:"label"`
	CustomerID int    `json:"customer"`
	Customer   *Company
}

Contract is a contract as seen in the ninetofiver api.

func (*Contract) Augment

func (c *Contract) Augment(cl *Client)

Augment populates extra fields of a contract

func (*Contract) DeleteArg

func (c *Contract) DeleteArg() string

DeleteArg returns the arg that is needed in url to delete the contract

func (*Contract) GetID

func (c *Contract) GetID() int

GetID returns the ID of a contract

func (*Contract) PrettyLabel

func (c *Contract) PrettyLabel() string

PrettyLabel returns the label of a contract that can be used in CLI etc.. to identify a contract. It contains the customer.

func (*Contract) PrettyPrint

func (c *Contract) PrettyPrint()

PrettyPrint prints contract in a nice way to the console

func (*Contract) SetID

func (c *Contract) SetID(i int)

SetID sets the ID of a contract

func (*Contract) Slug

func (c *Contract) Slug() string

Slug returns the slug for the contract model.

type ContractsList

type ContractsList struct {
	Contracts []Contract `json:"results"`
}

ContractsList is a list of contrats as seen in the ninetofiver api.

func (*ContractsList) GetByID

func (cs *ContractsList) GetByID(id int) *Contract

GetByID returns the contract with the given id

func (*ContractsList) GetByLabel

func (cs *ContractsList) GetByLabel(label string) *Contract

GetByLabel returns the contract with the given label

func (*ContractsList) GetColumns

func (cs *ContractsList) GetColumns() []string

GetColumns returns an empty list because contracts are not displayed as a table

func (*ContractsList) GetDefaultColumns

func (cs *ContractsList) GetDefaultColumns() []string

GetDefaultColumns returns an empty list because contracts are not displayed as a table

func (*ContractsList) HasPorcelain

func (cs *ContractsList) HasPorcelain() bool

HasPorcelain returns false because contracts do not support PorcelainPrettyPrint

func (*ContractsList) PorcelainPrettyPrint

func (cs *ContractsList) PorcelainPrettyPrint()

PorcelainPrettyPrint does nothing for this model

func (*ContractsList) PrettyPrint

func (cs *ContractsList) PrettyPrint(columns []string)

PrettyPrint prints contracts in a nice way to the console

func (*ContractsList) Slug

func (cs *ContractsList) Slug() string

Slug is used to represent the model in cli

type Model

type Model interface {
	SetID(int)
	GetID() int
	DeleteArg() string
	Augment(*Client)
	PrettyPrint()

	Slug() string
	// contains filtered or unexported methods
}

Model is an interface shared by all the models

type ModelList

type ModelList interface {
	Slug() string

	GetColumns() []string
	GetDefaultColumns() []string

	PrettyPrint([]string)
	HasPorcelain() bool
	PorcelainPrettyPrint()
	// contains filtered or unexported methods
}

ModelList is an interface shared by all the models lists

type Performance

type Performance struct {
	ID          int             `json:"id"`
	Type        PerformanceType `json:"type"`
	Timesheet   *Timesheet
	TimesheetID int `json:"timesheet"`
	ContractID  int `json:"contract"`
	Contract    *Contract
	Day         int    `json:"day"`
	Description string `json:"description"`
	Duration    string `json:"duration"`
	RateID      int    `json:"performance_type"`
	Rate        *PerformanceRate
}

Performance represents one performance we get in the ninetofoiver app

func (*Performance) Augment

func (p *Performance) Augment(c *Client)

Augment populates extra fields of a performance

func (*Performance) DeleteArg

func (p *Performance) DeleteArg() string

DeleteArg returns the args needed to delete a performance

func (*Performance) FetchContract

func (p *Performance) FetchContract(c Client) error

FetchContract fills the contract field of this performance

func (*Performance) FetchRate

func (p *Performance) FetchRate(c Client) error

FetchRate fills the rate field of this performance

func (*Performance) FetchTimesheet

func (p *Performance) FetchTimesheet(c Client) error

FetchTimesheet fills the timesheet field of this performance

func (*Performance) GetByID

func (p *Performance) GetByID(c Client) error

GetByID gets the performance from the server given its it

func (*Performance) GetColumn

func (p *Performance) GetColumn(name string) string

GetColumn returns the content of a column for a performance

func (*Performance) GetID

func (p *Performance) GetID() int

GetID returns the id of the performance

func (*Performance) New

func (p *Performance) New(c Client) error

New creates a new performance on the server

func (*Performance) Porcelain

func (p *Performance) Porcelain()

Porcelain prints out the porcelain version of the performance

func (*Performance) PrettyPrint

func (p *Performance) PrettyPrint()

PrettyPrint prints the performance

func (*Performance) SetID

func (p *Performance) SetID(i int)

SetID sets the id of the performance

func (*Performance) Slug

func (p *Performance) Slug() string

Slug is used to represent the model in cli

func (*Performance) Sporcelain

func (p *Performance) Sporcelain() string

Sporcelain creates a parsable string for the performance. Useful for scripting.

type PerformanceRate

type PerformanceRate struct {
	ID         int    `json:"id"`
	Label      string `json:"label"`
	Multiplier string `json:"multiplier"`
}

PerformanceRate represents a Performance Rate in the ninetofiver api.

func (*PerformanceRate) Augment

func (p *PerformanceRate) Augment(c *Client)

Augment populates extra fields of a perf rate

func (*PerformanceRate) DeleteArg

func (p *PerformanceRate) DeleteArg() string

DeleteArg returns what is required on the api side to delete a performance rate

func (*PerformanceRate) GetID

func (p *PerformanceRate) GetID() int

GetID returns the ID of the perf rate

func (*PerformanceRate) PrettyList

func (p *PerformanceRate) PrettyList() string

PrettyList returns a short list of performances rates, used in error messages (when a user specifies an unknown multiplier)

func (*PerformanceRate) PrettyPrint

func (p *PerformanceRate) PrettyPrint()

PrettyPrint prints the performance rate in a nice way.

func (*PerformanceRate) SetID

func (p *PerformanceRate) SetID(i int)

SetID sets the ID of the perf rate

func (*PerformanceRate) ShortPrint

func (p *PerformanceRate) ShortPrint()

ShortPrint the multiplier of the performance rate, and only that.

func (*PerformanceRate) Slug

func (p *PerformanceRate) Slug() string

Slug is used to represent the model in cli

type PerformanceRatesList

type PerformanceRatesList struct {
	PerformanceRates []PerformanceRate `json:"results"`
}

PerformanceRatesList represents a list of Performances Rates as we get them from the server.

func (*PerformanceRatesList) GetByID

func (pr *PerformanceRatesList) GetByID(id int) *PerformanceRate

GetByID fills a performance given its ID.

func (*PerformanceRatesList) GetByMultiplier

func (pr *PerformanceRatesList) GetByMultiplier(multiplier string) (*PerformanceRate, error)

GetByMultiplier fills a performance given its multiplier. It will error if multiple performances rates are found with the same multiplier.

func (*PerformanceRatesList) GetColumns

func (pr *PerformanceRatesList) GetColumns() []string

GetColumns returns an empty list because performances rates are not displayed as a table

func (*PerformanceRatesList) GetDefaultColumns

func (pr *PerformanceRatesList) GetDefaultColumns() []string

GetDefaultColumns returns an empty list because Performance rates are not displayed as a table

func (*PerformanceRatesList) HasPorcelain

func (pr *PerformanceRatesList) HasPorcelain() bool

HasPorcelain returns false because performances rates do not support PorcelainPrettyPrint

func (*PerformanceRatesList) PorcelainPrettyPrint

func (pr *PerformanceRatesList) PorcelainPrettyPrint()

PorcelainPrettyPrint does nothing for this model

func (*PerformanceRatesList) PrettyList

func (pr *PerformanceRatesList) PrettyList() string

PrettyList returns a string with all the performances rates displayed as a short list.

func (*PerformanceRatesList) PrettyPrint

func (pr *PerformanceRatesList) PrettyPrint(columns []string)

PrettyPrint prints the performances rates in a nice way.

func (*PerformanceRatesList) ShortPrint

func (pr *PerformanceRatesList) ShortPrint()

ShortPrint prints all the multipliers of the performance rates in the list, and only that.

func (*PerformanceRatesList) Slug

func (pr *PerformanceRatesList) Slug() string

Slug is used to represent the model in cli

type PerformanceType

type PerformanceType int

PerformanceType represents a Performance Type (standby/activity)

const (
	// ActivityPerformance represents the Activity Performance type
	ActivityPerformance PerformanceType = iota
	// StandbyPerformance represents the Standby Performance Type
	StandbyPerformance
)

func (PerformanceType) String

func (p PerformanceType) String() string

String returns the performance type as a string

func (*PerformanceType) UnmarshalJSON

func (p *PerformanceType) UnmarshalJSON(b []byte) error

UnmarshalJSON returns the performance type as an integer, like we expect it for PerformanceType

type PerformancesList

type PerformancesList struct {
	Performances []Performance `json:"results"`
}

PerformancesList represents a list of performances we get from the ninetofiver server

func (*PerformancesList) GetColumn

func (ps *PerformancesList) GetColumn(name string) string

GetColumn returns the header of a column for performances

func (*PerformancesList) GetColumns

func (ps *PerformancesList) GetColumns() []string

GetColumns returns all the available columns in the performances tabular

func (*PerformancesList) GetDefaultColumns

func (ps *PerformancesList) GetDefaultColumns() []string

GetDefaultColumns returns the list of default columns for performances

func (*PerformancesList) HasPorcelain

func (ps *PerformancesList) HasPorcelain() bool

HasPorcelain returns true because contracts do support PorcelainPrettyPrint

func (*PerformancesList) PorcelainPrettyPrint

func (ps *PerformancesList) PorcelainPrettyPrint()

PorcelainPrettyPrint prints out the porcelain version of the performances

func (*PerformancesList) PrettyPrint

func (ps *PerformancesList) PrettyPrint(columns []string)

PrettyPrint prints a list of performances as a table which columns specified as parameter

func (*PerformancesList) Slug

func (ps *PerformancesList) Slug() string

Slug is used to represent the model in cli

type Timesheet

type Timesheet struct {
	ID           int    `json:"id"`
	Year         int    `json:"year"`
	Month        int    `json:"month"`
	DisplayLabel string `json:"display_label"`
	Status       string `json:"status"`
}

Timesheet represents a ninetofiver timesheet

func (*Timesheet) Augment

func (t *Timesheet) Augment(c *Client)

Augment populates extra fields for the timesheet

func (*Timesheet) DeleteArg

func (t *Timesheet) DeleteArg() string

DeleteArg returns what is required in the url to delete the timesheet

func (*Timesheet) Get

func (t *Timesheet) Get(c Client) error

Get returns the timesheets from the server

func (*Timesheet) GetByID

func (t *Timesheet) GetByID(c Client) error

GetByID returns the timesheet from the server by its id

func (*Timesheet) GetID

func (t *Timesheet) GetID() int

GetID returns the ID of the timesheet

func (*Timesheet) Name

func (t *Timesheet) Name() string

Name returns the timesheet name (English month name + year)

func (*Timesheet) New

func (t *Timesheet) New(c Client) error

New creates a new timesheet on the server

func (*Timesheet) PrettyPrint

func (t *Timesheet) PrettyPrint()

PrettyPrint prints timesheet in a nice way to the console

Example
t := &Timesheet{
	Year:   2016,
	Month:  7,
	Status: "PENDING",
}
t.PrettyPrint()
Output:

July 2016 [PENDING]

func (*Timesheet) Release

func (t *Timesheet) Release(c Client) error

Release sends a request to ninetofiver to mark the timesheet as PENDING.

func (*Timesheet) SetID

func (t *Timesheet) SetID(i int)

SetID sets the ID of the timesheet

func (*Timesheet) Slug

func (t *Timesheet) Slug() string

Slug is used to represent the model in cli

type TimesheetsList

type TimesheetsList struct {
	Timesheets []Timesheet `json:"results"`
}

TimesheetsList represents a list of ninetofiver timesheet

func (*TimesheetsList) GetByID

func (ts *TimesheetsList) GetByID(id int) *Timesheet

GetByID returns the timesheet with the given id

func (*TimesheetsList) GetColumns

func (ts *TimesheetsList) GetColumns() []string

GetColumns returns an empty list because timesheets are not displayed as a table

func (*TimesheetsList) GetDefaultColumns

func (ts *TimesheetsList) GetDefaultColumns() []string

GetDefaultColumns returns an empty list because timesheets are not displayed as a table

func (*TimesheetsList) HasPorcelain

func (ts *TimesheetsList) HasPorcelain() bool

HasPorcelain returns false because timesheets do not support PorcelainPrettyPrint

func (*TimesheetsList) PorcelainPrettyPrint

func (ts *TimesheetsList) PorcelainPrettyPrint()

PorcelainPrettyPrint does nothing for this model

func (*TimesheetsList) PrettyPrint

func (ts *TimesheetsList) PrettyPrint(columns []string)

PrettyPrint prints timesheets in a nice way to the console

Example
t := &TimesheetsList{
	Timesheets: []Timesheet{
		Timesheet{
			Year:   2007,
			Month:  8,
			Status: "APPROVED",
		},
		Timesheet{
			Year:   2016,
			Month:  7,
			Status: "PENDING",
		},
	},
}
t.PrettyPrint(*new([]string))
Output:

August 2007 [APPROVED]
July 2016 [PENDING]

func (*TimesheetsList) Slug

func (ts *TimesheetsList) Slug() string

Slug is used to represent the model in cli

type User

type User struct {
	ID           int
	Username     string
	Email        string
	Groups       []string
	FirstName    string `json:"first_name"`
	LastName     string `json:"last_name"`
	DisplayLabel string
	IsActive     bool
	Country      string
	Gender       string
	BirthDate    string
	JoinDate     string
	RedmineID    int `json:"redmine_id"`
}

User represents a ninetofiver user

func (*User) Augment

func (u *User) Augment(c *Client)

Augment populates extra fields of a user

func (*User) DeleteArg

func (u *User) DeleteArg() string

DeleteArg returns what is needed in the API url to delete a user

func (*User) GetID

func (u *User) GetID() int

GetID returns the ID of a user

func (*User) PrettyPrint

func (u *User) PrettyPrint()

PrettyPrint prints user in a nice way to the console

func (*User) SetID

func (u *User) SetID(i int)

SetID sets the ID of a user

func (*User) Slug

func (u *User) Slug() string

Slug is used to represent the model in cli

type UsersList

type UsersList struct {
	Users []User `json:"results"`
}

UsersList is a list of ninetofiver users

func (*UsersList) GetColumns

func (users *UsersList) GetColumns() []string

GetColumns returns an empty list because users are not displayed as a table

func (*UsersList) GetDefaultColumns

func (users *UsersList) GetDefaultColumns() []string

GetDefaultColumns returns an empty list because users are not displayed as a table

func (*UsersList) HasPorcelain

func (users *UsersList) HasPorcelain() bool

HasPorcelain returns false because users do not support PorcelainPrettyPrint

func (*UsersList) PorcelainPrettyPrint

func (users *UsersList) PorcelainPrettyPrint()

PorcelainPrettyPrint does nothing for this model

func (*UsersList) PrettyPrint

func (users *UsersList) PrettyPrint(columns []string)

PrettyPrint prints users in a nice way to the console

func (*UsersList) Slug

func (users *UsersList) Slug() string

Slug is used to represent the model in cli

Jump to

Keyboard shortcuts

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