You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

357 lines
12 KiB

  1. // Copyright 2019 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. // Code generated by gapic-generator. DO NOT EDIT.
  15. package talent
  16. import (
  17. "context"
  18. "math"
  19. "time"
  20. "github.com/golang/protobuf/proto"
  21. gax "github.com/googleapis/gax-go/v2"
  22. "google.golang.org/api/iterator"
  23. "google.golang.org/api/option"
  24. "google.golang.org/api/transport"
  25. talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4beta1"
  26. "google.golang.org/grpc"
  27. "google.golang.org/grpc/codes"
  28. "google.golang.org/grpc/metadata"
  29. )
  30. // ProfileCallOptions contains the retry settings for each method of ProfileClient.
  31. type ProfileCallOptions struct {
  32. ListProfiles []gax.CallOption
  33. CreateProfile []gax.CallOption
  34. GetProfile []gax.CallOption
  35. UpdateProfile []gax.CallOption
  36. DeleteProfile []gax.CallOption
  37. SearchProfiles []gax.CallOption
  38. }
  39. func defaultProfileClientOptions() []option.ClientOption {
  40. return []option.ClientOption{
  41. option.WithEndpoint("jobs.googleapis.com:443"),
  42. option.WithScopes(DefaultAuthScopes()...),
  43. }
  44. }
  45. func defaultProfileCallOptions() *ProfileCallOptions {
  46. retry := map[[2]string][]gax.CallOption{
  47. {"default", "idempotent"}: {
  48. gax.WithRetry(func() gax.Retryer {
  49. return gax.OnCodes([]codes.Code{
  50. codes.DeadlineExceeded,
  51. codes.Unavailable,
  52. }, gax.Backoff{
  53. Initial: 100 * time.Millisecond,
  54. Max: 60000 * time.Millisecond,
  55. Multiplier: 1.3,
  56. })
  57. }),
  58. },
  59. }
  60. return &ProfileCallOptions{
  61. ListProfiles: retry[[2]string{"default", "idempotent"}],
  62. CreateProfile: retry[[2]string{"default", "non_idempotent"}],
  63. GetProfile: retry[[2]string{"default", "idempotent"}],
  64. UpdateProfile: retry[[2]string{"default", "non_idempotent"}],
  65. DeleteProfile: retry[[2]string{"default", "idempotent"}],
  66. SearchProfiles: retry[[2]string{"default", "non_idempotent"}],
  67. }
  68. }
  69. // ProfileClient is a client for interacting with Cloud Talent Solution API.
  70. //
  71. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  72. type ProfileClient struct {
  73. // The connection to the service.
  74. conn *grpc.ClientConn
  75. // The gRPC API client.
  76. profileClient talentpb.ProfileServiceClient
  77. // The call options for this service.
  78. CallOptions *ProfileCallOptions
  79. // The x-goog-* metadata to be sent with each request.
  80. xGoogMetadata metadata.MD
  81. }
  82. // NewProfileClient creates a new profile service client.
  83. //
  84. // A service that handles profile management, including profile CRUD,
  85. // enumeration and search.
  86. func NewProfileClient(ctx context.Context, opts ...option.ClientOption) (*ProfileClient, error) {
  87. conn, err := transport.DialGRPC(ctx, append(defaultProfileClientOptions(), opts...)...)
  88. if err != nil {
  89. return nil, err
  90. }
  91. c := &ProfileClient{
  92. conn: conn,
  93. CallOptions: defaultProfileCallOptions(),
  94. profileClient: talentpb.NewProfileServiceClient(conn),
  95. }
  96. c.setGoogleClientInfo()
  97. return c, nil
  98. }
  99. // Connection returns the client's connection to the API service.
  100. func (c *ProfileClient) Connection() *grpc.ClientConn {
  101. return c.conn
  102. }
  103. // Close closes the connection to the API service. The user should invoke this when
  104. // the client is no longer required.
  105. func (c *ProfileClient) Close() error {
  106. return c.conn.Close()
  107. }
  108. // setGoogleClientInfo sets the name and version of the application in
  109. // the `x-goog-api-client` header passed on each request. Intended for
  110. // use by Google-written clients.
  111. func (c *ProfileClient) setGoogleClientInfo(keyval ...string) {
  112. kv := append([]string{"gl-go", versionGo()}, keyval...)
  113. kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
  114. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  115. }
  116. // ListProfiles lists profiles by filter. The order is unspecified.
  117. func (c *ProfileClient) ListProfiles(ctx context.Context, req *talentpb.ListProfilesRequest, opts ...gax.CallOption) *ProfileIterator {
  118. ctx = insertMetadata(ctx, c.xGoogMetadata)
  119. opts = append(c.CallOptions.ListProfiles[0:len(c.CallOptions.ListProfiles):len(c.CallOptions.ListProfiles)], opts...)
  120. it := &ProfileIterator{}
  121. req = proto.Clone(req).(*talentpb.ListProfilesRequest)
  122. it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.Profile, string, error) {
  123. var resp *talentpb.ListProfilesResponse
  124. req.PageToken = pageToken
  125. if pageSize > math.MaxInt32 {
  126. req.PageSize = math.MaxInt32
  127. } else {
  128. req.PageSize = int32(pageSize)
  129. }
  130. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  131. var err error
  132. resp, err = c.profileClient.ListProfiles(ctx, req, settings.GRPC...)
  133. return err
  134. }, opts...)
  135. if err != nil {
  136. return nil, "", err
  137. }
  138. return resp.Profiles, resp.NextPageToken, nil
  139. }
  140. fetch := func(pageSize int, pageToken string) (string, error) {
  141. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  142. if err != nil {
  143. return "", err
  144. }
  145. it.items = append(it.items, items...)
  146. return nextPageToken, nil
  147. }
  148. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  149. it.pageInfo.MaxSize = int(req.PageSize)
  150. return it
  151. }
  152. // CreateProfile creates and returns a new profile.
  153. func (c *ProfileClient) CreateProfile(ctx context.Context, req *talentpb.CreateProfileRequest, opts ...gax.CallOption) (*talentpb.Profile, error) {
  154. ctx = insertMetadata(ctx, c.xGoogMetadata)
  155. opts = append(c.CallOptions.CreateProfile[0:len(c.CallOptions.CreateProfile):len(c.CallOptions.CreateProfile)], opts...)
  156. var resp *talentpb.Profile
  157. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  158. var err error
  159. resp, err = c.profileClient.CreateProfile(ctx, req, settings.GRPC...)
  160. return err
  161. }, opts...)
  162. if err != nil {
  163. return nil, err
  164. }
  165. return resp, nil
  166. }
  167. // GetProfile gets the specified profile.
  168. func (c *ProfileClient) GetProfile(ctx context.Context, req *talentpb.GetProfileRequest, opts ...gax.CallOption) (*talentpb.Profile, error) {
  169. ctx = insertMetadata(ctx, c.xGoogMetadata)
  170. opts = append(c.CallOptions.GetProfile[0:len(c.CallOptions.GetProfile):len(c.CallOptions.GetProfile)], opts...)
  171. var resp *talentpb.Profile
  172. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  173. var err error
  174. resp, err = c.profileClient.GetProfile(ctx, req, settings.GRPC...)
  175. return err
  176. }, opts...)
  177. if err != nil {
  178. return nil, err
  179. }
  180. return resp, nil
  181. }
  182. // UpdateProfile updates the specified profile and returns the updated result.
  183. func (c *ProfileClient) UpdateProfile(ctx context.Context, req *talentpb.UpdateProfileRequest, opts ...gax.CallOption) (*talentpb.Profile, error) {
  184. ctx = insertMetadata(ctx, c.xGoogMetadata)
  185. opts = append(c.CallOptions.UpdateProfile[0:len(c.CallOptions.UpdateProfile):len(c.CallOptions.UpdateProfile)], opts...)
  186. var resp *talentpb.Profile
  187. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  188. var err error
  189. resp, err = c.profileClient.UpdateProfile(ctx, req, settings.GRPC...)
  190. return err
  191. }, opts...)
  192. if err != nil {
  193. return nil, err
  194. }
  195. return resp, nil
  196. }
  197. // DeleteProfile deletes the specified profile.
  198. func (c *ProfileClient) DeleteProfile(ctx context.Context, req *talentpb.DeleteProfileRequest, opts ...gax.CallOption) error {
  199. ctx = insertMetadata(ctx, c.xGoogMetadata)
  200. opts = append(c.CallOptions.DeleteProfile[0:len(c.CallOptions.DeleteProfile):len(c.CallOptions.DeleteProfile)], opts...)
  201. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  202. var err error
  203. _, err = c.profileClient.DeleteProfile(ctx, req, settings.GRPC...)
  204. return err
  205. }, opts...)
  206. return err
  207. }
  208. // SearchProfiles searches for profiles within a tenant.
  209. //
  210. // For example, search by raw queries "software engineer in Mountain View" or
  211. // search by structured filters (location filter, education filter, etc.).
  212. //
  213. // See
  214. // [SearchProfilesRequest][google.cloud.talent.v4beta1.SearchProfilesRequest]
  215. // for more information.
  216. func (c *ProfileClient) SearchProfiles(ctx context.Context, req *talentpb.SearchProfilesRequest, opts ...gax.CallOption) *HistogramQueryResultIterator {
  217. ctx = insertMetadata(ctx, c.xGoogMetadata)
  218. opts = append(c.CallOptions.SearchProfiles[0:len(c.CallOptions.SearchProfiles):len(c.CallOptions.SearchProfiles)], opts...)
  219. it := &HistogramQueryResultIterator{}
  220. req = proto.Clone(req).(*talentpb.SearchProfilesRequest)
  221. it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.HistogramQueryResult, string, error) {
  222. var resp *talentpb.SearchProfilesResponse
  223. req.PageToken = pageToken
  224. if pageSize > math.MaxInt32 {
  225. req.PageSize = math.MaxInt32
  226. } else {
  227. req.PageSize = int32(pageSize)
  228. }
  229. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  230. var err error
  231. resp, err = c.profileClient.SearchProfiles(ctx, req, settings.GRPC...)
  232. return err
  233. }, opts...)
  234. if err != nil {
  235. return nil, "", err
  236. }
  237. return resp.HistogramQueryResults, resp.NextPageToken, nil
  238. }
  239. fetch := func(pageSize int, pageToken string) (string, error) {
  240. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  241. if err != nil {
  242. return "", err
  243. }
  244. it.items = append(it.items, items...)
  245. return nextPageToken, nil
  246. }
  247. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  248. it.pageInfo.MaxSize = int(req.PageSize)
  249. return it
  250. }
  251. // HistogramQueryResultIterator manages a stream of *talentpb.HistogramQueryResult.
  252. type HistogramQueryResultIterator struct {
  253. items []*talentpb.HistogramQueryResult
  254. pageInfo *iterator.PageInfo
  255. nextFunc func() error
  256. // InternalFetch is for use by the Google Cloud Libraries only.
  257. // It is not part of the stable interface of this package.
  258. //
  259. // InternalFetch returns results from a single call to the underlying RPC.
  260. // The number of results is no greater than pageSize.
  261. // If there are no more results, nextPageToken is empty and err is nil.
  262. InternalFetch func(pageSize int, pageToken string) (results []*talentpb.HistogramQueryResult, nextPageToken string, err error)
  263. }
  264. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  265. func (it *HistogramQueryResultIterator) PageInfo() *iterator.PageInfo {
  266. return it.pageInfo
  267. }
  268. // Next returns the next result. Its second return value is iterator.Done if there are no more
  269. // results. Once Next returns Done, all subsequent calls will return Done.
  270. func (it *HistogramQueryResultIterator) Next() (*talentpb.HistogramQueryResult, error) {
  271. var item *talentpb.HistogramQueryResult
  272. if err := it.nextFunc(); err != nil {
  273. return item, err
  274. }
  275. item = it.items[0]
  276. it.items = it.items[1:]
  277. return item, nil
  278. }
  279. func (it *HistogramQueryResultIterator) bufLen() int {
  280. return len(it.items)
  281. }
  282. func (it *HistogramQueryResultIterator) takeBuf() interface{} {
  283. b := it.items
  284. it.items = nil
  285. return b
  286. }
  287. // ProfileIterator manages a stream of *talentpb.Profile.
  288. type ProfileIterator struct {
  289. items []*talentpb.Profile
  290. pageInfo *iterator.PageInfo
  291. nextFunc func() error
  292. // InternalFetch is for use by the Google Cloud Libraries only.
  293. // It is not part of the stable interface of this package.
  294. //
  295. // InternalFetch returns results from a single call to the underlying RPC.
  296. // The number of results is no greater than pageSize.
  297. // If there are no more results, nextPageToken is empty and err is nil.
  298. InternalFetch func(pageSize int, pageToken string) (results []*talentpb.Profile, nextPageToken string, err error)
  299. }
  300. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  301. func (it *ProfileIterator) PageInfo() *iterator.PageInfo {
  302. return it.pageInfo
  303. }
  304. // Next returns the next result. Its second return value is iterator.Done if there are no more
  305. // results. Once Next returns Done, all subsequent calls will return Done.
  306. func (it *ProfileIterator) Next() (*talentpb.Profile, error) {
  307. var item *talentpb.Profile
  308. if err := it.nextFunc(); err != nil {
  309. return item, err
  310. }
  311. item = it.items[0]
  312. it.items = it.items[1:]
  313. return item, nil
  314. }
  315. func (it *ProfileIterator) bufLen() int {
  316. return len(it.items)
  317. }
  318. func (it *ProfileIterator) takeBuf() interface{} {
  319. b := it.items
  320. it.items = nil
  321. return b
  322. }