-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.go
53 lines (45 loc) · 1.8 KB
/
project.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package client
import (
"context"
"net/http"
"net/url"
"strconv"
"github.com/calyptia/api/types"
)
// CreateProject creates a new project.
// A project is the base unit of work at Calyptia Cloud.
// You can register agents here, create core instances in which you can deploy an entire set of pipelines, and monitor them.
// You can even invite other people to the project and have a team.
func (c *Client) CreateProject(ctx context.Context, payload types.CreateProject) (types.CreatedProject, error) {
var out types.CreatedProject
return out, c.do(ctx, http.MethodPost, "/v1/projects", payload, &out)
}
// Projects you are a member of in descending order.
func (c *Client) Projects(ctx context.Context, params types.ProjectsParams) (types.Projects, error) {
q := url.Values{}
if params.Last != nil {
q.Set("last", strconv.FormatUint(uint64(*params.Last), uintBase))
}
if params.Before != nil {
q.Set("before", *params.Before)
}
if params.Name != nil {
q.Set("name", *params.Name)
}
var out types.Projects
return out, c.do(ctx, http.MethodGet, "/v1/projects?"+q.Encode(), nil, &out.Items, withCursor(&out.EndCursor))
}
// Project by ID.
func (c *Client) Project(ctx context.Context, projectID string) (types.Project, error) {
var out types.Project
return out, c.do(ctx, http.MethodGet, "/v1/projects/"+url.PathEscape(projectID), nil, &out)
}
// UpdateProject by its ID.
func (c *Client) UpdateProject(ctx context.Context, projectID string, opts types.UpdateProject) error {
return c.do(ctx, http.MethodPatch, "/v1/projects/"+url.PathEscape(projectID), opts, nil)
}
// DeleteProject by its ID.
func (c *Client) DeleteProject(ctx context.Context, projectID string) (types.Deleted, error) {
var out types.Deleted
return out, c.do(ctx, http.MethodDelete, "/v1/projects/"+url.PathEscape(projectID), nil, &out)
}