asana

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: MIT Imports: 11 Imported by: 0

README

go-asana

Build Status GoDoc Coverage Status

Go library for accessing the Asana API.

Note: go-asana is currently in development, so its API may have slightly breaking changes if we find better ways of doing things.

Usage
import "github.com/tambet/go-asana/asana"

Create a new Asana client instance, then use provided methods on the client to access the API. For example, to list all workspaces:

client := asana.NewClient(nil)
workspaces, err := client.ListWorkspaces()
Authentication

The go-asana library does not directly handle authentication. Instead, when creating a new client, pass an http.Client that can handle authentication for you. The easiest way to do this is using the goauth2 library, but you can always use any other library that provides an http.Client. If you have an OAuth2 access token, you can use it with the goauth2 using:

t := &oauth.Transport{
  Token: &oauth.Token{AccessToken: "... your access token ..."},
}

client := asana.NewClient(t.Client())

// List all projects for the authenticated user
projects, err := client.ListProjects(opt)

See the goauth2 docs for complete instructions on using that library.

Documentation

Overview

Package asana is a client for Asana API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(b bool) *bool

Bool returns a pointer to a bool.

Types

type Client

type Client struct {
	BaseURL   *url.URL
	UserAgent string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(doer Doer) *Client

NewClient created new asana client with doer. If doer is nil then http.DefaultClient used intead.

func (*Client) CreateTask

func (c *Client) CreateTask(ctx context.Context, fields map[string]string, opts *Filter) (Task, error)

CreateTask creates a task.

https://asana.com/developers/api-reference/tasks#create

func (*Client) CreateWebhook

func (c *Client) CreateWebhook(ctx context.Context, id int64, target string) (Webhook, error)

func (*Client) CreateWebhookWithGID

func (c *Client) CreateWebhookWithGID(ctx context.Context, id string, target string) (Webhook, error)

func (*Client) DeleteWebhook

func (c *Client) DeleteWebhook(ctx context.Context, id int64) error

func (*Client) DeleteWebhookByGID

func (c *Client) DeleteWebhookByGID(ctx context.Context, id string) error

func (*Client) GetAuthenticatedUser

func (c *Client) GetAuthenticatedUser(ctx context.Context, opt *Filter) (User, error)

func (*Client) GetTask

func (c *Client) GetTask(ctx context.Context, id int64, opt *Filter) (Task, error)

func (*Client) GetTaskByGID

func (c *Client) GetTaskByGID(ctx context.Context, id string, opt *Filter) (Task, error)

func (*Client) GetUserByID

func (c *Client) GetUserByID(ctx context.Context, id int64, opt *Filter) (User, error)

func (*Client) GetWebhook

func (c *Client) GetWebhook(ctx context.Context, id int64) (Webhook, error)

func (*Client) GetWebhookByGID

func (c *Client) GetWebhookByGID(ctx context.Context, id string) (Webhook, error)

func (*Client) GetWebhooks

func (c *Client) GetWebhooks(ctx context.Context, opt *Filter) ([]Webhook, error)

func (*Client) ListProjectTasks

func (c *Client) ListProjectTasks(ctx context.Context, projectID int64, opt *Filter) ([]Task, error)

func (*Client) ListProjects

func (c *Client) ListProjects(ctx context.Context, opt *Filter) ([]Project, error)

func (*Client) ListTags

func (c *Client) ListTags(ctx context.Context, opt *Filter) ([]Tag, error)

func (*Client) ListTaskStories

func (c *Client) ListTaskStories(ctx context.Context, taskID int64, opt *Filter) ([]Story, error)

func (*Client) ListTasks

func (c *Client) ListTasks(ctx context.Context, opt *Filter) ([]Task, error)

func (*Client) ListUsers

func (c *Client) ListUsers(ctx context.Context, opt *Filter) ([]User, error)

func (*Client) ListWorkspaces

func (c *Client) ListWorkspaces(ctx context.Context) ([]Workspace, error)

func (*Client) Request

func (c *Client) Request(ctx context.Context, path string, opt *Filter, v interface{}) error

func (*Client) UpdateTask

func (c *Client) UpdateTask(ctx context.Context, id int64, tu TaskUpdate, opt *Filter) (Task, error)

UpdateTask updates a task.

https://asana.com/developers/api-reference/tasks#update

func (*Client) UpdateTaskByGID

func (c *Client) UpdateTaskByGID(ctx context.Context, id string, tu TaskUpdate, opt *Filter) (Task, error)

type Doer

type Doer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer interface used for doing http calls. Use it as point of setting Auth header or custom status code error handling.

type DoerFunc

type DoerFunc func(req *http.Request) (resp *http.Response, err error)

DoerFunc implements Doer interface. Allow to transform any appropriate function "f" to Doer instance: DoerFunc(f).

func (DoerFunc) Do

func (f DoerFunc) Do(req *http.Request) (resp *http.Response, err error)

type Error

type Error struct {
	Phrase  string `json:"phrase,omitempty"`
	Message string `json:"message,omitempty"`
}

func (Error) Error

func (e Error) Error() string

type Errors

type Errors []Error

Errors always has at least 1 element when returned.

func (Errors) Error

func (e Errors) Error() string

type Filter

type Filter struct {
	Archived       *bool    `url:"archived,omitempty"`
	Assignee       int64    `url:"assignee,omitempty"`
	AssigneeGID    string   `url:"assignee,omitempty"`
	Project        int64    `url:"project,omitempty"`
	ProjectGID     string   `url:"project,omitempty"`
	Workspace      int64    `url:"workspace,omitempty"`
	WorkspaceGID   string   `url:"workspace,omitempty"`
	CompletedSince string   `url:"completed_since,omitempty"`
	ModifiedSince  string   `url:"modified_since,omitempty"`
	OptFields      []string `url:"opt_fields,comma,omitempty"`
	OptExpand      []string `url:"opt_expand,comma,omitempty"`
	Offset         string   `url:"offset,omitempty"`
	Limit          uint32   `url:"limit,omitempty"`
}

type Heart

type Heart struct {
	ID   int64 `json:"id,omitempty"`
	User User  `json:"user,omitempty"`
}

Heart represents a ♥ action by a user.

type NextPage

type NextPage struct {
	Offset string `json:"offset,omitempty"`
	Path   string `json:"path,omitempty"`
	URI    string `json:"uri,omitempty"`
}

type Project

type Project struct {
	ID       int64  `json:"id,omitempty"`
	GID      string `json:"gid,omitempty"`
	Name     string `json:"name,omitempty"`
	Archived bool   `json:"archived,omitempty"`
	Color    string `json:"color,omitempty"`
	Notes    string `json:"notes,omitempty"`
}

type RequestError

type RequestError struct {
	Body string
	Code int
}

HTTP request error

func (RequestError) Error

func (re RequestError) Error() string

type Resource

type Resource struct {
	ID   int64  `json:"id,omitempty"`
	GID  string `json:"gid,omitempty"`
	Name string `json:"name,omitempty"`
}

type Response

type Response struct {
	Data     interface{} `json:"data,omitempty"`
	NextPage *NextPage   `json:"next_page,omitempty"`
	Errors   Errors      `json:"errors,omitempty"`
}

type Story

type Story struct {
	ID        int64     `json:"id,omitempty"`
	GID       string    `json:"gid,omitempty"`
	CreatedAt time.Time `json:"created_at,omitempty"`
	CreatedBy User      `json:"created_by,omitempty"`
	Hearts    []Heart   `json:"hearts,omitempty"`
	Text      string    `json:"text,omitempty"`
	Type      string    `json:"type,omitempty"` // E.g., "comment", "system".
}

type Tag

type Tag struct {
	ID    int64  `json:"id,omitempty"`
	GID   string `json:"gid,omitempty"`
	Name  string `json:"name,omitempty"`
	Color string `json:"color,omitempty"`
	Notes string `json:"notes,omitempty"`
}

type Task

type Task struct {
	ID             int64     `json:"id,omitempty"`
	GID            string    `json:"gid,omitempty"`
	Assignee       *User     `json:"assignee,omitempty"`
	AssigneeStatus string    `json:"assignee_status,omitempty"`
	CreatedAt      time.Time `json:"created_at,omitempty"`
	CreatedBy      User      `json:"created_by,omitempty"` // Undocumented field, but it can be included.
	Completed      bool      `json:"completed,omitempty"`
	CompletedAt    time.Time `json:"completed_at,omitempty"`
	Name           string    `json:"name,omitempty"`
	Hearts         []Heart   `json:"hearts,omitempty"`
	Notes          string    `json:"notes,omitempty"`
	ParentTask     *Task     `json:"parent,omitempty"`
	Projects       []Project `json:"projects,omitempty"`
	DueOn          string    `json:"due_on,omitempty"`
	DueAt          string    `json:"due_at,omitempty"`
}

type TaskUpdate

type TaskUpdate struct {
	Notes   *string `json:"notes,omitempty"`
	Hearted *bool   `json:"hearted,omitempty"`
}

TaskUpdate is used to update a task.

type User

type User struct {
	ID         int64             `json:"id,omitempty"`
	GID        string            `json:"gid,omitempty"`
	Email      string            `json:"email,omitempty"`
	Name       string            `json:"name,omitempty"`
	Photo      map[string]string `json:"photo,omitempty"`
	Workspaces []Workspace       `json:"workspaces,omitempty"`
}

type Webhook

type Webhook struct {
	ID       int64    `json:"id,omitempty"`
	GID      string   `json:"gid,omitempty"`
	Resource Resource `json:"resource,omitempty"`
	Target   string   `json:"target,omitempty"`
	Active   bool     `json:"active,omitempty"`
}

type Workspace

type Workspace struct {
	ID           int64  `json:"id,omitempty"`
	GID          string `json:"gid,omitempty"`
	Name         string `json:"name,omitempty"`
	Organization bool   `json:"is_organization,omitempty"`
}

Jump to

Keyboard shortcuts

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