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.
 
 
 

721 lines
30 KiB

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