ibm_watson 1.5.0 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +42 -4
  3. data/lib/ibm_watson/assistant_v1.rb +213 -195
  4. data/lib/ibm_watson/assistant_v2.rb +161 -17
  5. data/lib/ibm_watson/compare_comply_v1.rb +35 -21
  6. data/lib/ibm_watson/discovery_v1.rb +132 -13
  7. data/lib/ibm_watson/discovery_v2.rb +728 -21
  8. data/lib/ibm_watson/language_translator_v3.rb +205 -67
  9. data/lib/ibm_watson/natural_language_classifier_v1.rb +4 -2
  10. data/lib/ibm_watson/natural_language_understanding_v1.rb +21 -21
  11. data/lib/ibm_watson/personality_insights_v3.rb +27 -18
  12. data/lib/ibm_watson/speech_to_text_v1.rb +58 -46
  13. data/lib/ibm_watson/text_to_speech_v1.rb +113 -129
  14. data/lib/ibm_watson/tone_analyzer_v3.rb +12 -13
  15. data/lib/ibm_watson/version.rb +1 -1
  16. data/lib/ibm_watson/visual_recognition_v3.rb +33 -16
  17. data/lib/ibm_watson/visual_recognition_v4.rb +58 -17
  18. data/test/integration/test_assistant_v1.rb +9 -0
  19. data/test/integration/test_assistant_v2.rb +27 -0
  20. data/test/integration/test_discovery_v2.rb +132 -6
  21. data/test/integration/test_language_translator_v3.rb +5 -0
  22. data/test/integration/test_text_to_speech_v1.rb +3 -3
  23. data/test/unit/test_assistant_v1.rb +150 -99
  24. data/test/unit/test_assistant_v2.rb +91 -12
  25. data/test/unit/test_compare_comply_v1.rb +20 -20
  26. data/test/unit/test_discovery_v1.rb +125 -125
  27. data/test/unit/test_discovery_v2.rb +262 -29
  28. data/test/unit/test_language_translator_v3.rb +85 -24
  29. data/test/unit/test_natural_language_classifier_v1.rb +17 -17
  30. data/test/unit/test_natural_language_understanding_v1.rb +10 -10
  31. data/test/unit/test_personality_insights_v3.rb +14 -14
  32. data/test/unit/test_speech_to_text_v1.rb +97 -97
  33. data/test/unit/test_text_to_speech_v1.rb +48 -48
  34. data/test/unit/test_tone_analyzer_v3.rb +12 -12
  35. data/test/unit/test_visual_recognition_v3.rb +16 -16
  36. data/test/unit/test_visual_recognition_v4.rb +40 -40
  37. metadata +12 -11
@@ -13,12 +13,14 @@
13
13
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
-
17
- # IBM Watson™ Discovery for IBM Cloud Pak for Data is a cognitive search and
18
- # content analytics engine that you can add to applications to identify patterns, trends
19
- # and actionable insights to drive better decision-making. Securely unify structured and
20
- # unstructured data with pre-enriched content, and use a simplified query language to
21
- # eliminate the need for manual filtering of results.
16
+ #
17
+ # IBM OpenAPI SDK Code Generator Version: 3.19.0-be3b4618-20201113-200858
18
+ #
19
+ # IBM Watson™ Discovery is a cognitive search and content analytics engine that
20
+ # you can add to applications to identify patterns, trends and actionable insights to
21
+ # drive better decision-making. Securely unify structured and unstructured data with
22
+ # pre-enriched content, and use a simplified query language to eliminate the need for
23
+ # manual filtering of results.
22
24
 
23
25
  require "concurrent"
24
26
  require "erb"
@@ -33,22 +35,15 @@ module IBMWatson
33
35
  class DiscoveryV2 < IBMCloudSdkCore::BaseService
34
36
  include Concurrent::Async
35
37
  DEFAULT_SERVICE_NAME = "discovery"
36
- DEFAULT_SERVICE_URL = nil
38
+ DEFAULT_SERVICE_URL = "https://api.us-south.discovery.watson.cloud.ibm.com"
39
+ attr_accessor :version
37
40
  ##
38
41
  # @!method initialize(args)
39
42
  # Construct a new client for the Discovery service.
40
43
  #
41
44
  # @param args [Hash] The args to initialize with
42
- # @option args version [String] The API version date to use with the service, in
43
- # "YYYY-MM-DD" format. Whenever the API is changed in a backwards
44
- # incompatible way, a new minor version of the API is released.
45
- # The service uses the API version for the date you specify, or
46
- # the most recent version before that date. Note that you should
47
- # not programmatically specify the current date at runtime, in
48
- # case the API has been updated since your application's release.
49
- # Instead, specify a version date that is compatible with your
50
- # application, and don't change it until your application is
51
- # ready for a later version.
45
+ # @option args version [String] Release date of the version of the API you want to use. Specify dates in
46
+ # YYYY-MM-DD format. The current version is `2019-11-22`.
52
47
  # @option args service_url [String] The base service URL to use when contacting the service.
53
48
  # The base service_url may differ between IBM Cloud regions.
54
49
  # @option args authenticator [Object] The Authenticator instance to be configured for this service.
@@ -57,10 +52,10 @@ module IBMWatson
57
52
  def initialize(args = {})
58
53
  @__async_initialized__ = false
59
54
  defaults = {}
60
- defaults[:version] = nil
61
55
  defaults[:service_url] = DEFAULT_SERVICE_URL
62
56
  defaults[:service_name] = DEFAULT_SERVICE_NAME
63
57
  defaults[:authenticator] = nil
58
+ defaults[:version] = nil
64
59
  user_service_url = args[:service_url] unless args[:service_url].nil?
65
60
  args = defaults.merge(args)
66
61
  @version = args[:version]
@@ -85,6 +80,8 @@ module IBMWatson
85
80
  def list_collections(project_id:)
86
81
  raise ArgumentError.new("project_id must be provided") if project_id.nil?
87
82
 
83
+ raise ArgumentError.new("version must be provided") if version.nil?
84
+
88
85
  headers = {
89
86
  }
90
87
  sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "list_collections")
@@ -105,6 +102,172 @@ module IBMWatson
105
102
  )
106
103
  response
107
104
  end
105
+
106
+ ##
107
+ # @!method create_collection(project_id:, name:, description: nil, language: nil, enrichments: nil)
108
+ # Create a collection.
109
+ # Create a new collection in the specified project.
110
+ # @param project_id [String] The ID of the project. This information can be found from the deploy page of the
111
+ # Discovery administrative tooling.
112
+ # @param name [String] The name of the collection.
113
+ # @param description [String] A description of the collection.
114
+ # @param language [String] The language of the collection.
115
+ # @param enrichments [Array[CollectionEnrichment]] An array of enrichments that are applied to this collection.
116
+ # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
117
+ def create_collection(project_id:, name:, description: nil, language: nil, enrichments: nil)
118
+ raise ArgumentError.new("version must be provided") if version.nil?
119
+
120
+ raise ArgumentError.new("project_id must be provided") if project_id.nil?
121
+
122
+ raise ArgumentError.new("name must be provided") if name.nil?
123
+
124
+ headers = {
125
+ }
126
+ sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "create_collection")
127
+ headers.merge!(sdk_headers)
128
+
129
+ params = {
130
+ "version" => @version
131
+ }
132
+
133
+ data = {
134
+ "name" => name,
135
+ "description" => description,
136
+ "language" => language,
137
+ "enrichments" => enrichments
138
+ }
139
+
140
+ method_url = "/v2/projects/%s/collections" % [ERB::Util.url_encode(project_id)]
141
+
142
+ response = request(
143
+ method: "POST",
144
+ url: method_url,
145
+ headers: headers,
146
+ params: params,
147
+ json: data,
148
+ accept_json: true
149
+ )
150
+ response
151
+ end
152
+
153
+ ##
154
+ # @!method get_collection(project_id:, collection_id:)
155
+ # Get collection.
156
+ # Get details about the specified collection.
157
+ # @param project_id [String] The ID of the project. This information can be found from the deploy page of the
158
+ # Discovery administrative tooling.
159
+ # @param collection_id [String] The ID of the collection.
160
+ # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
161
+ def get_collection(project_id:, collection_id:)
162
+ raise ArgumentError.new("version must be provided") if version.nil?
163
+
164
+ raise ArgumentError.new("project_id must be provided") if project_id.nil?
165
+
166
+ raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
167
+
168
+ headers = {
169
+ }
170
+ sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "get_collection")
171
+ headers.merge!(sdk_headers)
172
+
173
+ params = {
174
+ "version" => @version
175
+ }
176
+
177
+ method_url = "/v2/projects/%s/collections/%s" % [ERB::Util.url_encode(project_id), ERB::Util.url_encode(collection_id)]
178
+
179
+ response = request(
180
+ method: "GET",
181
+ url: method_url,
182
+ headers: headers,
183
+ params: params,
184
+ accept_json: true
185
+ )
186
+ response
187
+ end
188
+
189
+ ##
190
+ # @!method update_collection(project_id:, collection_id:, name: nil, description: nil, enrichments: nil)
191
+ # Update a collection.
192
+ # Updates the specified collection's name, description, and enrichments.
193
+ # @param project_id [String] The ID of the project. This information can be found from the deploy page of the
194
+ # Discovery administrative tooling.
195
+ # @param collection_id [String] The ID of the collection.
196
+ # @param name [String] The name of the collection.
197
+ # @param description [String] A description of the collection.
198
+ # @param enrichments [Array[CollectionEnrichment]] An array of enrichments that are applied to this collection.
199
+ # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
200
+ def update_collection(project_id:, collection_id:, name: nil, description: nil, enrichments: nil)
201
+ raise ArgumentError.new("version must be provided") if version.nil?
202
+
203
+ raise ArgumentError.new("project_id must be provided") if project_id.nil?
204
+
205
+ raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
206
+
207
+ headers = {
208
+ }
209
+ sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "update_collection")
210
+ headers.merge!(sdk_headers)
211
+
212
+ params = {
213
+ "version" => @version
214
+ }
215
+
216
+ data = {
217
+ "name" => name,
218
+ "description" => description,
219
+ "enrichments" => enrichments
220
+ }
221
+
222
+ method_url = "/v2/projects/%s/collections/%s" % [ERB::Util.url_encode(project_id), ERB::Util.url_encode(collection_id)]
223
+
224
+ response = request(
225
+ method: "POST",
226
+ url: method_url,
227
+ headers: headers,
228
+ params: params,
229
+ json: data,
230
+ accept_json: true
231
+ )
232
+ response
233
+ end
234
+
235
+ ##
236
+ # @!method delete_collection(project_id:, collection_id:)
237
+ # Delete a collection.
238
+ # Deletes the specified collection from the project. All documents stored in the
239
+ # specified collection and not shared is also deleted.
240
+ # @param project_id [String] The ID of the project. This information can be found from the deploy page of the
241
+ # Discovery administrative tooling.
242
+ # @param collection_id [String] The ID of the collection.
243
+ # @return [nil]
244
+ def delete_collection(project_id:, collection_id:)
245
+ raise ArgumentError.new("version must be provided") if version.nil?
246
+
247
+ raise ArgumentError.new("project_id must be provided") if project_id.nil?
248
+
249
+ raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
250
+
251
+ headers = {
252
+ }
253
+ sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "delete_collection")
254
+ headers.merge!(sdk_headers)
255
+
256
+ params = {
257
+ "version" => @version
258
+ }
259
+
260
+ method_url = "/v2/projects/%s/collections/%s" % [ERB::Util.url_encode(project_id), ERB::Util.url_encode(collection_id)]
261
+
262
+ request(
263
+ method: "DELETE",
264
+ url: method_url,
265
+ headers: headers,
266
+ params: params,
267
+ accept_json: false
268
+ )
269
+ nil
270
+ end
108
271
  #########################
109
272
  # Queries
110
273
  #########################
@@ -114,6 +277,12 @@ module IBMWatson
114
277
  # Query a project.
115
278
  # By using this method, you can construct queries. For details, see the [Discovery
116
279
  # documentation](https://cloud.ibm.com/docs/discovery-data?topic=discovery-data-query-concepts).
280
+ # The default query parameters are defined by the settings for this project, see the
281
+ # [Discovery
282
+ # documentation](https://cloud.ibm.com/docs/discovery-data?topic=discovery-data-project-defaults)
283
+ # for an overview of the standard default settings, and see [the Projects API
284
+ # documentation](#create-project) for details about how to set custom default query
285
+ # settings.
117
286
  # @param project_id [String] The ID of the project. This information can be found from the deploy page of the
118
287
  # Discovery administrative tooling.
119
288
  # @param collection_ids [Array[String]] A comma-separated list of collection IDs to be queried against.
@@ -151,6 +320,8 @@ module IBMWatson
151
320
  def query(project_id:, collection_ids: nil, filter: nil, query: nil, natural_language_query: nil, aggregation: nil, count: nil, _return: nil, offset: nil, sort: nil, highlight: nil, spelling_suggestions: nil, table_results: nil, suggested_refinements: nil, passages: nil)
152
321
  raise ArgumentError.new("project_id must be provided") if project_id.nil?
153
322
 
323
+ raise ArgumentError.new("version must be provided") if version.nil?
324
+
154
325
  headers = {
155
326
  }
156
327
  sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "query")
@@ -207,6 +378,8 @@ module IBMWatson
207
378
  def get_autocompletion(project_id:, prefix:, collection_ids: nil, field: nil, count: nil)
208
379
  raise ArgumentError.new("project_id must be provided") if project_id.nil?
209
380
 
381
+ raise ArgumentError.new("version must be provided") if version.nil?
382
+
210
383
  raise ArgumentError.new("prefix must be provided") if prefix.nil?
211
384
 
212
385
  headers = {
@@ -258,6 +431,8 @@ module IBMWatson
258
431
  # one query is **10000**.
259
432
  # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
260
433
  def query_notices(project_id:, filter: nil, query: nil, natural_language_query: nil, count: nil, offset: nil)
434
+ raise ArgumentError.new("version must be provided") if version.nil?
435
+
261
436
  raise ArgumentError.new("project_id must be provided") if project_id.nil?
262
437
 
263
438
  headers = {
@@ -297,6 +472,8 @@ module IBMWatson
297
472
  # all collections in the project are used.
298
473
  # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
299
474
  def list_fields(project_id:, collection_ids: nil)
475
+ raise ArgumentError.new("version must be provided") if version.nil?
476
+
300
477
  raise ArgumentError.new("project_id must be provided") if project_id.nil?
301
478
 
302
479
  headers = {
@@ -327,7 +504,7 @@ module IBMWatson
327
504
 
328
505
  ##
329
506
  # @!method get_component_settings(project_id:)
330
- # Configuration settings for components.
507
+ # List component settings.
331
508
  # Returns default configuration settings for components.
332
509
  # @param project_id [String] The ID of the project. This information can be found from the deploy page of the
333
510
  # Discovery administrative tooling.
@@ -335,6 +512,8 @@ module IBMWatson
335
512
  def get_component_settings(project_id:)
336
513
  raise ArgumentError.new("project_id must be provided") if project_id.nil?
337
514
 
515
+ raise ArgumentError.new("version must be provided") if version.nil?
516
+
338
517
  headers = {
339
518
  }
340
519
  sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "get_component_settings")
@@ -405,7 +584,10 @@ module IBMWatson
405
584
  # @param filename [String] The filename for file.
406
585
  # @param file_content_type [String] The content type of file.
407
586
  # @param metadata [String] The maximum supported metadata file size is 1 MB. Metadata parts larger than 1 MB
408
- # are rejected. Example: ``` {
587
+ # are rejected.
588
+ #
589
+ #
590
+ # Example: ``` {
409
591
  # "Creator": "Johnny Appleseed",
410
592
  # "Subject": "Apples"
411
593
  # } ```.
@@ -413,6 +595,8 @@ module IBMWatson
413
595
  # that collection is shared with other collections.
414
596
  # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
415
597
  def add_document(project_id:, collection_id:, file: nil, filename: nil, file_content_type: nil, metadata: nil, x_watson_discovery_force: nil)
598
+ raise ArgumentError.new("version must be provided") if version.nil?
599
+
416
600
  raise ArgumentError.new("project_id must be provided") if project_id.nil?
417
601
 
418
602
  raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
@@ -481,7 +665,10 @@ module IBMWatson
481
665
  # @param filename [String] The filename for file.
482
666
  # @param file_content_type [String] The content type of file.
483
667
  # @param metadata [String] The maximum supported metadata file size is 1 MB. Metadata parts larger than 1 MB
484
- # are rejected. Example: ``` {
668
+ # are rejected.
669
+ #
670
+ #
671
+ # Example: ``` {
485
672
  # "Creator": "Johnny Appleseed",
486
673
  # "Subject": "Apples"
487
674
  # } ```.
@@ -489,6 +676,8 @@ module IBMWatson
489
676
  # that collection is shared with other collections.
490
677
  # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
491
678
  def update_document(project_id:, collection_id:, document_id:, file: nil, filename: nil, file_content_type: nil, metadata: nil, x_watson_discovery_force: nil)
679
+ raise ArgumentError.new("version must be provided") if version.nil?
680
+
492
681
  raise ArgumentError.new("project_id must be provided") if project_id.nil?
493
682
 
494
683
  raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
@@ -551,6 +740,8 @@ module IBMWatson
551
740
  # that collection is shared with other collections.
552
741
  # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
553
742
  def delete_document(project_id:, collection_id:, document_id:, x_watson_discovery_force: nil)
743
+ raise ArgumentError.new("version must be provided") if version.nil?
744
+
554
745
  raise ArgumentError.new("project_id must be provided") if project_id.nil?
555
746
 
556
747
  raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
@@ -590,6 +781,8 @@ module IBMWatson
590
781
  # Discovery administrative tooling.
591
782
  # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
592
783
  def list_training_queries(project_id:)
784
+ raise ArgumentError.new("version must be provided") if version.nil?
785
+
593
786
  raise ArgumentError.new("project_id must be provided") if project_id.nil?
594
787
 
595
788
  headers = {
@@ -621,6 +814,8 @@ module IBMWatson
621
814
  # Discovery administrative tooling.
622
815
  # @return [nil]
623
816
  def delete_training_queries(project_id:)
817
+ raise ArgumentError.new("version must be provided") if version.nil?
818
+
624
819
  raise ArgumentError.new("project_id must be provided") if project_id.nil?
625
820
 
626
821
  headers = {
@@ -657,6 +852,8 @@ module IBMWatson
657
852
  # applied.
658
853
  # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
659
854
  def create_training_query(project_id:, natural_language_query:, examples:, filter: nil)
855
+ raise ArgumentError.new("version must be provided") if version.nil?
856
+
660
857
  raise ArgumentError.new("project_id must be provided") if project_id.nil?
661
858
 
662
859
  raise ArgumentError.new("natural_language_query must be provided") if natural_language_query.nil?
@@ -701,6 +898,8 @@ module IBMWatson
701
898
  # @param query_id [String] The ID of the query used for training.
702
899
  # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
703
900
  def get_training_query(project_id:, query_id:)
901
+ raise ArgumentError.new("version must be provided") if version.nil?
902
+
704
903
  raise ArgumentError.new("project_id must be provided") if project_id.nil?
705
904
 
706
905
  raise ArgumentError.new("query_id must be provided") if query_id.nil?
@@ -739,6 +938,8 @@ module IBMWatson
739
938
  # applied.
740
939
  # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
741
940
  def update_training_query(project_id:, query_id:, natural_language_query:, examples:, filter: nil)
941
+ raise ArgumentError.new("version must be provided") if version.nil?
942
+
742
943
  raise ArgumentError.new("project_id must be provided") if project_id.nil?
743
944
 
744
945
  raise ArgumentError.new("query_id must be provided") if query_id.nil?
@@ -774,5 +975,511 @@ module IBMWatson
774
975
  )
775
976
  response
776
977
  end
978
+ #########################
979
+ # analyze
980
+ #########################
981
+
982
+ ##
983
+ # @!method analyze_document(project_id:, collection_id:, file: nil, filename: nil, file_content_type: nil, metadata: nil)
984
+ # Analyze a Document.
985
+ # Process a document using the specified collection's settings and return it for
986
+ # realtime use.
987
+ #
988
+ # **Note:** Documents processed using this method are not added to the specified
989
+ # collection.
990
+ #
991
+ # **Note:** This method is only supported on IBM Cloud Pak for Data instances of
992
+ # Discovery.
993
+ # @param project_id [String] The ID of the project. This information can be found from the deploy page of the
994
+ # Discovery administrative tooling.
995
+ # @param collection_id [String] The ID of the collection.
996
+ # @param file [File] The content of the document to ingest. The maximum supported file size when adding
997
+ # a file to a collection is 50 megabytes, the maximum supported file size when
998
+ # testing a configuration is 1 megabyte. Files larger than the supported size are
999
+ # rejected.
1000
+ # @param filename [String] The filename for file.
1001
+ # @param file_content_type [String] The content type of file.
1002
+ # @param metadata [String] The maximum supported metadata file size is 1 MB. Metadata parts larger than 1 MB
1003
+ # are rejected.
1004
+ #
1005
+ #
1006
+ # Example: ``` {
1007
+ # "Creator": "Johnny Appleseed",
1008
+ # "Subject": "Apples"
1009
+ # } ```.
1010
+ # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
1011
+ def analyze_document(project_id:, collection_id:, file: nil, filename: nil, file_content_type: nil, metadata: nil)
1012
+ raise ArgumentError.new("version must be provided") if version.nil?
1013
+
1014
+ raise ArgumentError.new("project_id must be provided") if project_id.nil?
1015
+
1016
+ raise ArgumentError.new("collection_id must be provided") if collection_id.nil?
1017
+
1018
+ headers = {
1019
+ }
1020
+ sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "analyze_document")
1021
+ headers.merge!(sdk_headers)
1022
+
1023
+ params = {
1024
+ "version" => @version
1025
+ }
1026
+
1027
+ form_data = {}
1028
+
1029
+ unless file.nil?
1030
+ unless file.instance_of?(StringIO) || file.instance_of?(File)
1031
+ file = file.respond_to?(:to_json) ? StringIO.new(file.to_json) : StringIO.new(file)
1032
+ end
1033
+ filename = file.path if filename.nil? && file.respond_to?(:path)
1034
+ form_data[:file] = HTTP::FormData::File.new(file, content_type: file_content_type.nil? ? "application/octet-stream" : file_content_type, filename: filename)
1035
+ end
1036
+
1037
+ form_data[:metadata] = HTTP::FormData::Part.new(metadata.to_s, content_type: "text/plain") unless metadata.nil?
1038
+
1039
+ method_url = "/v2/projects/%s/collections/%s/analyze" % [ERB::Util.url_encode(project_id), ERB::Util.url_encode(collection_id)]
1040
+
1041
+ response = request(
1042
+ method: "POST",
1043
+ url: method_url,
1044
+ headers: headers,
1045
+ params: params,
1046
+ form: form_data,
1047
+ accept_json: true
1048
+ )
1049
+ response
1050
+ end
1051
+ #########################
1052
+ # enrichments
1053
+ #########################
1054
+
1055
+ ##
1056
+ # @!method list_enrichments(project_id:)
1057
+ # List Enrichments.
1058
+ # List the enrichments available to this project.
1059
+ # @param project_id [String] The ID of the project. This information can be found from the deploy page of the
1060
+ # Discovery administrative tooling.
1061
+ # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
1062
+ def list_enrichments(project_id:)
1063
+ raise ArgumentError.new("version must be provided") if version.nil?
1064
+
1065
+ raise ArgumentError.new("project_id must be provided") if project_id.nil?
1066
+
1067
+ headers = {
1068
+ }
1069
+ sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "list_enrichments")
1070
+ headers.merge!(sdk_headers)
1071
+
1072
+ params = {
1073
+ "version" => @version
1074
+ }
1075
+
1076
+ method_url = "/v2/projects/%s/enrichments" % [ERB::Util.url_encode(project_id)]
1077
+
1078
+ response = request(
1079
+ method: "GET",
1080
+ url: method_url,
1081
+ headers: headers,
1082
+ params: params,
1083
+ accept_json: true
1084
+ )
1085
+ response
1086
+ end
1087
+
1088
+ ##
1089
+ # @!method create_enrichment(project_id:, enrichment:, file: nil)
1090
+ # Create an enrichment.
1091
+ # Create an enrichment for use with the specified project/.
1092
+ # @param project_id [String] The ID of the project. This information can be found from the deploy page of the
1093
+ # Discovery administrative tooling.
1094
+ # @param enrichment [CreateEnrichment]
1095
+ # @param file [File] The enrichment file to upload.
1096
+ # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
1097
+ def create_enrichment(project_id:, enrichment:, file: nil)
1098
+ raise ArgumentError.new("version must be provided") if version.nil?
1099
+
1100
+ raise ArgumentError.new("project_id must be provided") if project_id.nil?
1101
+
1102
+ raise ArgumentError.new("enrichment must be provided") if enrichment.nil?
1103
+
1104
+ headers = {
1105
+ }
1106
+ sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "create_enrichment")
1107
+ headers.merge!(sdk_headers)
1108
+
1109
+ params = {
1110
+ "version" => @version
1111
+ }
1112
+
1113
+ form_data = {}
1114
+
1115
+ form_data[:enrichment] = HTTP::FormData::Part.new(enrichment.to_s, content_type: "application/json")
1116
+
1117
+ unless file.nil?
1118
+ unless file.instance_of?(StringIO) || file.instance_of?(File)
1119
+ file = file.respond_to?(:to_json) ? StringIO.new(file.to_json) : StringIO.new(file)
1120
+ end
1121
+ form_data[:file] = HTTP::FormData::File.new(file, content_type: "application/octet-stream", filename: file.respond_to?(:path) ? file.path : nil)
1122
+ end
1123
+
1124
+ method_url = "/v2/projects/%s/enrichments" % [ERB::Util.url_encode(project_id)]
1125
+
1126
+ response = request(
1127
+ method: "POST",
1128
+ url: method_url,
1129
+ headers: headers,
1130
+ params: params,
1131
+ form: form_data,
1132
+ accept_json: true
1133
+ )
1134
+ response
1135
+ end
1136
+
1137
+ ##
1138
+ # @!method get_enrichment(project_id:, enrichment_id:)
1139
+ # Get enrichment.
1140
+ # Get details about a specific enrichment.
1141
+ # @param project_id [String] The ID of the project. This information can be found from the deploy page of the
1142
+ # Discovery administrative tooling.
1143
+ # @param enrichment_id [String] The ID of the enrichment.
1144
+ # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
1145
+ def get_enrichment(project_id:, enrichment_id:)
1146
+ raise ArgumentError.new("version must be provided") if version.nil?
1147
+
1148
+ raise ArgumentError.new("project_id must be provided") if project_id.nil?
1149
+
1150
+ raise ArgumentError.new("enrichment_id must be provided") if enrichment_id.nil?
1151
+
1152
+ headers = {
1153
+ }
1154
+ sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "get_enrichment")
1155
+ headers.merge!(sdk_headers)
1156
+
1157
+ params = {
1158
+ "version" => @version
1159
+ }
1160
+
1161
+ method_url = "/v2/projects/%s/enrichments/%s" % [ERB::Util.url_encode(project_id), ERB::Util.url_encode(enrichment_id)]
1162
+
1163
+ response = request(
1164
+ method: "GET",
1165
+ url: method_url,
1166
+ headers: headers,
1167
+ params: params,
1168
+ accept_json: true
1169
+ )
1170
+ response
1171
+ end
1172
+
1173
+ ##
1174
+ # @!method update_enrichment(project_id:, enrichment_id:, name:, description: nil)
1175
+ # Update an enrichment.
1176
+ # Updates an existing enrichment's name and description.
1177
+ # @param project_id [String] The ID of the project. This information can be found from the deploy page of the
1178
+ # Discovery administrative tooling.
1179
+ # @param enrichment_id [String] The ID of the enrichment.
1180
+ # @param name [String] A new name for the enrichment.
1181
+ # @param description [String] A new description for the enrichment.
1182
+ # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
1183
+ def update_enrichment(project_id:, enrichment_id:, name:, description: nil)
1184
+ raise ArgumentError.new("version must be provided") if version.nil?
1185
+
1186
+ raise ArgumentError.new("project_id must be provided") if project_id.nil?
1187
+
1188
+ raise ArgumentError.new("enrichment_id must be provided") if enrichment_id.nil?
1189
+
1190
+ raise ArgumentError.new("name must be provided") if name.nil?
1191
+
1192
+ headers = {
1193
+ }
1194
+ sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "update_enrichment")
1195
+ headers.merge!(sdk_headers)
1196
+
1197
+ params = {
1198
+ "version" => @version
1199
+ }
1200
+
1201
+ data = {
1202
+ "name" => name,
1203
+ "description" => description
1204
+ }
1205
+
1206
+ method_url = "/v2/projects/%s/enrichments/%s" % [ERB::Util.url_encode(project_id), ERB::Util.url_encode(enrichment_id)]
1207
+
1208
+ response = request(
1209
+ method: "POST",
1210
+ url: method_url,
1211
+ headers: headers,
1212
+ params: params,
1213
+ json: data,
1214
+ accept_json: true
1215
+ )
1216
+ response
1217
+ end
1218
+
1219
+ ##
1220
+ # @!method delete_enrichment(project_id:, enrichment_id:)
1221
+ # Delete an enrichment.
1222
+ # Deletes an existing enrichment from the specified project.
1223
+ #
1224
+ # **Note:** Only enrichments that have been manually created can be deleted.
1225
+ # @param project_id [String] The ID of the project. This information can be found from the deploy page of the
1226
+ # Discovery administrative tooling.
1227
+ # @param enrichment_id [String] The ID of the enrichment.
1228
+ # @return [nil]
1229
+ def delete_enrichment(project_id:, enrichment_id:)
1230
+ raise ArgumentError.new("version must be provided") if version.nil?
1231
+
1232
+ raise ArgumentError.new("project_id must be provided") if project_id.nil?
1233
+
1234
+ raise ArgumentError.new("enrichment_id must be provided") if enrichment_id.nil?
1235
+
1236
+ headers = {
1237
+ }
1238
+ sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "delete_enrichment")
1239
+ headers.merge!(sdk_headers)
1240
+
1241
+ params = {
1242
+ "version" => @version
1243
+ }
1244
+
1245
+ method_url = "/v2/projects/%s/enrichments/%s" % [ERB::Util.url_encode(project_id), ERB::Util.url_encode(enrichment_id)]
1246
+
1247
+ request(
1248
+ method: "DELETE",
1249
+ url: method_url,
1250
+ headers: headers,
1251
+ params: params,
1252
+ accept_json: false
1253
+ )
1254
+ nil
1255
+ end
1256
+ #########################
1257
+ # projects
1258
+ #########################
1259
+
1260
+ ##
1261
+ # @!method list_projects
1262
+ # List projects.
1263
+ # Lists existing projects for this instance.
1264
+ # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
1265
+ def list_projects
1266
+ raise ArgumentError.new("version must be provided") if version.nil?
1267
+
1268
+ headers = {
1269
+ }
1270
+ sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "list_projects")
1271
+ headers.merge!(sdk_headers)
1272
+
1273
+ params = {
1274
+ "version" => @version
1275
+ }
1276
+
1277
+ method_url = "/v2/projects"
1278
+
1279
+ response = request(
1280
+ method: "GET",
1281
+ url: method_url,
1282
+ headers: headers,
1283
+ params: params,
1284
+ accept_json: true
1285
+ )
1286
+ response
1287
+ end
1288
+
1289
+ ##
1290
+ # @!method create_project(name:, type:, default_query_parameters: nil)
1291
+ # Create a Project.
1292
+ # Create a new project for this instance.
1293
+ # @param name [String] The human readable name of this project.
1294
+ # @param type [String] The project type of this project.
1295
+ # @param default_query_parameters [DefaultQueryParams] Default query parameters for this project.
1296
+ # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
1297
+ def create_project(name:, type:, default_query_parameters: nil)
1298
+ raise ArgumentError.new("version must be provided") if version.nil?
1299
+
1300
+ raise ArgumentError.new("name must be provided") if name.nil?
1301
+
1302
+ raise ArgumentError.new("type must be provided") if type.nil?
1303
+
1304
+ headers = {
1305
+ }
1306
+ sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "create_project")
1307
+ headers.merge!(sdk_headers)
1308
+
1309
+ params = {
1310
+ "version" => @version
1311
+ }
1312
+
1313
+ data = {
1314
+ "name" => name,
1315
+ "type" => type,
1316
+ "default_query_parameters" => default_query_parameters
1317
+ }
1318
+
1319
+ method_url = "/v2/projects"
1320
+
1321
+ response = request(
1322
+ method: "POST",
1323
+ url: method_url,
1324
+ headers: headers,
1325
+ params: params,
1326
+ json: data,
1327
+ accept_json: true
1328
+ )
1329
+ response
1330
+ end
1331
+
1332
+ ##
1333
+ # @!method get_project(project_id:)
1334
+ # Get project.
1335
+ # Get details on the specified project.
1336
+ # @param project_id [String] The ID of the project. This information can be found from the deploy page of the
1337
+ # Discovery administrative tooling.
1338
+ # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
1339
+ def get_project(project_id:)
1340
+ raise ArgumentError.new("version must be provided") if version.nil?
1341
+
1342
+ raise ArgumentError.new("project_id must be provided") if project_id.nil?
1343
+
1344
+ headers = {
1345
+ }
1346
+ sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "get_project")
1347
+ headers.merge!(sdk_headers)
1348
+
1349
+ params = {
1350
+ "version" => @version
1351
+ }
1352
+
1353
+ method_url = "/v2/projects/%s" % [ERB::Util.url_encode(project_id)]
1354
+
1355
+ response = request(
1356
+ method: "GET",
1357
+ url: method_url,
1358
+ headers: headers,
1359
+ params: params,
1360
+ accept_json: true
1361
+ )
1362
+ response
1363
+ end
1364
+
1365
+ ##
1366
+ # @!method update_project(project_id:, name: nil)
1367
+ # Update a project.
1368
+ # Update the specified project's name.
1369
+ # @param project_id [String] The ID of the project. This information can be found from the deploy page of the
1370
+ # Discovery administrative tooling.
1371
+ # @param name [String] The new name to give this project.
1372
+ # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
1373
+ def update_project(project_id:, name: nil)
1374
+ raise ArgumentError.new("version must be provided") if version.nil?
1375
+
1376
+ raise ArgumentError.new("project_id must be provided") if project_id.nil?
1377
+
1378
+ headers = {
1379
+ }
1380
+ sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "update_project")
1381
+ headers.merge!(sdk_headers)
1382
+
1383
+ params = {
1384
+ "version" => @version
1385
+ }
1386
+
1387
+ data = {
1388
+ "name" => name
1389
+ }
1390
+
1391
+ method_url = "/v2/projects/%s" % [ERB::Util.url_encode(project_id)]
1392
+
1393
+ response = request(
1394
+ method: "POST",
1395
+ url: method_url,
1396
+ headers: headers,
1397
+ params: params,
1398
+ json: data,
1399
+ accept_json: true
1400
+ )
1401
+ response
1402
+ end
1403
+
1404
+ ##
1405
+ # @!method delete_project(project_id:)
1406
+ # Delete a project.
1407
+ # Deletes the specified project.
1408
+ #
1409
+ # **Important:** Deleting a project deletes everything that is part of the specified
1410
+ # project, including all collections.
1411
+ # @param project_id [String] The ID of the project. This information can be found from the deploy page of the
1412
+ # Discovery administrative tooling.
1413
+ # @return [nil]
1414
+ def delete_project(project_id:)
1415
+ raise ArgumentError.new("version must be provided") if version.nil?
1416
+
1417
+ raise ArgumentError.new("project_id must be provided") if project_id.nil?
1418
+
1419
+ headers = {
1420
+ }
1421
+ sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "delete_project")
1422
+ headers.merge!(sdk_headers)
1423
+
1424
+ params = {
1425
+ "version" => @version
1426
+ }
1427
+
1428
+ method_url = "/v2/projects/%s" % [ERB::Util.url_encode(project_id)]
1429
+
1430
+ request(
1431
+ method: "DELETE",
1432
+ url: method_url,
1433
+ headers: headers,
1434
+ params: params,
1435
+ accept_json: false
1436
+ )
1437
+ nil
1438
+ end
1439
+ #########################
1440
+ # userData
1441
+ #########################
1442
+
1443
+ ##
1444
+ # @!method delete_user_data(customer_id:)
1445
+ # Delete labeled data.
1446
+ # Deletes all data associated with a specified customer ID. The method has no effect
1447
+ # if no data is associated with the customer ID.
1448
+ #
1449
+ # You associate a customer ID with data by passing the **X-Watson-Metadata** header
1450
+ # with a request that passes data. For more information about personal data and
1451
+ # customer IDs, see [Information
1452
+ # security](https://cloud.ibm.com/docs/discovery-data?topic=discovery-data-information-security#information-security).
1453
+ #
1454
+ #
1455
+ # **Note:** This method is only supported on IBM Cloud instances of Discovery.
1456
+ # @param customer_id [String] The customer ID for which all data is to be deleted.
1457
+ # @return [nil]
1458
+ def delete_user_data(customer_id:)
1459
+ raise ArgumentError.new("version must be provided") if version.nil?
1460
+
1461
+ raise ArgumentError.new("customer_id must be provided") if customer_id.nil?
1462
+
1463
+ headers = {
1464
+ }
1465
+ sdk_headers = Common.new.get_sdk_headers("discovery", "V2", "delete_user_data")
1466
+ headers.merge!(sdk_headers)
1467
+
1468
+ params = {
1469
+ "version" => @version,
1470
+ "customer_id" => customer_id
1471
+ }
1472
+
1473
+ method_url = "/v2/user_data"
1474
+
1475
+ request(
1476
+ method: "DELETE",
1477
+ url: method_url,
1478
+ headers: headers,
1479
+ params: params,
1480
+ accept_json: false
1481
+ )
1482
+ nil
1483
+ end
777
1484
  end
778
1485
  end