Debian Codegraph @

talent/apiv4/company_client.go

raw
1 // Copyright 2025 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17 package talent
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
30 talentpb "cloud.google.com/go/talent/apiv4/talentpb"
31 gax "github.com/googleapis/gax-go/v2"
32 "google.golang.org/api/iterator"
33 "google.golang.org/api/option"
34 "google.golang.org/api/option/internaloption"
35 gtransport "google.golang.org/api/transport/grpc"
36 httptransport "google.golang.org/api/transport/http"
37 "google.golang.org/grpc"
38 "google.golang.org/grpc/codes"
39 "google.golang.org/protobuf/encoding/protojson"
40 "google.golang.org/protobuf/proto"
41 )
42
43 var newCompanyClientHook clientHook
44
45 // CompanyCallOptions contains the retry settings for each method of CompanyClient.
46 type CompanyCallOptions struct {
47 CreateCompany []gax.CallOption
48 GetCompany []gax.CallOption
49 UpdateCompany []gax.CallOption
50 DeleteCompany []gax.CallOption
51 ListCompanies []gax.CallOption
52 GetOperation []gax.CallOption
53 }
54
55 func defaultCompanyGRPCClientOptions() []option.ClientOption {
56 return []option.ClientOption{
57 internaloption.WithDefaultEndpoint("jobs.googleapis.com:443"),
58 internaloption.WithDefaultEndpointTemplate("jobs.UNIVERSE_DOMAIN:443"),
59 internaloption.WithDefaultMTLSEndpoint("jobs.mtls.googleapis.com:443"),
60 internaloption.WithDefaultUniverseDomain("googleapis.com"),
61 internaloption.WithDefaultAudience("https://jobs.googleapis.com/"),
62 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
63 internaloption.EnableJwtWithScope(),
64 internaloption.EnableNewAuthLibrary(),
65 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
66 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
67 }
68 }
69
70 func defaultCompanyCallOptions() *CompanyCallOptions {
71 return &CompanyCallOptions{
72 CreateCompany: []gax.CallOption{
73 gax.WithTimeout(30000 * time.Millisecond),
74 },
75 GetCompany: []gax.CallOption{
76 gax.WithTimeout(30000 * time.Millisecond),
77 gax.WithRetry(func() gax.Retryer {
78 return gax.OnCodes([]codes.Code{
79 codes.DeadlineExceeded,
80 codes.Unavailable,
81 }, gax.Backoff{
82 Initial: 100 * time.Millisecond,
83 Max: 60000 * time.Millisecond,
84 Multiplier: 1.30,
85 })
86 }),
87 },
88 UpdateCompany: []gax.CallOption{
89 gax.WithTimeout(30000 * time.Millisecond),
90 },
91 DeleteCompany: []gax.CallOption{
92 gax.WithTimeout(30000 * time.Millisecond),
93 gax.WithRetry(func() gax.Retryer {
94 return gax.OnCodes([]codes.Code{
95 codes.DeadlineExceeded,
96 codes.Unavailable,
97 }, gax.Backoff{
98 Initial: 100 * time.Millisecond,
99 Max: 60000 * time.Millisecond,
100 Multiplier: 1.30,
101 })
102 }),
103 },
104 ListCompanies: []gax.CallOption{
105 gax.WithTimeout(30000 * time.Millisecond),
106 gax.WithRetry(func() gax.Retryer {
107 return gax.OnCodes([]codes.Code{
108 codes.DeadlineExceeded,
109 codes.Unavailable,
110 }, gax.Backoff{
111 Initial: 100 * time.Millisecond,
112 Max: 60000 * time.Millisecond,
113 Multiplier: 1.30,
114 })
115 }),
116 },
117 GetOperation: []gax.CallOption{},
118 }
119 }
120
121 func defaultCompanyRESTCallOptions() *CompanyCallOptions {
122 return &CompanyCallOptions{
123 CreateCompany: []gax.CallOption{
124 gax.WithTimeout(30000 * time.Millisecond),
125 },
126 GetCompany: []gax.CallOption{
127 gax.WithTimeout(30000 * time.Millisecond),
128 gax.WithRetry(func() gax.Retryer {
129 return gax.OnHTTPCodes(gax.Backoff{
130 Initial: 100 * time.Millisecond,
131 Max: 60000 * time.Millisecond,
132 Multiplier: 1.30,
133 },
134 http.StatusGatewayTimeout,
135 http.StatusServiceUnavailable)
136 }),
137 },
138 UpdateCompany: []gax.CallOption{
139 gax.WithTimeout(30000 * time.Millisecond),
140 },
141 DeleteCompany: []gax.CallOption{
142 gax.WithTimeout(30000 * time.Millisecond),
143 gax.WithRetry(func() gax.Retryer {
144 return gax.OnHTTPCodes(gax.Backoff{
145 Initial: 100 * time.Millisecond,
146 Max: 60000 * time.Millisecond,
147 Multiplier: 1.30,
148 },
149 http.StatusGatewayTimeout,
150 http.StatusServiceUnavailable)
151 }),
152 },
153 ListCompanies: []gax.CallOption{
154 gax.WithTimeout(30000 * time.Millisecond),
155 gax.WithRetry(func() gax.Retryer {
156 return gax.OnHTTPCodes(gax.Backoff{
157 Initial: 100 * time.Millisecond,
158 Max: 60000 * time.Millisecond,
159 Multiplier: 1.30,
160 },
161 http.StatusGatewayTimeout,
162 http.StatusServiceUnavailable)
163 }),
164 },
165 GetOperation: []gax.CallOption{},
166 }
167 }
168
169 // internalCompanyClient is an interface that defines the methods available from Cloud Talent Solution API.
170 type internalCompanyClient interface {
171 Close() error
172 setGoogleClientInfo(...string)
173 Connection() *grpc.ClientConn
174 CreateCompany(context.Context, *talentpb.CreateCompanyRequest, ...gax.CallOption) (*talentpb.Company, error)
175 GetCompany(context.Context, *talentpb.GetCompanyRequest, ...gax.CallOption) (*talentpb.Company, error)
176 UpdateCompany(context.Context, *talentpb.UpdateCompanyRequest, ...gax.CallOption) (*talentpb.Company, error)
177 DeleteCompany(context.Context, *talentpb.DeleteCompanyRequest, ...gax.CallOption) error
178 ListCompanies(context.Context, *talentpb.ListCompaniesRequest, ...gax.CallOption) *CompanyIterator
179 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
180 }
181
182 // CompanyClient is a client for interacting with Cloud Talent Solution API.
183 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
184 //
185 // A service that handles company management, including CRUD and enumeration.
186 type CompanyClient struct {
187 // The internal transport-dependent client.
188 internalClient internalCompanyClient
189
190 // The call options for this service.
191 CallOptions *CompanyCallOptions
192 }
193
194 // Wrapper methods routed to the internal client.
195
196 // Close closes the connection to the API service. The user should invoke this when
197 // the client is no longer required.
198 func (c *CompanyClient) Close() error {
199 return c.internalClient.Close()
200 }
201
202 // setGoogleClientInfo sets the name and version of the application in
203 // the `x-goog-api-client` header passed on each request. Intended for
204 // use by Google-written clients.
205 func (c *CompanyClient) setGoogleClientInfo(keyval ...string) {
206 c.internalClient.setGoogleClientInfo(keyval...)
207 }
208
209 // Connection returns a connection to the API service.
210 //
211 // Deprecated: Connections are now pooled so this method does not always
212 // return the same resource.
213 func (c *CompanyClient) Connection() *grpc.ClientConn {
214 return c.internalClient.Connection()
215 }
216
217 // CreateCompany creates a new company entity.
218 func (c *CompanyClient) CreateCompany(ctx context.Context, req *talentpb.CreateCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) {
219 return c.internalClient.CreateCompany(ctx, req, opts...)
220 }
221
222 // GetCompany retrieves specified company.
223 func (c *CompanyClient) GetCompany(ctx context.Context, req *talentpb.GetCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) {
224 return c.internalClient.GetCompany(ctx, req, opts...)
225 }
226
227 // UpdateCompany updates specified company.
228 func (c *CompanyClient) UpdateCompany(ctx context.Context, req *talentpb.UpdateCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) {
229 return c.internalClient.UpdateCompany(ctx, req, opts...)
230 }
231
232 // DeleteCompany deletes specified company.
233 // Prerequisite: The company has no jobs associated with it.
234 func (c *CompanyClient) DeleteCompany(ctx context.Context, req *talentpb.DeleteCompanyRequest, opts ...gax.CallOption) error {
235 return c.internalClient.DeleteCompany(ctx, req, opts...)
236 }
237
238 // ListCompanies lists all companies associated with the project.
239 func (c *CompanyClient) ListCompanies(ctx context.Context, req *talentpb.ListCompaniesRequest, opts ...gax.CallOption) *CompanyIterator {
240 return c.internalClient.ListCompanies(ctx, req, opts...)
241 }
242
243 // GetOperation is a utility method from google.longrunning.Operations.
244 func (c *CompanyClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
245 return c.internalClient.GetOperation(ctx, req, opts...)
246 }
247
248 // companyGRPCClient is a client for interacting with Cloud Talent Solution API over gRPC transport.
249 //
250 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
251 type companyGRPCClient struct {
252 // Connection pool of gRPC connections to the service.
253 connPool gtransport.ConnPool
254
255 // Points back to the CallOptions field of the containing CompanyClient
256 CallOptions **CompanyCallOptions
257
258 // The gRPC API client.
259 companyClient talentpb.CompanyServiceClient
260
261 operationsClient longrunningpb.OperationsClient
262
263 // The x-goog-* metadata to be sent with each request.
264 xGoogHeaders []string
265
266 logger *slog.Logger
267 }
268
269 // NewCompanyClient creates a new company service client based on gRPC.
270 // The returned client must be Closed when it is done being used to clean up its underlying connections.
271 //
272 // A service that handles company management, including CRUD and enumeration.
273 func NewCompanyClient(ctx context.Context, opts ...option.ClientOption) (*CompanyClient, error) {
274 clientOpts := defaultCompanyGRPCClientOptions()
275 if newCompanyClientHook != nil {
276 hookOpts, err := newCompanyClientHook(ctx, clientHookParams{})
277 if err != nil {
278 return nil, err
279 }
280 clientOpts = append(clientOpts, hookOpts...)
281 }
282
283 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
284 if err != nil {
285 return nil, err
286 }
287 client := CompanyClient{CallOptions: defaultCompanyCallOptions()}
288
289 c := &companyGRPCClient{
290 connPool: connPool,
291 companyClient: talentpb.NewCompanyServiceClient(connPool),
292 CallOptions: &client.CallOptions,
293 logger: internaloption.GetLogger(opts),
294 operationsClient: longrunningpb.NewOperationsClient(connPool),
295 }
296 c.setGoogleClientInfo()
297
298 client.internalClient = c
299
300 return &client, nil
301 }
302
303 // Connection returns a connection to the API service.
304 //
305 // Deprecated: Connections are now pooled so this method does not always
306 // return the same resource.
307 func (c *companyGRPCClient) Connection() *grpc.ClientConn {
308 return c.connPool.Conn()
309 }
310
311 // setGoogleClientInfo sets the name and version of the application in
312 // the `x-goog-api-client` header passed on each request. Intended for
313 // use by Google-written clients.
314 func (c *companyGRPCClient) setGoogleClientInfo(keyval ...string) {
315 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
316 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
317 c.xGoogHeaders = []string{
318 "x-goog-api-client", gax.XGoogHeader(kv...),
319 }
320 }
321
322 // Close closes the connection to the API service. The user should invoke this when
323 // the client is no longer required.
324 func (c *companyGRPCClient) Close() error {
325 return c.connPool.Close()
326 }
327
328 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
329 type companyRESTClient struct {
330 // The http endpoint to connect to.
331 endpoint string
332
333 // The http client.
334 httpClient *http.Client
335
336 // The x-goog-* headers to be sent with each request.
337 xGoogHeaders []string
338
339 // Points back to the CallOptions field of the containing CompanyClient
340 CallOptions **CompanyCallOptions
341
342 logger *slog.Logger
343 }
344
345 // NewCompanyRESTClient creates a new company service rest client.
346 //
347 // A service that handles company management, including CRUD and enumeration.
348 func NewCompanyRESTClient(ctx context.Context, opts ...option.ClientOption) (*CompanyClient, error) {
349 clientOpts := append(defaultCompanyRESTClientOptions(), opts...)
350 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
351 if err != nil {
352 return nil, err
353 }
354
355 callOpts := defaultCompanyRESTCallOptions()
356 c := &companyRESTClient{
357 endpoint: endpoint,
358 httpClient: httpClient,
359 CallOptions: &callOpts,
360 logger: internaloption.GetLogger(opts),
361 }
362 c.setGoogleClientInfo()
363
364 return &CompanyClient{internalClient: c, CallOptions: callOpts}, nil
365 }
366
367 func defaultCompanyRESTClientOptions() []option.ClientOption {
368 return []option.ClientOption{
369 internaloption.WithDefaultEndpoint("https://jobs.googleapis.com"),
370 internaloption.WithDefaultEndpointTemplate("https://jobs.UNIVERSE_DOMAIN"),
371 internaloption.WithDefaultMTLSEndpoint("https://jobs.mtls.googleapis.com"),
372 internaloption.WithDefaultUniverseDomain("googleapis.com"),
373 internaloption.WithDefaultAudience("https://jobs.googleapis.com/"),
374 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
375 internaloption.EnableNewAuthLibrary(),
376 }
377 }
378
379 // setGoogleClientInfo sets the name and version of the application in
380 // the `x-goog-api-client` header passed on each request. Intended for
381 // use by Google-written clients.
382 func (c *companyRESTClient) setGoogleClientInfo(keyval ...string) {
383 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
384 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
385 c.xGoogHeaders = []string{
386 "x-goog-api-client", gax.XGoogHeader(kv...),
387 }
388 }
389
390 // Close closes the connection to the API service. The user should invoke this when
391 // the client is no longer required.
392 func (c *companyRESTClient) Close() error {
393 // Replace httpClient with nil to force cleanup.
394 c.httpClient = nil
395 return nil
396 }
397
398 // Connection returns a connection to the API service.
399 //
400 // Deprecated: This method always returns nil.
401 func (c *companyRESTClient) Connection() *grpc.ClientConn {
402 return nil
403 }
404 func (c *companyGRPCClient) CreateCompany(ctx context.Context, req *talentpb.CreateCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) {
405 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
406
407 hds = append(c.xGoogHeaders, hds...)
408 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
409 opts = append((*c.CallOptions).CreateCompany[0:len((*c.CallOptions).CreateCompany):len((*c.CallOptions).CreateCompany)], opts...)
410 var resp *talentpb.Company
411 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
412 var err error
413 resp, err = executeRPC(ctx, c.companyClient.CreateCompany, req, settings.GRPC, c.logger, "CreateCompany")
414 return err
415 }, opts...)
416 if err != nil {
417 return nil, err
418 }
419 return resp, nil
420 }
421
422 func (c *companyGRPCClient) GetCompany(ctx context.Context, req *talentpb.GetCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) {
423 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
424
425 hds = append(c.xGoogHeaders, hds...)
426 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
427 opts = append((*c.CallOptions).GetCompany[0:len((*c.CallOptions).GetCompany):len((*c.CallOptions).GetCompany)], opts...)
428 var resp *talentpb.Company
429 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
430 var err error
431 resp, err = executeRPC(ctx, c.companyClient.GetCompany, req, settings.GRPC, c.logger, "GetCompany")
432 return err
433 }, opts...)
434 if err != nil {
435 return nil, err
436 }
437 return resp, nil
438 }
439
440 func (c *companyGRPCClient) UpdateCompany(ctx context.Context, req *talentpb.UpdateCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) {
441 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "company.name", url.QueryEscape(req.GetCompany().GetName()))}
442
443 hds = append(c.xGoogHeaders, hds...)
444 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
445 opts = append((*c.CallOptions).UpdateCompany[0:len((*c.CallOptions).UpdateCompany):len((*c.CallOptions).UpdateCompany)], opts...)
446 var resp *talentpb.Company
447 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
448 var err error
449 resp, err = executeRPC(ctx, c.companyClient.UpdateCompany, req, settings.GRPC, c.logger, "UpdateCompany")
450 return err
451 }, opts...)
452 if err != nil {
453 return nil, err
454 }
455 return resp, nil
456 }
457
458 func (c *companyGRPCClient) DeleteCompany(ctx context.Context, req *talentpb.DeleteCompanyRequest, opts ...gax.CallOption) error {
459 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
460
461 hds = append(c.xGoogHeaders, hds...)
462 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
463 opts = append((*c.CallOptions).DeleteCompany[0:len((*c.CallOptions).DeleteCompany):len((*c.CallOptions).DeleteCompany)], opts...)
464 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
465 var err error
466 _, err = executeRPC(ctx, c.companyClient.DeleteCompany, req, settings.GRPC, c.logger, "DeleteCompany")
467 return err
468 }, opts...)
469 return err
470 }
471
472 func (c *companyGRPCClient) ListCompanies(ctx context.Context, req *talentpb.ListCompaniesRequest, opts ...gax.CallOption) *CompanyIterator {
473 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
474
475 hds = append(c.xGoogHeaders, hds...)
476 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
477 opts = append((*c.CallOptions).ListCompanies[0:len((*c.CallOptions).ListCompanies):len((*c.CallOptions).ListCompanies)], opts...)
478 it := &CompanyIterator{}
479 req = proto.Clone(req).(*talentpb.ListCompaniesRequest)
480 it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.Company, string, error) {
481 resp := &talentpb.ListCompaniesResponse{}
482 if pageToken != "" {
483 req.PageToken = pageToken
484 }
485 if pageSize > math.MaxInt32 {
486 req.PageSize = math.MaxInt32
487 } else if pageSize != 0 {
488 req.PageSize = int32(pageSize)
489 }
490 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
491 var err error
492 resp, err = executeRPC(ctx, c.companyClient.ListCompanies, req, settings.GRPC, c.logger, "ListCompanies")
493 return err
494 }, opts...)
495 if err != nil {
496 return nil, "", err
497 }
498
499 it.Response = resp
500 return resp.GetCompanies(), resp.GetNextPageToken(), nil
501 }
502 fetch := func(pageSize int, pageToken string) (string, error) {
503 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
504 if err != nil {
505 return "", err
506 }
507 it.items = append(it.items, items...)
508 return nextPageToken, nil
509 }
510
511 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
512 it.pageInfo.MaxSize = int(req.GetPageSize())
513 it.pageInfo.Token = req.GetPageToken()
514
515 return it
516 }
517
518 func (c *companyGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
519 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
520
521 hds = append(c.xGoogHeaders, hds...)
522 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
523 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
524 var resp *longrunningpb.Operation
525 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
526 var err error
527 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
528 return err
529 }, opts...)
530 if err != nil {
531 return nil, err
532 }
533 return resp, nil
534 }
535
536 // CreateCompany creates a new company entity.
537 func (c *companyRESTClient) CreateCompany(ctx context.Context, req *talentpb.CreateCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) {
538 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
539 body := req.GetCompany()
540 jsonReq, err := m.Marshal(body)
541 if err != nil {
542 return nil, err
543 }
544
545 baseUrl, err := url.Parse(c.endpoint)
546 if err != nil {
547 return nil, err
548 }
549 baseUrl.Path += fmt.Sprintf("/v4/%v/companies", req.GetParent())
550
551 params := url.Values{}
552 params.Add("$alt", "json;enum-encoding=int")
553
554 baseUrl.RawQuery = params.Encode()
555
556 // Build HTTP headers from client and context metadata.
557 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
558
559 hds = append(c.xGoogHeaders, hds...)
560 hds = append(hds, "Content-Type", "application/json")
561 headers := gax.BuildHeaders(ctx, hds...)
562 opts = append((*c.CallOptions).CreateCompany[0:len((*c.CallOptions).CreateCompany):len((*c.CallOptions).CreateCompany)], opts...)
563 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
564 resp := &talentpb.Company{}
565 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
566 if settings.Path != "" {
567 baseUrl.Path = settings.Path
568 }
569 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
570 if err != nil {
571 return err
572 }
573 httpReq = httpReq.WithContext(ctx)
574 httpReq.Header = headers
575
576 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateCompany")
577 if err != nil {
578 return err
579 }
580
581 if err := unm.Unmarshal(buf, resp); err != nil {
582 return err
583 }
584
585 return nil
586 }, opts...)
587 if e != nil {
588 return nil, e
589 }
590 return resp, nil
591 }
592
593 // GetCompany retrieves specified company.
594 func (c *companyRESTClient) GetCompany(ctx context.Context, req *talentpb.GetCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) {
595 baseUrl, err := url.Parse(c.endpoint)
596 if err != nil {
597 return nil, err
598 }
599 baseUrl.Path += fmt.Sprintf("/v4/%v", req.GetName())
600
601 params := url.Values{}
602 params.Add("$alt", "json;enum-encoding=int")
603
604 baseUrl.RawQuery = params.Encode()
605
606 // Build HTTP headers from client and context metadata.
607 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
608
609 hds = append(c.xGoogHeaders, hds...)
610 hds = append(hds, "Content-Type", "application/json")
611 headers := gax.BuildHeaders(ctx, hds...)
612 opts = append((*c.CallOptions).GetCompany[0:len((*c.CallOptions).GetCompany):len((*c.CallOptions).GetCompany)], opts...)
613 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
614 resp := &talentpb.Company{}
615 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
616 if settings.Path != "" {
617 baseUrl.Path = settings.Path
618 }
619 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
620 if err != nil {
621 return err
622 }
623 httpReq = httpReq.WithContext(ctx)
624 httpReq.Header = headers
625
626 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetCompany")
627 if err != nil {
628 return err
629 }
630
631 if err := unm.Unmarshal(buf, resp); err != nil {
632 return err
633 }
634
635 return nil
636 }, opts...)
637 if e != nil {
638 return nil, e
639 }
640 return resp, nil
641 }
642
643 // UpdateCompany updates specified company.
644 func (c *companyRESTClient) UpdateCompany(ctx context.Context, req *talentpb.UpdateCompanyRequest, opts ...gax.CallOption) (*talentpb.Company, error) {
645 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
646 body := req.GetCompany()
647 jsonReq, err := m.Marshal(body)
648 if err != nil {
649 return nil, err
650 }
651
652 baseUrl, err := url.Parse(c.endpoint)
653 if err != nil {
654 return nil, err
655 }
656 baseUrl.Path += fmt.Sprintf("/v4/%v", req.GetCompany().GetName())
657
658 params := url.Values{}
659 params.Add("$alt", "json;enum-encoding=int")
660 if req.GetUpdateMask() != nil {
661 field, err := protojson.Marshal(req.GetUpdateMask())
662 if err != nil {
663 return nil, err
664 }
665 params.Add("updateMask", string(field[1:len(field)-1]))
666 }
667
668 baseUrl.RawQuery = params.Encode()
669
670 // Build HTTP headers from client and context metadata.
671 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "company.name", url.QueryEscape(req.GetCompany().GetName()))}
672
673 hds = append(c.xGoogHeaders, hds...)
674 hds = append(hds, "Content-Type", "application/json")
675 headers := gax.BuildHeaders(ctx, hds...)
676 opts = append((*c.CallOptions).UpdateCompany[0:len((*c.CallOptions).UpdateCompany):len((*c.CallOptions).UpdateCompany)], opts...)
677 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
678 resp := &talentpb.Company{}
679 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
680 if settings.Path != "" {
681 baseUrl.Path = settings.Path
682 }
683 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
684 if err != nil {
685 return err
686 }
687 httpReq = httpReq.WithContext(ctx)
688 httpReq.Header = headers
689
690 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateCompany")
691 if err != nil {
692 return err
693 }
694
695 if err := unm.Unmarshal(buf, resp); err != nil {
696 return err
697 }
698
699 return nil
700 }, opts...)
701 if e != nil {
702 return nil, e
703 }
704 return resp, nil
705 }
706
707 // DeleteCompany deletes specified company.
708 // Prerequisite: The company has no jobs associated with it.
709 func (c *companyRESTClient) DeleteCompany(ctx context.Context, req *talentpb.DeleteCompanyRequest, opts ...gax.CallOption) error {
710 baseUrl, err := url.Parse(c.endpoint)
711 if err != nil {
712 return err
713 }
714 baseUrl.Path += fmt.Sprintf("/v4/%v", req.GetName())
715
716 params := url.Values{}
717 params.Add("$alt", "json;enum-encoding=int")
718
719 baseUrl.RawQuery = params.Encode()
720
721 // Build HTTP headers from client and context metadata.
722 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
723
724 hds = append(c.xGoogHeaders, hds...)
725 hds = append(hds, "Content-Type", "application/json")
726 headers := gax.BuildHeaders(ctx, hds...)
727 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
728 if settings.Path != "" {
729 baseUrl.Path = settings.Path
730 }
731 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
732 if err != nil {
733 return err
734 }
735 httpReq = httpReq.WithContext(ctx)
736 httpReq.Header = headers
737
738 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteCompany")
739 return err
740 }, opts...)
741 }
742
743 // ListCompanies lists all companies associated with the project.
744 func (c *companyRESTClient) ListCompanies(ctx context.Context, req *talentpb.ListCompaniesRequest, opts ...gax.CallOption) *CompanyIterator {
745 it := &CompanyIterator{}
746 req = proto.Clone(req).(*talentpb.ListCompaniesRequest)
747 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
748 it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.Company, string, error) {
749 resp := &talentpb.ListCompaniesResponse{}
750 if pageToken != "" {
751 req.PageToken = pageToken
752 }
753 if pageSize > math.MaxInt32 {
754 req.PageSize = math.MaxInt32
755 } else if pageSize != 0 {
756 req.PageSize = int32(pageSize)
757 }
758 baseUrl, err := url.Parse(c.endpoint)
759 if err != nil {
760 return nil, "", err
761 }
762 baseUrl.Path += fmt.Sprintf("/v4/%v/companies", req.GetParent())
763
764 params := url.Values{}
765 params.Add("$alt", "json;enum-encoding=int")
766 if req.GetPageSize() != 0 {
767 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
768 }
769 if req.GetPageToken() != "" {
770 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
771 }
772 if req.GetRequireOpenJobs() {
773 params.Add("requireOpenJobs", fmt.Sprintf("%v", req.GetRequireOpenJobs()))
774 }
775
776 baseUrl.RawQuery = params.Encode()
777
778 // Build HTTP headers from client and context metadata.
779 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
780 headers := gax.BuildHeaders(ctx, hds...)
781 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
782 if settings.Path != "" {
783 baseUrl.Path = settings.Path
784 }
785 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
786 if err != nil {
787 return err
788 }
789 httpReq.Header = headers
790
791 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListCompanies")
792 if err != nil {
793 return err
794 }
795 if err := unm.Unmarshal(buf, resp); err != nil {
796 return err
797 }
798
799 return nil
800 }, opts...)
801 if e != nil {
802 return nil, "", e
803 }
804 it.Response = resp
805 return resp.GetCompanies(), resp.GetNextPageToken(), nil
806 }
807
808 fetch := func(pageSize int, pageToken string) (string, error) {
809 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
810 if err != nil {
811 return "", err
812 }
813 it.items = append(it.items, items...)
814 return nextPageToken, nil
815 }
816
817 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
818 it.pageInfo.MaxSize = int(req.GetPageSize())
819 it.pageInfo.Token = req.GetPageToken()
820
821 return it
822 }
823
824 // GetOperation is a utility method from google.longrunning.Operations.
825 func (c *companyRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
826 baseUrl, err := url.Parse(c.endpoint)
827 if err != nil {
828 return nil, err
829 }
830 baseUrl.Path += fmt.Sprintf("/v4/%v", req.GetName())
831
832 params := url.Values{}
833 params.Add("$alt", "json;enum-encoding=int")
834
835 baseUrl.RawQuery = params.Encode()
836
837 // Build HTTP headers from client and context metadata.
838 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
839
840 hds = append(c.xGoogHeaders, hds...)
841 hds = append(hds, "Content-Type", "application/json")
842 headers := gax.BuildHeaders(ctx, hds...)
843 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
844 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
845 resp := &longrunningpb.Operation{}
846 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
847 if settings.Path != "" {
848 baseUrl.Path = settings.Path
849 }
850 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
851 if err != nil {
852 return err
853 }
854 httpReq = httpReq.WithContext(ctx)
855 httpReq.Header = headers
856
857 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
858 if err != nil {
859 return err
860 }
861
862 if err := unm.Unmarshal(buf, resp); err != nil {
863 return err
864 }
865
866 return nil
867 }, opts...)
868 if e != nil {
869 return nil, e
870 }
871 return resp, nil
872 }