twapi

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2025 License: MIT Imports: 8 Imported by: 0

README ΒΆ

Teamwork.com API - Go SDK

This is the official Go SDK for the Teamwork.com API.

https://apidocs.teamwork.com/

πŸ“¦ Installing

TO add this library as a dependency of youRun the following command inside your Go module:

go get github.com/teamwork/twapi-go-sdk

πŸ” Authentication

The library supports the following authentication methods:

  • Basic authentication using an API token or user credentials.
  • Bearer token authentication.
  • OAuth2 authentication using client ID and secret. This will open a browser window to authorize the application, so it is not suitable for headless environments.

🏁 Getting started

package main

import (
  "context"
  "fmt"
  "log"

  twapi "github.com/teamwork/twapi-go-sdk"
  "github.com/teamwork/twapi-go-sdk/projects"
  "github.com/teamwork/twapi-go-sdk/session"
)

func main() {
  ctx := context.Background()
  engine := twapi.NewEngine(session.NewBearerToken("your_token", "https://yourdomain.teamwork.com"))

  project, err := projects.ProjectCreate(ctx, engine, projects.ProjectCreateRequest{
    Name: "New Project",
  })
  if err != nil {
    fmt.Printf("failed to create project: %s", err)
  } else {
    fmt.Printf("created project with identifier %d\n", project.ID)
  }
}

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

func Execute ΒΆ

func Execute[T HTTPResponser](ctx context.Context, engine *Engine, requester HTTPRequester) (T, error)

Execute sends an HTTP request using the provided requester and handles the response using the provided responser.

func Ptr ΒΆ

func Ptr[T any](v T) *T

Ptr returns a pointer to the value v.

Types ΒΆ

type Date ΒΆ

type Date time.Time

Date is a type alias for time.Time, used to represent date values in the API.

func (Date) MarshalJSON ΒΆ

func (d Date) MarshalJSON() ([]byte, error)

MarshalJSON encodes the Date as a string in the format "2006-01-02".

func (Date) MarshalText ΒΆ

func (d Date) MarshalText() ([]byte, error)

MarshalText encodes the Date as a string in the format "2006-01-02".

func (Date) String ΒΆ

func (d Date) String() string

String returns the string representation of the Date in the format "2006-01-02".

func (*Date) UnmarshalJSON ΒΆ

func (d *Date) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a JSON string into a Date type.

func (*Date) UnmarshalText ΒΆ

func (d *Date) UnmarshalText(text []byte) error

UnmarshalText decodes a text string into a Date type. This is required when using Date type as a map key.

type Engine ΒΆ

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

Engine is the main structure that handles communication with the Teamwork API.

func NewEngine ΒΆ

func NewEngine(session Session, opts ...EngineOption) *Engine

NewEngine creates a new Engine instance with the provided HTTP client and session.

type EngineOption ΒΆ

type EngineOption func(*Engine)

EngineOption is a function that modifies the Engine configuration.

func WithHTTPClient ΒΆ

func WithHTTPClient(client *http.Client) EngineOption

WithHTTPClient sets the HTTP client for the Engine. By default, it uses http.DefaultClient.

func WithLogger ΒΆ

func WithLogger(logger *slog.Logger) EngineOption

WithLogger sets the logger for the Engine. By default, it uses slog.Default().

func WithRequestMiddleware ΒΆ added in v0.0.3

func WithRequestMiddleware(middleware func(HTTPRequester) HTTPRequester) EngineOption

WithRequestMiddleware adds a request middleware to the Engine. Middlewares are applied in the order they are added.

func WithResponseMiddleware ΒΆ added in v0.0.3

func WithResponseMiddleware(middleware func(HTTPResponser) HTTPResponser) EngineOption

WithResponseMiddleware adds a response middleware to the Engine. Middlewares are applied in the order they are added.

type HTTPError ΒΆ added in v0.0.3

type HTTPError struct {
	StatusCode int
	Headers    http.Header
	Message    string
	Details    string
}

HTTPError represents an error response from the API.

func NewHTTPError ΒΆ added in v0.0.3

func NewHTTPError(resp *http.Response, message string) *HTTPError

NewHTTPError creates a new HTTPError from an http.Response.

func (*HTTPError) Error ΒΆ added in v0.0.3

func (e *HTTPError) Error() string

Error implements the error interface.

type HTTPRequester ΒΆ

type HTTPRequester interface {
	HTTPRequest(ctx context.Context, server string) (*http.Request, error)
}

HTTPRequester knows how to create an HTTP request for a specific entity.

type HTTPResponser ΒΆ

type HTTPResponser interface {
	HandleHTTPResponse(resp *http.Response) error
}

HTTPResponser knows how to handle an HTTP response for a specific entity.

type Money ΒΆ

type Money int64

Money represents a monetary value in the API.

func (*Money) Set ΒΆ

func (m *Money) Set(value float64)

Set sets the value of Money from a float64.

func (Money) Value ΒΆ

func (m Money) Value() float64

Value returns the value of Money as a float64.

type OptionalDateTime ΒΆ

type OptionalDateTime time.Time

OptionalDateTime is a type alias for time.Time, used to represent date and time values in the API. The difference is that it will accept empty strings as valid values.

func (OptionalDateTime) MarshalJSON ΒΆ

func (d OptionalDateTime) MarshalJSON() ([]byte, error)

MarshalJSON encodes the OptionalDateTime as a string in the format "2006-01-02T15:04:05Z07:00".

func (*OptionalDateTime) UnmarshalJSON ΒΆ

func (d *OptionalDateTime) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a JSON string into an OptionalDateTime type.

type Relationship ΒΆ added in v0.0.3

type Relationship struct {
	ID   int64          `json:"id"`
	Type string         `json:"type"`
	Meta map[string]any `json:"meta,omitempty"`
}

Relationship describes the relation between the main entity and a sideload type.

type Session ΒΆ

type Session interface {
	Authenticate(ctx context.Context, req *http.Request) error
	Server() string
}

Session is an interface that defines the methods required for a session to authenticate requests to the Teamwork Engine.

type Time ΒΆ

type Time time.Time

Time is a type alias for time.Time, used to represent time values in the API.

func (Time) MarshalJSON ΒΆ

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON encodes the Time as a string in the format "15:04:05".

func (Time) MarshalText ΒΆ

func (t Time) MarshalText() ([]byte, error)

MarshalText encodes the Time as a string in the format "15:04:05".

func (Time) String ΒΆ

func (t Time) String() string

String returns the string representation of the Time in the format "15:04:05".

func (*Time) UnmarshalJSON ΒΆ

func (t *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a JSON string into a Date type.

func (*Time) UnmarshalText ΒΆ

func (t *Time) UnmarshalText(text []byte) error

UnmarshalText decodes a text string into a Time type. This is required when using Time type as a map key.

Directories ΒΆ

Path Synopsis
examples
oauth2 command
internal

Jump to

Keyboard shortcuts

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