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.
 
 
 

725 lines
30 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 dialogflow
  16. import (
  17. "context"
  18. "math"
  19. "time"
  20. "cloud.google.com/go/longrunning"
  21. lroauto "cloud.google.com/go/longrunning/autogen"
  22. "github.com/golang/protobuf/proto"
  23. structpbpb "github.com/golang/protobuf/ptypes/struct"
  24. gax "github.com/googleapis/gax-go/v2"
  25. "google.golang.org/api/iterator"
  26. "google.golang.org/api/option"
  27. "google.golang.org/api/transport"
  28. dialogflowpb "google.golang.org/genproto/googleapis/cloud/dialogflow/v2"
  29. longrunningpb "google.golang.org/genproto/googleapis/longrunning"
  30. "google.golang.org/grpc"
  31. "google.golang.org/grpc/codes"
  32. "google.golang.org/grpc/metadata"
  33. )
  34. // EntityTypesCallOptions contains the retry settings for each method of EntityTypesClient.
  35. type EntityTypesCallOptions struct {
  36. ListEntityTypes []gax.CallOption
  37. GetEntityType []gax.CallOption
  38. CreateEntityType []gax.CallOption
  39. UpdateEntityType []gax.CallOption
  40. DeleteEntityType []gax.CallOption
  41. BatchUpdateEntityTypes []gax.CallOption
  42. BatchDeleteEntityTypes []gax.CallOption
  43. BatchCreateEntities []gax.CallOption
  44. BatchUpdateEntities []gax.CallOption
  45. BatchDeleteEntities []gax.CallOption
  46. }
  47. func defaultEntityTypesClientOptions() []option.ClientOption {
  48. return []option.ClientOption{
  49. option.WithEndpoint("dialogflow.googleapis.com:443"),
  50. option.WithScopes(DefaultAuthScopes()...),
  51. }
  52. }
  53. func defaultEntityTypesCallOptions() *EntityTypesCallOptions {
  54. retry := map[[2]string][]gax.CallOption{
  55. {"default", "idempotent"}: {
  56. gax.WithRetry(func() gax.Retryer {
  57. return gax.OnCodes([]codes.Code{
  58. codes.DeadlineExceeded,
  59. codes.Unavailable,
  60. }, gax.Backoff{
  61. Initial: 100 * time.Millisecond,
  62. Max: 60000 * time.Millisecond,
  63. Multiplier: 1.3,
  64. })
  65. }),
  66. },
  67. }
  68. return &EntityTypesCallOptions{
  69. ListEntityTypes: retry[[2]string{"default", "idempotent"}],
  70. GetEntityType: retry[[2]string{"default", "idempotent"}],
  71. CreateEntityType: retry[[2]string{"default", "non_idempotent"}],
  72. UpdateEntityType: retry[[2]string{"default", "non_idempotent"}],
  73. DeleteEntityType: retry[[2]string{"default", "idempotent"}],
  74. BatchUpdateEntityTypes: retry[[2]string{"default", "non_idempotent"}],
  75. BatchDeleteEntityTypes: retry[[2]string{"default", "idempotent"}],
  76. BatchCreateEntities: retry[[2]string{"default", "non_idempotent"}],
  77. BatchUpdateEntities: retry[[2]string{"default", "non_idempotent"}],
  78. BatchDeleteEntities: retry[[2]string{"default", "idempotent"}],
  79. }
  80. }
  81. // EntityTypesClient is a client for interacting with Dialogflow API.
  82. //
  83. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  84. type EntityTypesClient struct {
  85. // The connection to the service.
  86. conn *grpc.ClientConn
  87. // The gRPC API client.
  88. entityTypesClient dialogflowpb.EntityTypesClient
  89. // LROClient is used internally to handle longrunning operations.
  90. // It is exposed so that its CallOptions can be modified if required.
  91. // Users should not Close this client.
  92. LROClient *lroauto.OperationsClient
  93. // The call options for this service.
  94. CallOptions *EntityTypesCallOptions
  95. // The x-goog-* metadata to be sent with each request.
  96. xGoogMetadata metadata.MD
  97. }
  98. // NewEntityTypesClient creates a new entity types client.
  99. //
  100. // Entities are extracted from user input and represent parameters that are
  101. // meaningful to your application. For example, a date range, a proper name
  102. // such as a geographic location or landmark, and so on. Entities represent
  103. // actionable data for your application.
  104. //
  105. // When you define an entity, you can also include synonyms that all map to
  106. // that entity. For example, "soft drink", "soda", "pop", and so on.
  107. //
  108. // There are three types of entities:
  109. //
  110. // * **System** - entities that are defined by the Dialogflow API for common
  111. // data types such as date, time, currency, and so on. A system entity is
  112. // represented by the `EntityType` type.
  113. //
  114. // * **Developer** - entities that are defined by you that represent
  115. // actionable data that is meaningful to your application. For example,
  116. // you could define a `pizza.sauce` entity for red or white pizza sauce,
  117. // a `pizza.cheese` entity for the different types of cheese on a pizza,
  118. // a `pizza.topping` entity for different toppings, and so on. A developer
  119. // entity is represented by the `EntityType` type.
  120. //
  121. // * **User** - entities that are built for an individual user such as
  122. // favorites, preferences, playlists, and so on. A user entity is
  123. // represented by the
  124. // [SessionEntityType][google.cloud.dialogflow.v2.SessionEntityType] type.
  125. //
  126. // For more information about entity types, see the
  127. // [Dialogflow documentation](https://dialogflow.com/docs/entities).
  128. func NewEntityTypesClient(ctx context.Context, opts ...option.ClientOption) (*EntityTypesClient, error) {
  129. conn, err := transport.DialGRPC(ctx, append(defaultEntityTypesClientOptions(), opts...)...)
  130. if err != nil {
  131. return nil, err
  132. }
  133. c := &EntityTypesClient{
  134. conn: conn,
  135. CallOptions: defaultEntityTypesCallOptions(),
  136. entityTypesClient: dialogflowpb.NewEntityTypesClient(conn),
  137. }
  138. c.setGoogleClientInfo()
  139. c.LROClient, err = lroauto.NewOperationsClient(ctx, option.WithGRPCConn(conn))
  140. if err != nil {
  141. // This error "should not happen", since we are just reusing old connection
  142. // and never actually need to dial.
  143. // If this does happen, we could leak conn. However, we cannot close conn:
  144. // If the user invoked the function with option.WithGRPCConn,
  145. // we would close a connection that's still in use.
  146. // TODO(pongad): investigate error conditions.
  147. return nil, err
  148. }
  149. return c, nil
  150. }
  151. // Connection returns the client's connection to the API service.
  152. func (c *EntityTypesClient) Connection() *grpc.ClientConn {
  153. return c.conn
  154. }
  155. // Close closes the connection to the API service. The user should invoke this when
  156. // the client is no longer required.
  157. func (c *EntityTypesClient) Close() error {
  158. return c.conn.Close()
  159. }
  160. // setGoogleClientInfo sets the name and version of the application in
  161. // the `x-goog-api-client` header passed on each request. Intended for
  162. // use by Google-written clients.
  163. func (c *EntityTypesClient) setGoogleClientInfo(keyval ...string) {
  164. kv := append([]string{"gl-go", versionGo()}, keyval...)
  165. kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
  166. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  167. }
  168. // ListEntityTypes returns the list of all entity types in the specified agent.
  169. func (c *EntityTypesClient) ListEntityTypes(ctx context.Context, req *dialogflowpb.ListEntityTypesRequest, opts ...gax.CallOption) *EntityTypeIterator {
  170. ctx = insertMetadata(ctx, c.xGoogMetadata)
  171. opts = append(c.CallOptions.ListEntityTypes[0:len(c.CallOptions.ListEntityTypes):len(c.CallOptions.ListEntityTypes)], opts...)
  172. it := &EntityTypeIterator{}
  173. req = proto.Clone(req).(*dialogflowpb.ListEntityTypesRequest)
  174. it.InternalFetch = func(pageSize int, pageToken string) ([]*dialogflowpb.EntityType, string, error) {
  175. var resp *dialogflowpb.ListEntityTypesResponse
  176. req.PageToken = pageToken
  177. if pageSize > math.MaxInt32 {
  178. req.PageSize = math.MaxInt32
  179. } else {
  180. req.PageSize = int32(pageSize)
  181. }
  182. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  183. var err error
  184. resp, err = c.entityTypesClient.ListEntityTypes(ctx, req, settings.GRPC...)
  185. return err
  186. }, opts...)
  187. if err != nil {
  188. return nil, "", err
  189. }
  190. return resp.EntityTypes, resp.NextPageToken, nil
  191. }
  192. fetch := func(pageSize int, pageToken string) (string, error) {
  193. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  194. if err != nil {
  195. return "", err
  196. }
  197. it.items = append(it.items, items...)
  198. return nextPageToken, nil
  199. }
  200. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  201. it.pageInfo.MaxSize = int(req.PageSize)
  202. return it
  203. }
  204. // GetEntityType retrieves the specified entity type.
  205. func (c *EntityTypesClient) GetEntityType(ctx context.Context, req *dialogflowpb.GetEntityTypeRequest, opts ...gax.CallOption) (*dialogflowpb.EntityType, error) {
  206. ctx = insertMetadata(ctx, c.xGoogMetadata)
  207. opts = append(c.CallOptions.GetEntityType[0:len(c.CallOptions.GetEntityType):len(c.CallOptions.GetEntityType)], opts...)
  208. var resp *dialogflowpb.EntityType
  209. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  210. var err error
  211. resp, err = c.entityTypesClient.GetEntityType(ctx, req, settings.GRPC...)
  212. return err
  213. }, opts...)
  214. if err != nil {
  215. return nil, err
  216. }
  217. return resp, nil
  218. }
  219. // CreateEntityType creates an entity type in the specified agent.
  220. func (c *EntityTypesClient) CreateEntityType(ctx context.Context, req *dialogflowpb.CreateEntityTypeRequest, opts ...gax.CallOption) (*dialogflowpb.EntityType, error) {
  221. ctx = insertMetadata(ctx, c.xGoogMetadata)
  222. opts = append(c.CallOptions.CreateEntityType[0:len(c.CallOptions.CreateEntityType):len(c.CallOptions.CreateEntityType)], opts...)
  223. var resp *dialogflowpb.EntityType
  224. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  225. var err error
  226. resp, err = c.entityTypesClient.CreateEntityType(ctx, req, settings.GRPC...)
  227. return err
  228. }, opts...)
  229. if err != nil {
  230. return nil, err
  231. }
  232. return resp, nil
  233. }
  234. // UpdateEntityType updates the specified entity type.
  235. func (c *EntityTypesClient) UpdateEntityType(ctx context.Context, req *dialogflowpb.UpdateEntityTypeRequest, opts ...gax.CallOption) (*dialogflowpb.EntityType, error) {
  236. ctx = insertMetadata(ctx, c.xGoogMetadata)
  237. opts = append(c.CallOptions.UpdateEntityType[0:len(c.CallOptions.UpdateEntityType):len(c.CallOptions.UpdateEntityType)], opts...)
  238. var resp *dialogflowpb.EntityType
  239. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  240. var err error
  241. resp, err = c.entityTypesClient.UpdateEntityType(ctx, req, settings.GRPC...)
  242. return err
  243. }, opts...)
  244. if err != nil {
  245. return nil, err
  246. }
  247. return resp, nil
  248. }
  249. // DeleteEntityType deletes the specified entity type.
  250. func (c *EntityTypesClient) DeleteEntityType(ctx context.Context, req *dialogflowpb.DeleteEntityTypeRequest, opts ...gax.CallOption) error {
  251. ctx = insertMetadata(ctx, c.xGoogMetadata)
  252. opts = append(c.CallOptions.DeleteEntityType[0:len(c.CallOptions.DeleteEntityType):len(c.CallOptions.DeleteEntityType)], opts...)
  253. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  254. var err error
  255. _, err = c.entityTypesClient.DeleteEntityType(ctx, req, settings.GRPC...)
  256. return err
  257. }, opts...)
  258. return err
  259. }
  260. // BatchUpdateEntityTypes updates/Creates multiple entity types in the specified agent.
  261. //
  262. // Operation <response:
  263. // [BatchUpdateEntityTypesResponse][google.cloud.dialogflow.v2.BatchUpdateEntityTypesResponse],
  264. // metadata: [google.protobuf.Struct][google.protobuf.Struct]>
  265. func (c *EntityTypesClient) BatchUpdateEntityTypes(ctx context.Context, req *dialogflowpb.BatchUpdateEntityTypesRequest, opts ...gax.CallOption) (*BatchUpdateEntityTypesOperation, error) {
  266. ctx = insertMetadata(ctx, c.xGoogMetadata)
  267. opts = append(c.CallOptions.BatchUpdateEntityTypes[0:len(c.CallOptions.BatchUpdateEntityTypes):len(c.CallOptions.BatchUpdateEntityTypes)], opts...)
  268. var resp *longrunningpb.Operation
  269. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  270. var err error
  271. resp, err = c.entityTypesClient.BatchUpdateEntityTypes(ctx, req, settings.GRPC...)
  272. return err
  273. }, opts...)
  274. if err != nil {
  275. return nil, err
  276. }
  277. return &BatchUpdateEntityTypesOperation{
  278. lro: longrunning.InternalNewOperation(c.LROClient, resp),
  279. }, nil
  280. }
  281. // BatchDeleteEntityTypes deletes entity types in the specified agent.
  282. //
  283. // Operation <response: [google.protobuf.Empty][google.protobuf.Empty],
  284. // metadata: [google.protobuf.Struct][google.protobuf.Struct]>
  285. func (c *EntityTypesClient) BatchDeleteEntityTypes(ctx context.Context, req *dialogflowpb.BatchDeleteEntityTypesRequest, opts ...gax.CallOption) (*BatchDeleteEntityTypesOperation, error) {
  286. ctx = insertMetadata(ctx, c.xGoogMetadata)
  287. opts = append(c.CallOptions.BatchDeleteEntityTypes[0:len(c.CallOptions.BatchDeleteEntityTypes):len(c.CallOptions.BatchDeleteEntityTypes)], opts...)
  288. var resp *longrunningpb.Operation
  289. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  290. var err error
  291. resp, err = c.entityTypesClient.BatchDeleteEntityTypes(ctx, req, settings.GRPC...)
  292. return err
  293. }, opts...)
  294. if err != nil {
  295. return nil, err
  296. }
  297. return &BatchDeleteEntityTypesOperation{
  298. lro: longrunning.InternalNewOperation(c.LROClient, resp),
  299. }, nil
  300. }
  301. // BatchCreateEntities creates multiple new entities in the specified entity type (extends the
  302. // existing collection of entries).
  303. //
  304. // Operation <response: [google.protobuf.Empty][google.protobuf.Empty]>
  305. func (c *EntityTypesClient) BatchCreateEntities(ctx context.Context, req *dialogflowpb.BatchCreateEntitiesRequest, opts ...gax.CallOption) (*BatchCreateEntitiesOperation, error) {
  306. ctx = insertMetadata(ctx, c.xGoogMetadata)
  307. opts = append(c.CallOptions.BatchCreateEntities[0:len(c.CallOptions.BatchCreateEntities):len(c.CallOptions.BatchCreateEntities)], opts...)
  308. var resp *longrunningpb.Operation
  309. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  310. var err error
  311. resp, err = c.entityTypesClient.BatchCreateEntities(ctx, req, settings.GRPC...)
  312. return err
  313. }, opts...)
  314. if err != nil {
  315. return nil, err
  316. }
  317. return &BatchCreateEntitiesOperation{
  318. lro: longrunning.InternalNewOperation(c.LROClient, resp),
  319. }, nil
  320. }
  321. // BatchUpdateEntities updates entities in the specified entity type (replaces the existing
  322. // collection of entries).
  323. //
  324. // Operation <response: [google.protobuf.Empty][google.protobuf.Empty],
  325. // metadata: [google.protobuf.Struct][google.protobuf.Struct]>
  326. func (c *EntityTypesClient) BatchUpdateEntities(ctx context.Context, req *dialogflowpb.BatchUpdateEntitiesRequest, opts ...gax.CallOption) (*BatchUpdateEntitiesOperation, error) {
  327. ctx = insertMetadata(ctx, c.xGoogMetadata)
  328. opts = append(c.CallOptions.BatchUpdateEntities[0:len(c.CallOptions.BatchUpdateEntities):len(c.CallOptions.BatchUpdateEntities)], opts...)
  329. var resp *longrunningpb.Operation
  330. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  331. var err error
  332. resp, err = c.entityTypesClient.BatchUpdateEntities(ctx, req, settings.GRPC...)
  333. return err
  334. }, opts...)
  335. if err != nil {
  336. return nil, err
  337. }
  338. return &BatchUpdateEntitiesOperation{
  339. lro: longrunning.InternalNewOperation(c.LROClient, resp),
  340. }, nil
  341. }
  342. // BatchDeleteEntities deletes entities in the specified entity type.
  343. //
  344. // Operation <response: [google.protobuf.Empty][google.protobuf.Empty],
  345. // metadata: [google.protobuf.Struct][google.protobuf.Struct]>
  346. func (c *EntityTypesClient) BatchDeleteEntities(ctx context.Context, req *dialogflowpb.BatchDeleteEntitiesRequest, opts ...gax.CallOption) (*BatchDeleteEntitiesOperation, error) {
  347. ctx = insertMetadata(ctx, c.xGoogMetadata)
  348. opts = append(c.CallOptions.BatchDeleteEntities[0:len(c.CallOptions.BatchDeleteEntities):len(c.CallOptions.BatchDeleteEntities)], opts...)
  349. var resp *longrunningpb.Operation
  350. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  351. var err error
  352. resp, err = c.entityTypesClient.BatchDeleteEntities(ctx, req, settings.GRPC...)
  353. return err
  354. }, opts...)
  355. if err != nil {
  356. return nil, err
  357. }
  358. return &BatchDeleteEntitiesOperation{
  359. lro: longrunning.InternalNewOperation(c.LROClient, resp),
  360. }, nil
  361. }
  362. // EntityTypeIterator manages a stream of *dialogflowpb.EntityType.
  363. type EntityTypeIterator struct {
  364. items []*dialogflowpb.EntityType
  365. pageInfo *iterator.PageInfo
  366. nextFunc func() error
  367. // InternalFetch is for use by the Google Cloud Libraries only.
  368. // It is not part of the stable interface of this package.
  369. //
  370. // InternalFetch returns results from a single call to the underlying RPC.
  371. // The number of results is no greater than pageSize.
  372. // If there are no more results, nextPageToken is empty and err is nil.
  373. InternalFetch func(pageSize int, pageToken string) (results []*dialogflowpb.EntityType, nextPageToken string, err error)
  374. }
  375. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  376. func (it *EntityTypeIterator) PageInfo() *iterator.PageInfo {
  377. return it.pageInfo
  378. }
  379. // Next returns the next result. Its second return value is iterator.Done if there are no more
  380. // results. Once Next returns Done, all subsequent calls will return Done.
  381. func (it *EntityTypeIterator) Next() (*dialogflowpb.EntityType, error) {
  382. var item *dialogflowpb.EntityType
  383. if err := it.nextFunc(); err != nil {
  384. return item, err
  385. }
  386. item = it.items[0]
  387. it.items = it.items[1:]
  388. return item, nil
  389. }
  390. func (it *EntityTypeIterator) bufLen() int {
  391. return len(it.items)
  392. }
  393. func (it *EntityTypeIterator) takeBuf() interface{} {
  394. b := it.items
  395. it.items = nil
  396. return b
  397. }
  398. // BatchCreateEntitiesOperation manages a long-running operation from BatchCreateEntities.
  399. type BatchCreateEntitiesOperation struct {
  400. lro *longrunning.Operation
  401. }
  402. // BatchCreateEntitiesOperation returns a new BatchCreateEntitiesOperation from a given name.
  403. // The name must be that of a previously created BatchCreateEntitiesOperation, possibly from a different process.
  404. func (c *EntityTypesClient) BatchCreateEntitiesOperation(name string) *BatchCreateEntitiesOperation {
  405. return &BatchCreateEntitiesOperation{
  406. lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
  407. }
  408. }
  409. // Wait blocks until the long-running operation is completed, returning any error encountered.
  410. //
  411. // See documentation of Poll for error-handling information.
  412. func (op *BatchCreateEntitiesOperation) Wait(ctx context.Context, opts ...gax.CallOption) error {
  413. return op.lro.WaitWithInterval(ctx, nil, 5000*time.Millisecond, opts...)
  414. }
  415. // Poll fetches the latest state of the long-running operation.
  416. //
  417. // Poll also fetches the latest metadata, which can be retrieved by Metadata.
  418. //
  419. // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
  420. // the operation has completed with failure, the error is returned and op.Done will return true.
  421. // If Poll succeeds and the operation has completed successfully, op.Done will return true.
  422. func (op *BatchCreateEntitiesOperation) Poll(ctx context.Context, opts ...gax.CallOption) error {
  423. return op.lro.Poll(ctx, nil, opts...)
  424. }
  425. // Metadata returns metadata associated with the long-running operation.
  426. // Metadata itself does not contact the server, but Poll does.
  427. // To get the latest metadata, call this method after a successful call to Poll.
  428. // If the metadata is not available, the returned metadata and error are both nil.
  429. func (op *BatchCreateEntitiesOperation) Metadata() (*structpbpb.Struct, error) {
  430. var meta structpbpb.Struct
  431. if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
  432. return nil, nil
  433. } else if err != nil {
  434. return nil, err
  435. }
  436. return &meta, nil
  437. }
  438. // Done reports whether the long-running operation has completed.
  439. func (op *BatchCreateEntitiesOperation) Done() bool {
  440. return op.lro.Done()
  441. }
  442. // Name returns the name of the long-running operation.
  443. // The name is assigned by the server and is unique within the service from which the operation is created.
  444. func (op *BatchCreateEntitiesOperation) Name() string {
  445. return op.lro.Name()
  446. }
  447. // BatchDeleteEntitiesOperation manages a long-running operation from BatchDeleteEntities.
  448. type BatchDeleteEntitiesOperation struct {
  449. lro *longrunning.Operation
  450. }
  451. // BatchDeleteEntitiesOperation returns a new BatchDeleteEntitiesOperation from a given name.
  452. // The name must be that of a previously created BatchDeleteEntitiesOperation, possibly from a different process.
  453. func (c *EntityTypesClient) BatchDeleteEntitiesOperation(name string) *BatchDeleteEntitiesOperation {
  454. return &BatchDeleteEntitiesOperation{
  455. lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
  456. }
  457. }
  458. // Wait blocks until the long-running operation is completed, returning any error encountered.
  459. //
  460. // See documentation of Poll for error-handling information.
  461. func (op *BatchDeleteEntitiesOperation) Wait(ctx context.Context, opts ...gax.CallOption) error {
  462. return op.lro.WaitWithInterval(ctx, nil, 5000*time.Millisecond, opts...)
  463. }
  464. // Poll fetches the latest state of the long-running operation.
  465. //
  466. // Poll also fetches the latest metadata, which can be retrieved by Metadata.
  467. //
  468. // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
  469. // the operation has completed with failure, the error is returned and op.Done will return true.
  470. // If Poll succeeds and the operation has completed successfully, op.Done will return true.
  471. func (op *BatchDeleteEntitiesOperation) Poll(ctx context.Context, opts ...gax.CallOption) error {
  472. return op.lro.Poll(ctx, nil, opts...)
  473. }
  474. // Metadata returns metadata associated with the long-running operation.
  475. // Metadata itself does not contact the server, but Poll does.
  476. // To get the latest metadata, call this method after a successful call to Poll.
  477. // If the metadata is not available, the returned metadata and error are both nil.
  478. func (op *BatchDeleteEntitiesOperation) Metadata() (*structpbpb.Struct, error) {
  479. var meta structpbpb.Struct
  480. if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
  481. return nil, nil
  482. } else if err != nil {
  483. return nil, err
  484. }
  485. return &meta, nil
  486. }
  487. // Done reports whether the long-running operation has completed.
  488. func (op *BatchDeleteEntitiesOperation) Done() bool {
  489. return op.lro.Done()
  490. }
  491. // Name returns the name of the long-running operation.
  492. // The name is assigned by the server and is unique within the service from which the operation is created.
  493. func (op *BatchDeleteEntitiesOperation) Name() string {
  494. return op.lro.Name()
  495. }
  496. // BatchDeleteEntityTypesOperation manages a long-running operation from BatchDeleteEntityTypes.
  497. type BatchDeleteEntityTypesOperation struct {
  498. lro *longrunning.Operation
  499. }
  500. // BatchDeleteEntityTypesOperation returns a new BatchDeleteEntityTypesOperation from a given name.
  501. // The name must be that of a previously created BatchDeleteEntityTypesOperation, possibly from a different process.
  502. func (c *EntityTypesClient) BatchDeleteEntityTypesOperation(name string) *BatchDeleteEntityTypesOperation {
  503. return &BatchDeleteEntityTypesOperation{
  504. lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
  505. }
  506. }
  507. // Wait blocks until the long-running operation is completed, returning any error encountered.
  508. //
  509. // See documentation of Poll for error-handling information.
  510. func (op *BatchDeleteEntityTypesOperation) Wait(ctx context.Context, opts ...gax.CallOption) error {
  511. return op.lro.WaitWithInterval(ctx, nil, 5000*time.Millisecond, opts...)
  512. }
  513. // Poll fetches the latest state of the long-running operation.
  514. //
  515. // Poll also fetches the latest metadata, which can be retrieved by Metadata.
  516. //
  517. // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
  518. // the operation has completed with failure, the error is returned and op.Done will return true.
  519. // If Poll succeeds and the operation has completed successfully, op.Done will return true.
  520. func (op *BatchDeleteEntityTypesOperation) Poll(ctx context.Context, opts ...gax.CallOption) error {
  521. return op.lro.Poll(ctx, nil, opts...)
  522. }
  523. // Metadata returns metadata associated with the long-running operation.
  524. // Metadata itself does not contact the server, but Poll does.
  525. // To get the latest metadata, call this method after a successful call to Poll.
  526. // If the metadata is not available, the returned metadata and error are both nil.
  527. func (op *BatchDeleteEntityTypesOperation) Metadata() (*structpbpb.Struct, error) {
  528. var meta structpbpb.Struct
  529. if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
  530. return nil, nil
  531. } else if err != nil {
  532. return nil, err
  533. }
  534. return &meta, nil
  535. }
  536. // Done reports whether the long-running operation has completed.
  537. func (op *BatchDeleteEntityTypesOperation) Done() bool {
  538. return op.lro.Done()
  539. }
  540. // Name returns the name of the long-running operation.
  541. // The name is assigned by the server and is unique within the service from which the operation is created.
  542. func (op *BatchDeleteEntityTypesOperation) Name() string {
  543. return op.lro.Name()
  544. }
  545. // BatchUpdateEntitiesOperation manages a long-running operation from BatchUpdateEntities.
  546. type BatchUpdateEntitiesOperation struct {
  547. lro *longrunning.Operation
  548. }
  549. // BatchUpdateEntitiesOperation returns a new BatchUpdateEntitiesOperation from a given name.
  550. // The name must be that of a previously created BatchUpdateEntitiesOperation, possibly from a different process.
  551. func (c *EntityTypesClient) BatchUpdateEntitiesOperation(name string) *BatchUpdateEntitiesOperation {
  552. return &BatchUpdateEntitiesOperation{
  553. lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
  554. }
  555. }
  556. // Wait blocks until the long-running operation is completed, returning any error encountered.
  557. //
  558. // See documentation of Poll for error-handling information.
  559. func (op *BatchUpdateEntitiesOperation) Wait(ctx context.Context, opts ...gax.CallOption) error {
  560. return op.lro.WaitWithInterval(ctx, nil, 5000*time.Millisecond, opts...)
  561. }
  562. // Poll fetches the latest state of the long-running operation.
  563. //
  564. // Poll also fetches the latest metadata, which can be retrieved by Metadata.
  565. //
  566. // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
  567. // the operation has completed with failure, the error is returned and op.Done will return true.
  568. // If Poll succeeds and the operation has completed successfully, op.Done will return true.
  569. func (op *BatchUpdateEntitiesOperation) Poll(ctx context.Context, opts ...gax.CallOption) error {
  570. return op.lro.Poll(ctx, nil, opts...)
  571. }
  572. // Metadata returns metadata associated with the long-running operation.
  573. // Metadata itself does not contact the server, but Poll does.
  574. // To get the latest metadata, call this method after a successful call to Poll.
  575. // If the metadata is not available, the returned metadata and error are both nil.
  576. func (op *BatchUpdateEntitiesOperation) Metadata() (*structpbpb.Struct, error) {
  577. var meta structpbpb.Struct
  578. if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
  579. return nil, nil
  580. } else if err != nil {
  581. return nil, err
  582. }
  583. return &meta, nil
  584. }
  585. // Done reports whether the long-running operation has completed.
  586. func (op *BatchUpdateEntitiesOperation) Done() bool {
  587. return op.lro.Done()
  588. }
  589. // Name returns the name of the long-running operation.
  590. // The name is assigned by the server and is unique within the service from which the operation is created.
  591. func (op *BatchUpdateEntitiesOperation) Name() string {
  592. return op.lro.Name()
  593. }
  594. // BatchUpdateEntityTypesOperation manages a long-running operation from BatchUpdateEntityTypes.
  595. type BatchUpdateEntityTypesOperation struct {
  596. lro *longrunning.Operation
  597. }
  598. // BatchUpdateEntityTypesOperation returns a new BatchUpdateEntityTypesOperation from a given name.
  599. // The name must be that of a previously created BatchUpdateEntityTypesOperation, possibly from a different process.
  600. func (c *EntityTypesClient) BatchUpdateEntityTypesOperation(name string) *BatchUpdateEntityTypesOperation {
  601. return &BatchUpdateEntityTypesOperation{
  602. lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
  603. }
  604. }
  605. // Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
  606. //
  607. // See documentation of Poll for error-handling information.
  608. func (op *BatchUpdateEntityTypesOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*dialogflowpb.BatchUpdateEntityTypesResponse, error) {
  609. var resp dialogflowpb.BatchUpdateEntityTypesResponse
  610. if err := op.lro.WaitWithInterval(ctx, &resp, 5000*time.Millisecond, opts...); err != nil {
  611. return nil, err
  612. }
  613. return &resp, nil
  614. }
  615. // Poll fetches the latest state of the long-running operation.
  616. //
  617. // Poll also fetches the latest metadata, which can be retrieved by Metadata.
  618. //
  619. // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
  620. // the operation has completed with failure, the error is returned and op.Done will return true.
  621. // If Poll succeeds and the operation has completed successfully,
  622. // op.Done will return true, and the response of the operation is returned.
  623. // If Poll succeeds and the operation has not completed, the returned response and error are both nil.
  624. func (op *BatchUpdateEntityTypesOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*dialogflowpb.BatchUpdateEntityTypesResponse, error) {
  625. var resp dialogflowpb.BatchUpdateEntityTypesResponse
  626. if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
  627. return nil, err
  628. }
  629. if !op.Done() {
  630. return nil, nil
  631. }
  632. return &resp, nil
  633. }
  634. // Metadata returns metadata associated with the long-running operation.
  635. // Metadata itself does not contact the server, but Poll does.
  636. // To get the latest metadata, call this method after a successful call to Poll.
  637. // If the metadata is not available, the returned metadata and error are both nil.
  638. func (op *BatchUpdateEntityTypesOperation) Metadata() (*structpbpb.Struct, error) {
  639. var meta structpbpb.Struct
  640. if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
  641. return nil, nil
  642. } else if err != nil {
  643. return nil, err
  644. }
  645. return &meta, nil
  646. }
  647. // Done reports whether the long-running operation has completed.
  648. func (op *BatchUpdateEntityTypesOperation) Done() bool {
  649. return op.lro.Done()
  650. }
  651. // Name returns the name of the long-running operation.
  652. // The name is assigned by the server and is unique within the service from which the operation is created.
  653. func (op *BatchUpdateEntityTypesOperation) Name() string {
  654. return op.lro.Name()
  655. }