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.
 
 
 

277 line
11 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. gax "github.com/googleapis/gax-go"
  21. "golang.org/x/net/context"
  22. "google.golang.org/api/iterator"
  23. "google.golang.org/api/option"
  24. "google.golang.org/api/transport"
  25. dialogflowpb "google.golang.org/genproto/googleapis/cloud/dialogflow/v2"
  26. "google.golang.org/grpc"
  27. "google.golang.org/grpc/codes"
  28. "google.golang.org/grpc/metadata"
  29. )
  30. // SessionEntityTypesCallOptions contains the retry settings for each method of SessionEntityTypesClient.
  31. type SessionEntityTypesCallOptions struct {
  32. ListSessionEntityTypes []gax.CallOption
  33. GetSessionEntityType []gax.CallOption
  34. CreateSessionEntityType []gax.CallOption
  35. UpdateSessionEntityType []gax.CallOption
  36. DeleteSessionEntityType []gax.CallOption
  37. }
  38. func defaultSessionEntityTypesClientOptions() []option.ClientOption {
  39. return []option.ClientOption{
  40. option.WithEndpoint("dialogflow.googleapis.com:443"),
  41. option.WithScopes(DefaultAuthScopes()...),
  42. }
  43. }
  44. func defaultSessionEntityTypesCallOptions() *SessionEntityTypesCallOptions {
  45. retry := map[[2]string][]gax.CallOption{
  46. {"default", "idempotent"}: {
  47. gax.WithRetry(func() gax.Retryer {
  48. return gax.OnCodes([]codes.Code{
  49. codes.DeadlineExceeded,
  50. codes.Unavailable,
  51. }, gax.Backoff{
  52. Initial: 100 * time.Millisecond,
  53. Max: 60000 * time.Millisecond,
  54. Multiplier: 1.3,
  55. })
  56. }),
  57. },
  58. }
  59. return &SessionEntityTypesCallOptions{
  60. ListSessionEntityTypes: retry[[2]string{"default", "idempotent"}],
  61. GetSessionEntityType: retry[[2]string{"default", "idempotent"}],
  62. CreateSessionEntityType: retry[[2]string{"default", "non_idempotent"}],
  63. UpdateSessionEntityType: retry[[2]string{"default", "non_idempotent"}],
  64. DeleteSessionEntityType: retry[[2]string{"default", "idempotent"}],
  65. }
  66. }
  67. // SessionEntityTypesClient is a client for interacting with Dialogflow API.
  68. //
  69. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  70. type SessionEntityTypesClient struct {
  71. // The connection to the service.
  72. conn *grpc.ClientConn
  73. // The gRPC API client.
  74. sessionEntityTypesClient dialogflowpb.SessionEntityTypesClient
  75. // The call options for this service.
  76. CallOptions *SessionEntityTypesCallOptions
  77. // The x-goog-* metadata to be sent with each request.
  78. xGoogMetadata metadata.MD
  79. }
  80. // NewSessionEntityTypesClient creates a new session entity types client.
  81. //
  82. // Entities are extracted from user input and represent parameters that are
  83. // meaningful to your application. For example, a date range, a proper name
  84. // such as a geographic location or landmark, and so on. Entities represent
  85. // actionable data for your application.
  86. //
  87. // Session entity types are referred to as **User** entity types and are
  88. // entities that are built for an individual user such as
  89. // favorites, preferences, playlists, and so on. You can redefine a session
  90. // entity type at the session level.
  91. //
  92. // For more information about entity types, see the
  93. // [Dialogflow documentation](https://dialogflow.com/docs/entities).
  94. func NewSessionEntityTypesClient(ctx context.Context, opts ...option.ClientOption) (*SessionEntityTypesClient, error) {
  95. conn, err := transport.DialGRPC(ctx, append(defaultSessionEntityTypesClientOptions(), opts...)...)
  96. if err != nil {
  97. return nil, err
  98. }
  99. c := &SessionEntityTypesClient{
  100. conn: conn,
  101. CallOptions: defaultSessionEntityTypesCallOptions(),
  102. sessionEntityTypesClient: dialogflowpb.NewSessionEntityTypesClient(conn),
  103. }
  104. c.setGoogleClientInfo()
  105. return c, nil
  106. }
  107. // Connection returns the client's connection to the API service.
  108. func (c *SessionEntityTypesClient) Connection() *grpc.ClientConn {
  109. return c.conn
  110. }
  111. // Close closes the connection to the API service. The user should invoke this when
  112. // the client is no longer required.
  113. func (c *SessionEntityTypesClient) Close() error {
  114. return c.conn.Close()
  115. }
  116. // setGoogleClientInfo sets the name and version of the application in
  117. // the `x-goog-api-client` header passed on each request. Intended for
  118. // use by Google-written clients.
  119. func (c *SessionEntityTypesClient) setGoogleClientInfo(keyval ...string) {
  120. kv := append([]string{"gl-go", version.Go()}, keyval...)
  121. kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", grpc.Version)
  122. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  123. }
  124. // ListSessionEntityTypes returns the list of all session entity types in the specified session.
  125. func (c *SessionEntityTypesClient) ListSessionEntityTypes(ctx context.Context, req *dialogflowpb.ListSessionEntityTypesRequest, opts ...gax.CallOption) *SessionEntityTypeIterator {
  126. ctx = insertMetadata(ctx, c.xGoogMetadata)
  127. opts = append(c.CallOptions.ListSessionEntityTypes[0:len(c.CallOptions.ListSessionEntityTypes):len(c.CallOptions.ListSessionEntityTypes)], opts...)
  128. it := &SessionEntityTypeIterator{}
  129. it.InternalFetch = func(pageSize int, pageToken string) ([]*dialogflowpb.SessionEntityType, string, error) {
  130. var resp *dialogflowpb.ListSessionEntityTypesResponse
  131. req.PageToken = pageToken
  132. if pageSize > math.MaxInt32 {
  133. req.PageSize = math.MaxInt32
  134. } else {
  135. req.PageSize = int32(pageSize)
  136. }
  137. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  138. var err error
  139. resp, err = c.sessionEntityTypesClient.ListSessionEntityTypes(ctx, req, settings.GRPC...)
  140. return err
  141. }, opts...)
  142. if err != nil {
  143. return nil, "", err
  144. }
  145. return resp.SessionEntityTypes, resp.NextPageToken, nil
  146. }
  147. fetch := func(pageSize int, pageToken string) (string, error) {
  148. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  149. if err != nil {
  150. return "", err
  151. }
  152. it.items = append(it.items, items...)
  153. return nextPageToken, nil
  154. }
  155. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  156. return it
  157. }
  158. // GetSessionEntityType retrieves the specified session entity type.
  159. func (c *SessionEntityTypesClient) GetSessionEntityType(ctx context.Context, req *dialogflowpb.GetSessionEntityTypeRequest, opts ...gax.CallOption) (*dialogflowpb.SessionEntityType, error) {
  160. ctx = insertMetadata(ctx, c.xGoogMetadata)
  161. opts = append(c.CallOptions.GetSessionEntityType[0:len(c.CallOptions.GetSessionEntityType):len(c.CallOptions.GetSessionEntityType)], opts...)
  162. var resp *dialogflowpb.SessionEntityType
  163. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  164. var err error
  165. resp, err = c.sessionEntityTypesClient.GetSessionEntityType(ctx, req, settings.GRPC...)
  166. return err
  167. }, opts...)
  168. if err != nil {
  169. return nil, err
  170. }
  171. return resp, nil
  172. }
  173. // CreateSessionEntityType creates a session entity type.
  174. func (c *SessionEntityTypesClient) CreateSessionEntityType(ctx context.Context, req *dialogflowpb.CreateSessionEntityTypeRequest, opts ...gax.CallOption) (*dialogflowpb.SessionEntityType, error) {
  175. ctx = insertMetadata(ctx, c.xGoogMetadata)
  176. opts = append(c.CallOptions.CreateSessionEntityType[0:len(c.CallOptions.CreateSessionEntityType):len(c.CallOptions.CreateSessionEntityType)], opts...)
  177. var resp *dialogflowpb.SessionEntityType
  178. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  179. var err error
  180. resp, err = c.sessionEntityTypesClient.CreateSessionEntityType(ctx, req, settings.GRPC...)
  181. return err
  182. }, opts...)
  183. if err != nil {
  184. return nil, err
  185. }
  186. return resp, nil
  187. }
  188. // UpdateSessionEntityType updates the specified session entity type.
  189. func (c *SessionEntityTypesClient) UpdateSessionEntityType(ctx context.Context, req *dialogflowpb.UpdateSessionEntityTypeRequest, opts ...gax.CallOption) (*dialogflowpb.SessionEntityType, error) {
  190. ctx = insertMetadata(ctx, c.xGoogMetadata)
  191. opts = append(c.CallOptions.UpdateSessionEntityType[0:len(c.CallOptions.UpdateSessionEntityType):len(c.CallOptions.UpdateSessionEntityType)], opts...)
  192. var resp *dialogflowpb.SessionEntityType
  193. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  194. var err error
  195. resp, err = c.sessionEntityTypesClient.UpdateSessionEntityType(ctx, req, settings.GRPC...)
  196. return err
  197. }, opts...)
  198. if err != nil {
  199. return nil, err
  200. }
  201. return resp, nil
  202. }
  203. // DeleteSessionEntityType deletes the specified session entity type.
  204. func (c *SessionEntityTypesClient) DeleteSessionEntityType(ctx context.Context, req *dialogflowpb.DeleteSessionEntityTypeRequest, opts ...gax.CallOption) error {
  205. ctx = insertMetadata(ctx, c.xGoogMetadata)
  206. opts = append(c.CallOptions.DeleteSessionEntityType[0:len(c.CallOptions.DeleteSessionEntityType):len(c.CallOptions.DeleteSessionEntityType)], opts...)
  207. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  208. var err error
  209. _, err = c.sessionEntityTypesClient.DeleteSessionEntityType(ctx, req, settings.GRPC...)
  210. return err
  211. }, opts...)
  212. return err
  213. }
  214. // SessionEntityTypeIterator manages a stream of *dialogflowpb.SessionEntityType.
  215. type SessionEntityTypeIterator struct {
  216. items []*dialogflowpb.SessionEntityType
  217. pageInfo *iterator.PageInfo
  218. nextFunc func() error
  219. // InternalFetch is for use by the Google Cloud Libraries only.
  220. // It is not part of the stable interface of this package.
  221. //
  222. // InternalFetch returns results from a single call to the underlying RPC.
  223. // The number of results is no greater than pageSize.
  224. // If there are no more results, nextPageToken is empty and err is nil.
  225. InternalFetch func(pageSize int, pageToken string) (results []*dialogflowpb.SessionEntityType, nextPageToken string, err error)
  226. }
  227. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  228. func (it *SessionEntityTypeIterator) PageInfo() *iterator.PageInfo {
  229. return it.pageInfo
  230. }
  231. // Next returns the next result. Its second return value is iterator.Done if there are no more
  232. // results. Once Next returns Done, all subsequent calls will return Done.
  233. func (it *SessionEntityTypeIterator) Next() (*dialogflowpb.SessionEntityType, error) {
  234. var item *dialogflowpb.SessionEntityType
  235. if err := it.nextFunc(); err != nil {
  236. return item, err
  237. }
  238. item = it.items[0]
  239. it.items = it.items[1:]
  240. return item, nil
  241. }
  242. func (it *SessionEntityTypeIterator) bufLen() int {
  243. return len(it.items)
  244. }
  245. func (it *SessionEntityTypeIterator) takeBuf() interface{} {
  246. b := it.items
  247. it.items = nil
  248. return b
  249. }