/
estimate_item_category.go
155 lines (121 loc) · 3.93 KB
/
estimate_item_category.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package harvest
import (
"context"
"fmt"
"net/http"
"time"
)
// Harvest API docs: https://help.getharvest.com/api-v2/estimates-api/estimates/estimate-item-categories/
type EstimateItemCategory struct {
// Unique ID for the estimate item category.
ID *int64 `json:"id,omitempty"`
// The name of the estimate item category.
Name *string `json:"name,omitempty"`
// Date and time the estimate item category was created.
CreatedAt *time.Time `json:"created_at,omitempty"`
// Date and time the estimate item category was last updated.
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}
type EstimateItemCategoryList struct {
EstimateItemCategories []*EstimateItemCategory `json:"estimate_item_categories"`
Pagination
}
type EstimateItemCategoryRequest struct {
Name *string `json:"name,omitempty"` // required The name of the estimate item category.
}
func (p EstimateItemCategory) String() string {
return Stringify(p)
}
func (p EstimateItemCategoryList) String() string {
return Stringify(p)
}
type EstimateItemCategoryListOptions struct {
// Only return estimate item categories that have been updated since the given date and time.
UpdatedSince time.Time `url:"updated_since,omitempty"`
ListOptions
}
// ListItemCategories returns a list of your estimate item categories.
func (s *EstimateService) ListItemCategories(
ctx context.Context,
opt *EstimateItemCategoryListOptions,
) (*EstimateItemCategoryList, *http.Response, error) {
u := "estimate_item_categories"
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
}
estimateItemCategoryList := new(EstimateItemCategoryList)
resp, err := s.client.Do(ctx, req, &estimateItemCategoryList)
if err != nil {
return nil, resp, err
}
return estimateItemCategoryList, resp, nil
}
// GetItemCategory retrieves the estimate item category with the given ID.
func (s *EstimateService) GetItemCategory(
ctx context.Context,
estimateItemCategoryID int64,
) (*EstimateItemCategory, *http.Response, error) {
u := fmt.Sprintf("estimate_item_categories/%d", estimateItemCategoryID)
req, err := s.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
}
estimateItemCategory := new(EstimateItemCategory)
resp, err := s.client.Do(ctx, req, estimateItemCategory)
if err != nil {
return nil, resp, err
}
return estimateItemCategory, resp, nil
}
// CreateItemCategory creates an estimate item category.
func (s *EstimateService) CreateItemCategory(
ctx context.Context,
data *EstimateItemCategoryRequest,
) (*EstimateItemCategory, *http.Response, error) {
u := "estimate_item_categories"
req, err := s.client.NewRequest(ctx, "POST", u, data)
if err != nil {
return nil, nil, err
}
estimateItemCategory := new(EstimateItemCategory)
resp, err := s.client.Do(ctx, req, estimateItemCategory)
if err != nil {
return nil, resp, err
}
return estimateItemCategory, resp, nil
}
// UpdateItemCategory updates an estimate item category.
func (s *EstimateService) UpdateItemCategory(
ctx context.Context,
estimateItemCategoryID int64,
data *EstimateItemCategoryRequest,
) (*EstimateItemCategory, *http.Response, error) {
u := fmt.Sprintf("estimate_item_categories/%d", estimateItemCategoryID)
req, err := s.client.NewRequest(ctx, "PATCH", u, data)
if err != nil {
return nil, nil, err
}
estimateItemCategory := new(EstimateItemCategory)
resp, err := s.client.Do(ctx, req, estimateItemCategory)
if err != nil {
return nil, resp, err
}
return estimateItemCategory, resp, nil
}
// DeleteItemCategory deletes an estimate item category.
func (s *EstimateService) DeleteItemCategory(
ctx context.Context,
estimateItemCategoryID int64,
) (*http.Response, error) {
u := fmt.Sprintf("estimate_item_categories/%d", estimateItemCategoryID)
req, err := s.client.NewRequest(ctx, "DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}