Documentation ¶
Index ¶
- Constants
- Variables
- func GetSidPidFromKey(key string) (IntegrationID, PipeID)
- func PipesKey(sid IntegrationID, pid PipeID) string
- type Account
- type AccountsResponse
- type AuthParams
- type Authorization
- type AuthorizationService
- type AuthorizationsStorage
- type Client
- type ClientRequest
- type ClientsImport
- type ClientsResponse
- type HealthCheckService
- type IDMapping
- type IDMappingsStorage
- type ImportsStorage
- type Integration
- type IntegrationID
- type IntegrationsStorage
- type OAuthProvider
- type Pipe
- type PipeID
- type PipeIntegration
- type PipeService
- type PipeSyncService
- type PipesStorage
- type Project
- type ProjectRequest
- type ProjectsImport
- type ProjectsResponse
- type Queue
- type ReversedIDMapping
- type Status
- type Task
- type TaskRequest
- type TasksImport
- type TasksResponse
- type TimeEntry
- type TogglClient
- type User
- type UserParams
- type UsersImport
- type UsersRequest
- type UsersResponse
- type Workspace
- type WorkspaceResponse
Constants ¶
const ( TypeOauth2 = "oauth2" TypeOauth1 = "oauth1" )
const ( StatusRunning = "running" StatusError = "error" StatusSuccess = "success" )
Variables ¶
var ErrJSONParsing = errors.New("failed to parse response from service, please contact support")
ErrJSONParsing hides json marshalling errors from users
Functions ¶
func GetSidPidFromKey ¶
func GetSidPidFromKey(key string) (IntegrationID, PipeID)
func PipesKey ¶
func PipesKey(sid IntegrationID, pid PipeID) string
Types ¶
type AccountsResponse ¶
type AuthParams ¶
type AuthParams struct { // Fields used for OAuth1 AccountName string `json:"account_name,omitempty"` Token string `json:"oauth_token,omitempty"` Verifier string `json:"oauth_verifier,omitempty"` // Fields used for OAuth2 Code string `json:"code,omitempty"` }
AuthParams describes authorization parameters that come from `pipes-ui`. This structure is used for both oAuth1 and oAuth2 params.
type Authorization ¶
type Authorization struct { WorkspaceID int ServiceID IntegrationID WorkspaceToken string // Data can store 2 different structures encoded to JSON depends on Authorization type. // For oAuth v1 it will store "*oauthplain.Token" and for oAuth v2 it will store "*goauth2.Token". Data []byte }
func NewAuthorization ¶
func NewAuthorization(workspaceID int, id IntegrationID) *Authorization
func (*Authorization) SetOAuth1Token ¶
func (a *Authorization) SetOAuth1Token(t *oauthplain.Token) error
func (*Authorization) SetOAuth2Token ¶
func (a *Authorization) SetOAuth2Token(t *goauth2.Token) error
type AuthorizationService ¶
type AuthorizationService interface { GetAuthURL(sid IntegrationID, accountName, callbackURL string) (string, error) // CreateAuthorization creates new authorization for specified workspace and service and stores it in the persistent storage. // workspaceToken - it is an "Toggl.Track" authorization token which is "user_name" field from BasicAuth HTTP Header. E.g.: "Authorization Bearer base64(user_name:password)". CreateAuthorization(workspaceID int, sid IntegrationID, workspaceToken string, params AuthParams) error // DeleteAuthorization removes authorization for specified workspace and service from the persistent storage. // It also delete all pipes for given service and workspace. DeleteAuthorization(workspaceID int, sid IntegrationID) error }
type AuthorizationsStorage ¶
type AuthorizationsStorage interface { Load(workspaceID int, externalServiceID IntegrationID, a *Authorization) error LoadWorkspaceAuthorizations(workspaceID int) (map[IntegrationID]bool, error) Save(a *Authorization) error Delete(workspaceID int, externalServiceID IntegrationID) error }
type ClientRequest ¶
type ClientRequest struct {
Clients []*Client `json:"clients"`
}
type ClientsImport ¶
type ClientsImport struct { Clients []*Client `json:"clients"` Notifications []string `json:"notifications"` }
func (*ClientsImport) Count ¶
func (p *ClientsImport) Count() int
type ClientsResponse ¶
type HealthCheckService ¶
type HealthCheckService interface {
Ready() []error
}
type IDMapping ¶
IDMapping describes service IntegrationID connection between external services end Toggl.
It can store "users", "clients", "projects", "tasks", "todolists" or "time_entries" id mappings. The "Key" field will store different types of data described above. In a different cases "Data" map will store different types, such as:
map[ForeignTaskID]TaskID (E.g. map["1"] = 112) map[ForeignClientID]ClientID (E.g. map["2"] = 234) map[ForeignProjectID]ProjectID (E.g. map["3"] = 350)
func NewIDMapping ¶
type IDMappingsStorage ¶
type ImportsStorage ¶
type ImportsStorage interface { // Imports LoadAccountsFor(s PipeIntegration) (*AccountsResponse, error) SaveAccountsFor(s PipeIntegration, res AccountsResponse) error DeleteAccountsFor(s PipeIntegration) error LoadUsersFor(s PipeIntegration) (*UsersResponse, error) SaveUsersFor(s PipeIntegration, res UsersResponse) error DeleteUsersFor(s PipeIntegration) error LoadClientsFor(s PipeIntegration) (*ClientsResponse, error) SaveClientsFor(s PipeIntegration, res ClientsResponse) error LoadProjectsFor(s PipeIntegration) (*ProjectsResponse, error) SaveProjectsFor(s PipeIntegration, res ProjectsResponse) error LoadTasksFor(s PipeIntegration) (*TasksResponse, error) SaveTasksFor(s PipeIntegration, res TasksResponse) error LoadTodoListsFor(s PipeIntegration) (*TasksResponse, error) SaveTodoListsFor(s PipeIntegration, res TasksResponse) error }
type Integration ¶
type IntegrationID ¶
type IntegrationID string
const ( BaseCamp IntegrationID = "basecamp" FreshBooks IntegrationID = "freshbooks" TogglPlan IntegrationID = "teamweek" // should not be changed to "togglplan", because active customers lost their synchronized data. Asana IntegrationID = "asana" GitHub IntegrationID = "github" )
type IntegrationsStorage ¶
type IntegrationsStorage interface { LoadIntegrations() ([]*Integration, error) LoadAuthorizationType(serviceID IntegrationID) (string, error) SaveAuthorizationType(serviceID IntegrationID, authType string) error IsValidPipe(pipeID PipeID) bool IsValidService(serviceID IntegrationID) bool }
type OAuthProvider ¶
type OAuthProvider interface { OAuth2URL(IntegrationID) string OAuth1Configs(IntegrationID) (*oauthplain.Config, bool) OAuth1Exchange(sid IntegrationID, accountName, oAuthToken, oAuthVerifier string) (*oauthplain.Token, error) OAuth2Exchange(sid IntegrationID, code string) (*goauth2.Token, error) OAuth2Configs(IntegrationID) (*goauth2.Config, bool) OAuth2Refresh(*goauth2.Config, *goauth2.Token) error }
type Pipe ¶
type Pipe struct { ID PipeID `json:"id"` Name string `json:"name"` Description string `json:"description,omitempty"` Automatic bool `json:"automatic,omitempty"` AutomaticOption bool `json:"automatic_option"` Configured bool `json:"configured"` Premium bool `json:"premium"` ServiceParams []byte `json:"service_params,omitempty"` PipeStatus *Status `json:"pipe_status,omitempty"` WorkspaceID int `json:"-"` ServiceID IntegrationID `json:"-"` UsersSelector UserParams `json:"-"` LastSync *time.Time `json:"-"` PipesApiHost string `json:"-"` }
type PipeIntegration ¶
type PipeIntegration interface { // IntegrationID returns an IntegrationID of the service ID() IntegrationID // GetWorkspaceID helper function, should just return workspaceID GetWorkspaceID() int // SetSince takes the provided time.Time // and adds it to Integration struct. This can be used // to fetch just the modified data from external services. // Implemented only for "basecamp" integration. SetSince(*time.Time) // SetParams takes the necessary Integration params // (for example the selected account id) as JSON // and adds them to Integration struct. SetParams([]byte) error // SetAuthData adds the provided oauth token to Integration struct SetAuthData([]byte) error // KeyFor should provide unique key for object type // Example: asana:account:XXXX:projects KeyFor(PipeID) string // Accounts maps foreign account to Account models Accounts() ([]*Account, error) // Users maps foreign users to User models Users() ([]*User, error) // Clients maps foreign clients to Client models Clients() ([]*Client, error) // Projects maps foreign projects to Project models Projects() ([]*Project, error) // Tasks maps foreign tasks to Task models Tasks() ([]*Task, error) // TodoLists maps foreign to do lists to Task models TodoLists() ([]*Task, error) // ExportTimeEntry exports time entry model to foreign service // should return foreign id of saved time entry // Implemented only for "freshbook" integration ExportTimeEntry(*TimeEntry) (int, error) }
Integration interface for external integrations Example implementation: github.go
type PipeService ¶
type PipeService interface { GetPipe(workspaceID int, sid IntegrationID, pid PipeID) (*Pipe, error) CreatePipe(workspaceID int, sid IntegrationID, pid PipeID, params []byte) error UpdatePipe(workspaceID int, sid IntegrationID, pid PipeID, params []byte) error DeletePipe(workspaceID int, sid IntegrationID, pid PipeID) error }
type PipeSyncService ¶
type PipeSyncService interface { GetServicePipeLog(workspaceID int, sid IntegrationID, pid PipeID) (string, error) GetServiceUsers(workspaceID int, sid IntegrationID, forceImport bool) (*UsersResponse, error) GetServiceAccounts(workspaceID int, sid IntegrationID, forceImport bool) (*AccountsResponse, error) GetIntegrations(workspaceID int) ([]Integration, error) Synchronize(p *Pipe) error // Deprecated: TODO: Remove dead method. It's used only in h4xx0rz(old Backoffice) https://github.com/toggl/support/blob/master/app/controllers/workspaces_controller.rb#L145 ClearIDMappings(workspaceID int, sid IntegrationID, pid PipeID) error }
type PipesStorage ¶
type PipesStorage interface { // Pipes Load(p *Pipe) error LoadAll(workspaceID int) (map[string]*Pipe, error) Save(p *Pipe) error Delete(p *Pipe, workspaceID int) error DeleteByWorkspaceIDServiceID(workspaceID int, sid IntegrationID) error LoadLastSyncFor(p *Pipe) // Pipe Statuses LoadStatus(workspaceID int, sid IntegrationID, pid PipeID) (*Status, error) LoadAllStatuses(workspaceID int) (map[string]*Status, error) SaveStatus(p *Status) error IsDown() bool }
type Project ¶
type Project struct { ID int `json:"id,omitempty"` Name string `json:"name,omitempty"` Active bool `json:"active,omitempty"` Billable bool `json:"billable,omitempty"` ClientID int `json:"cid,omitempty"` // ForeignID is a meta information which won't be saved into DB on "toggl_api" side. ForeignID string `json:"foreign_id,omitempty"` ForeignClientID string `json:"-"` }
type ProjectRequest ¶
type ProjectRequest struct {
Projects []*Project `json:"projects"`
}
type ProjectsImport ¶
type ProjectsImport struct { Projects []*Project `json:"projects"` Notifications []string `json:"notifications"` }
func (*ProjectsImport) Count ¶
func (p *ProjectsImport) Count() int
type ProjectsResponse ¶
type Queue ¶
type Queue interface { ScheduleAutomaticPipesSynchronization() error LoadScheduledPipes() ([]*Pipe, error) MarkPipeSynchronized(*Pipe) error SchedulePipeSynchronization(workspaceID int, serviceID IntegrationID, pipeID PipeID, usersSelector UserParams) error }
type ReversedIDMapping ¶
ReversedIDMapping describes reversed service id mappings.
It can store "tasks", "users" or "projects" item id mappings. In a different cases "Data" map will store different types, such as:
map[TaskID]ForeignTaskID-tasks (E.g. map[1] = "5-tasks") map[UserID]ForeignUserID-users (E.g. map[2] = "3-users") map[ProjectID]ForeignProjectID-projects (E.g. map[5] = "8-projects")
func NewReversedConnection ¶
func NewReversedConnection() *ReversedIDMapping
func (*ReversedIDMapping) GetForeignID ¶
func (c *ReversedIDMapping) GetForeignID(key int) int
func (*ReversedIDMapping) GetKeys ¶
func (c *ReversedIDMapping) GetKeys() []int
type Status ¶
type Status struct { Status string `json:"status,omitempty"` Message string `json:"message,omitempty"` SyncLog string `json:"sync_log,omitempty"` SyncDate string `json:"sync_date,omitempty"` ObjectCounts []string `json:"object_counts,omitempty"` Notifications []string `json:"notifications,omitempty"` WorkspaceID int `json:"-"` ServiceID IntegrationID `json:"-"` PipeID PipeID `json:"-"` Key string `json:"-"` PipesApiHost string `json:"-"` }
func NewStatus ¶
func NewStatus(workspaceID int, externalServiceID IntegrationID, pipeID PipeID, pipesApiHost string) *Status
func (*Status) GenerateLog ¶
type TaskRequest ¶
type TaskRequest struct {
Tasks []*Task `json:"tasks"`
}
type TasksImport ¶
type TasksImport struct { Tasks []*Task `json:"tasks"` Notifications []string `json:"notifications"` }
func (*TasksImport) Count ¶
func (p *TasksImport) Count() int
type TasksResponse ¶
type TimeEntry ¶
type TimeEntry struct { ID int `json:"id"` ProjectID int `json:"pid,omitempty"` TaskID int `json:"tid,omitempty"` UserID int `json:"uid,omitempty"` Billable bool `json:"billable"` Start string `json:"start"` Stop string `json:"stop,omitempty"` DurationInSeconds int `json:"duration"` Description string `json:"description,omitempty"` // ForeignID is a meta information which won't be saved into DB on "toggl_api" side. ForeignID string `json:"foreign_id,omitempty"` ForeignTaskID string `json:"-"` ForeignUserID string `json:"-"` ForeignProjectID string `json:"-"` }
type TogglClient ¶
type TogglClient interface { WithAuthToken(authToken string) GetWorkspaceIdByToken(token string) (int, error) PostClients(clientsPipeID PipeID, clients interface{}) (*ClientsImport, error) PostProjects(projectsPipeID PipeID, projects interface{}) (*ProjectsImport, error) PostTasks(tasksPipeID PipeID, tasks interface{}) (*TasksImport, error) PostTodoLists(tasksPipeID PipeID, tasks interface{}) (*TasksImport, error) PostUsers(usersPipeID PipeID, users interface{}) (*UsersImport, error) GetTimeEntries(lastSync time.Time, userIDs, projectsIDs []int) ([]TimeEntry, error) AdjustRequestSize(tasks []*Task, split int) ([]*TaskRequest, error) Ping() error }
type UserParams ¶
type UsersImport ¶
type UsersImport struct { WorkspaceUsers []*User `json:"users"` Notifications []string `json:"notifications"` }
func (*UsersImport) Count ¶
func (p *UsersImport) Count() int
type UsersRequest ¶
type UsersRequest struct {
Users []*User `json:"users"`
}
type UsersResponse ¶
type WorkspaceResponse ¶
type WorkspaceResponse struct {
Workspace *Workspace `json:"data"`
}