-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhrisdirectory.go
301 lines (264 loc) · 9.18 KB
/
hrisdirectory.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package finchgo
import (
"context"
"net/http"
"net/url"
"github.com/Finch-API/finch-api-go/internal/apijson"
"github.com/Finch-API/finch-api-go/internal/apiquery"
"github.com/Finch-API/finch-api-go/internal/param"
"github.com/Finch-API/finch-api-go/internal/requestconfig"
"github.com/Finch-API/finch-api-go/option"
"github.com/Finch-API/finch-api-go/shared"
)
// HRISDirectoryService contains methods and other services that help with
// interacting with the Finch API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewHRISDirectoryService] method instead.
type HRISDirectoryService struct {
Options []option.RequestOption
}
// NewHRISDirectoryService generates a new service that applies the given options
// to each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewHRISDirectoryService(opts ...option.RequestOption) (r *HRISDirectoryService) {
r = &HRISDirectoryService{}
r.Options = opts
return
}
// Read company directory and organization structure
func (r *HRISDirectoryService) List(ctx context.Context, query HRISDirectoryListParams, opts ...option.RequestOption) (res *IndividualsPage, err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "employer/directory"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// Read company directory and organization structure
func (r *HRISDirectoryService) ListAutoPaging(ctx context.Context, query HRISDirectoryListParams, opts ...option.RequestOption) *IndividualsPageAutoPager {
return NewIndividualsPageAutoPager(r.List(ctx, query, opts...))
}
// Read company directory and organization structure
//
// Deprecated: use `List` instead
func (r *HRISDirectoryService) ListIndividuals(ctx context.Context, query HRISDirectoryListIndividualsParams, opts ...option.RequestOption) (res *IndividualsPage, err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "employer/directory"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// Read company directory and organization structure
//
// Deprecated: use `List` instead
func (r *HRISDirectoryService) ListIndividualsAutoPaging(ctx context.Context, query HRISDirectoryListIndividualsParams, opts ...option.RequestOption) *IndividualsPageAutoPager {
return NewIndividualsPageAutoPager(r.ListIndividuals(ctx, query, opts...))
}
type IndividualsPage struct {
// The array of employees.
Individuals []IndividualInDirectory `json:"individuals"`
Paging shared.Paging `json:"paging,required"`
JSON individualsPageJSON `json:"-"`
cfg *requestconfig.RequestConfig
res *http.Response
}
// individualsPageJSON contains the JSON metadata for the struct [IndividualsPage]
type individualsPageJSON struct {
Individuals apijson.Field
Paging apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *IndividualsPage) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r individualsPageJSON) RawJSON() string {
return r.raw
}
// GetNextPage returns the next page as defined by this pagination style. When
// there is no next page, this function will return a 'nil' for the page value, but
// will not return an error
func (r *IndividualsPage) GetNextPage() (res *IndividualsPage, err error) {
// This page represents a response that isn't actually paginated at the API level
// so there will never be a next page.
cfg := (*requestconfig.RequestConfig)(nil)
if cfg == nil {
return nil, nil
}
var raw *http.Response
cfg.ResponseInto = &raw
cfg.ResponseBodyInto = &res
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
func (r *IndividualsPage) SetPageConfig(cfg *requestconfig.RequestConfig, res *http.Response) {
if r == nil {
r = &IndividualsPage{}
}
r.cfg = cfg
r.res = res
}
type IndividualsPageAutoPager struct {
page *IndividualsPage
cur IndividualInDirectory
idx int
run int
err error
}
func NewIndividualsPageAutoPager(page *IndividualsPage, err error) *IndividualsPageAutoPager {
return &IndividualsPageAutoPager{
page: page,
err: err,
}
}
func (r *IndividualsPageAutoPager) Next() bool {
if r.page == nil || len(r.page.Individuals) == 0 {
return false
}
if r.idx >= len(r.page.Individuals) {
r.idx = 0
r.page, r.err = r.page.GetNextPage()
if r.err != nil || r.page == nil || len(r.page.Individuals) == 0 {
return false
}
}
r.cur = r.page.Individuals[r.idx]
r.run += 1
r.idx += 1
return true
}
func (r *IndividualsPageAutoPager) Current() IndividualInDirectory {
return r.cur
}
func (r *IndividualsPageAutoPager) Err() error {
return r.err
}
func (r *IndividualsPageAutoPager) Index() int {
return r.run
}
type IndividualInDirectory struct {
// A stable Finch id (UUID v4) for an individual in the company.
ID string `json:"id"`
// The department object.
Department IndividualInDirectoryDepartment `json:"department,nullable"`
// The legal first name of the individual.
FirstName string `json:"first_name,nullable"`
// `true` if the individual is an active employee or contractor at the company.
IsActive bool `json:"is_active,nullable"`
// The legal last name of the individual.
LastName string `json:"last_name,nullable"`
// The manager object.
Manager IndividualInDirectoryManager `json:"manager,nullable"`
// The legal middle name of the individual.
MiddleName string `json:"middle_name,nullable"`
JSON individualInDirectoryJSON `json:"-"`
}
// individualInDirectoryJSON contains the JSON metadata for the struct
// [IndividualInDirectory]
type individualInDirectoryJSON struct {
ID apijson.Field
Department apijson.Field
FirstName apijson.Field
IsActive apijson.Field
LastName apijson.Field
Manager apijson.Field
MiddleName apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *IndividualInDirectory) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r individualInDirectoryJSON) RawJSON() string {
return r.raw
}
// The department object.
type IndividualInDirectoryDepartment struct {
// The name of the department.
Name string `json:"name,nullable"`
JSON individualInDirectoryDepartmentJSON `json:"-"`
}
// individualInDirectoryDepartmentJSON contains the JSON metadata for the struct
// [IndividualInDirectoryDepartment]
type individualInDirectoryDepartmentJSON struct {
Name apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *IndividualInDirectoryDepartment) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r individualInDirectoryDepartmentJSON) RawJSON() string {
return r.raw
}
// The manager object.
type IndividualInDirectoryManager struct {
// A stable Finch `id` (UUID v4) for an individual in the company.
ID string `json:"id"`
JSON individualInDirectoryManagerJSON `json:"-"`
}
// individualInDirectoryManagerJSON contains the JSON metadata for the struct
// [IndividualInDirectoryManager]
type individualInDirectoryManagerJSON struct {
ID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *IndividualInDirectoryManager) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r individualInDirectoryManagerJSON) RawJSON() string {
return r.raw
}
type HRISDirectoryListParams struct {
// Number of employees to return (defaults to all)
Limit param.Field[int64] `query:"limit"`
// Index to start from (defaults to 0)
Offset param.Field[int64] `query:"offset"`
}
// URLQuery serializes [HRISDirectoryListParams]'s query parameters as
// `url.Values`.
func (r HRISDirectoryListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type HRISDirectoryListIndividualsParams struct {
// Number of employees to return (defaults to all)
Limit param.Field[int64] `query:"limit"`
// Index to start from (defaults to 0)
Offset param.Field[int64] `query:"offset"`
}
// URLQuery serializes [HRISDirectoryListIndividualsParams]'s query parameters as
// `url.Values`.
func (r HRISDirectoryListIndividualsParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}