ibm_watson 0.16.1 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -55,16 +55,16 @@ module IBMWatson
55
55
  # ready for a later version.
56
56
  # @option args url [String] The base url to use when contacting the service (e.g.
57
57
  # "https://gateway.watsonplatform.net/tone-analyzer/api").
58
- # The base url may differ between Bluemix regions.
58
+ # The base url may differ between IBM Cloud regions.
59
59
  # @option args username [String] The username used to authenticate with the service.
60
60
  # Username and password credentials are only required to run your
61
- # application locally or outside of Bluemix. When running on
62
- # Bluemix, the credentials will be automatically loaded from the
61
+ # application locally or outside of IBM Cloud. When running on
62
+ # IBM Cloud, the credentials will be automatically loaded from the
63
63
  # `VCAP_SERVICES` environment variable.
64
64
  # @option args password [String] The password used to authenticate with the service.
65
65
  # Username and password credentials are only required to run your
66
- # application locally or outside of Bluemix. When running on
67
- # Bluemix, the credentials will be automatically loaded from the
66
+ # application locally or outside of IBM Cloud. When running on
67
+ # IBM Cloud, the credentials will be automatically loaded from the
68
68
  # `VCAP_SERVICES` environment variable.
69
69
  # @option args iam_apikey [String] An API key that can be used to request IAM tokens. If
70
70
  # this API key is provided, the SDK will manage the token and handle the
@@ -74,7 +74,9 @@ module IBMWatson
74
74
  # it expires or reactively upon receiving a 401 from the service as any requests
75
75
  # made with an expired token will fail.
76
76
  # @option args iam_url [String] An optional URL for the IAM service API. Defaults to
77
- # 'https://iam.ng.bluemix.net/identity/token'.
77
+ # 'https://iam.cloud.ibm.com/identity/token'.
78
+ # @option args iam_client_id [String] An optional client id for the IAM service API.
79
+ # @option args iam_client_secret [String] An optional client secret for the IAM service API.
78
80
  def initialize(args = {})
79
81
  @__async_initialized__ = false
80
82
  defaults = {}
@@ -85,6 +87,8 @@ module IBMWatson
85
87
  defaults[:iam_apikey] = nil
86
88
  defaults[:iam_access_token] = nil
87
89
  defaults[:iam_url] = nil
90
+ defaults[:iam_client_id] = nil
91
+ defaults[:iam_client_secret] = nil
88
92
  args = defaults.merge(args)
89
93
  args[:vcap_services_name] = "tone_analyzer"
90
94
  super
@@ -99,7 +103,7 @@ module IBMWatson
99
103
  ##
100
104
  # @!method tone(tone_input:, sentences: nil, tones: nil, content_language: nil, accept_language: nil, content_type: nil)
101
105
  # Analyze general tone.
102
- # Use the general purpose endpoint to analyze the tone of your input content. The
106
+ # Use the general-purpose endpoint to analyze the tone of your input content. The
103
107
  # service analyzes the content for emotional and language tones. The method always
104
108
  # analyzes the tone of the full document; by default, it also analyzes the tone of
105
109
  # each individual sentence of the content.
@@ -118,7 +122,7 @@ module IBMWatson
118
122
  # analyzes only the textual content.
119
123
  #
120
124
  # **See also:** [Using the general-purpose
121
- # endpoint](https://cloud.ibm.com/docs/services/tone-analyzer/using-tone.html#using-the-general-purpose-endpoint).
125
+ # endpoint](https://cloud.ibm.com/docs/services/tone-analyzer?topic=tone-analyzer-utgpe#utgpe).
122
126
  # @param tone_input [ToneInput] JSON, plain text, or HTML input that contains the content to be analyzed. For JSON
123
127
  # input, provide an object of type `ToneInput`.
124
128
  # @param sentences [Boolean] Indicates whether the service is to return an analysis of each individual sentence
@@ -183,8 +187,8 @@ module IBMWatson
183
187
 
184
188
  ##
185
189
  # @!method tone_chat(utterances:, content_language: nil, accept_language: nil)
186
- # Analyze customer engagement tone.
187
- # Use the customer engagement endpoint to analyze the tone of customer service and
190
+ # Analyze customer-engagement tone.
191
+ # Use the customer-engagement endpoint to analyze the tone of customer service and
188
192
  # customer support conversations. For each utterance of a conversation, the method
189
193
  # reports the most prevalent subset of the following seven tones: sad, frustrated,
190
194
  # satisfied, excited, polite, impolite, and sympathetic.
@@ -197,7 +201,7 @@ module IBMWatson
197
201
  # character encoding for JSON content is effectively always UTF-8.
198
202
  #
199
203
  # **See also:** [Using the customer-engagement
200
- # endpoint](https://cloud.ibm.com/docs/services/tone-analyzer/using-tone-chat.html#using-the-customer-engagement-endpoint).
204
+ # endpoint](https://cloud.ibm.com/docs/services/tone-analyzer?topic=tone-analyzer-utco#utco).
201
205
  # @param utterances [Array[Utterance]] An array of `Utterance` objects that provides the input content that the service
202
206
  # is to analyze.
203
207
  # @param content_language [String] The language of the input text for the request: English or French. Regional
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IBMWatson
4
- VERSION = "0.16.1"
4
+ VERSION = "0.17.0"
5
5
  end
@@ -47,7 +47,7 @@ module IBMWatson
47
47
  # ready for a later version.
48
48
  # @option args url [String] The base url to use when contacting the service (e.g.
49
49
  # "https://gateway.watsonplatform.net/visual-recognition/api").
50
- # The base url may differ between Bluemix regions.
50
+ # The base url may differ between IBM Cloud regions.
51
51
  # @option args iam_apikey [String] An API key that can be used to request IAM tokens. If
52
52
  # this API key is provided, the SDK will manage the token and handle the
53
53
  # refreshing.
@@ -56,7 +56,9 @@ module IBMWatson
56
56
  # it expires or reactively upon receiving a 401 from the service as any requests
57
57
  # made with an expired token will fail.
58
58
  # @option args iam_url [String] An optional URL for the IAM service API. Defaults to
59
- # 'https://iam.ng.bluemix.net/identity/token'.
59
+ # 'https://iam.cloud.ibm.com/identity/token'.
60
+ # @option args iam_client_id [String] An optional client id for the IAM service API.
61
+ # @option args iam_client_secret [String] An optional client secret for the IAM service API.
60
62
  def initialize(args = {})
61
63
  @__async_initialized__ = false
62
64
  defaults = {}
@@ -65,6 +67,8 @@ module IBMWatson
65
67
  defaults[:iam_apikey] = nil
66
68
  defaults[:iam_access_token] = nil
67
69
  defaults[:iam_url] = nil
70
+ defaults[:iam_client_id] = nil
71
+ defaults[:iam_client_secret] = nil
68
72
  args = defaults.merge(args)
69
73
  args[:vcap_services_name] = "watson_vision_combined"
70
74
  super
@@ -169,11 +173,11 @@ module IBMWatson
169
173
  # to the Face model was removed. The identity information refers to the `name` of
170
174
  # the person, `score`, and `type_hierarchy` knowledge graph. For details about the
171
175
  # enhanced Face model, see the [Release
172
- # notes](https://cloud.ibm.com/docs/services/visual-recognition/release-notes.html#2april2018).
176
+ # notes](https://cloud.ibm.com/docs/services/visual-recognition?topic=visual-recognition-release-notes#2april2018).
173
177
  #
174
178
  # Analyze and get data about faces in images. Responses can include estimated age
175
179
  # and gender. This feature uses a built-in model, so no training is necessary. The
176
- # Detect faces method does not support general biometric facial recognition.
180
+ # **Detect faces** method does not support general biometric facial recognition.
177
181
  #
178
182
  # Supported image formats include .gif, .jpg, .png, and .tif. The maximum image size
179
183
  # is 10 MB. The minimum recommended pixel density is 32X32 pixels, but the service
@@ -315,32 +319,32 @@ module IBMWatson
315
319
  end
316
320
 
317
321
  ##
318
- # @!method delete_classifier(classifier_id:)
319
- # Delete a classifier.
320
- # @param classifier_id [String] The ID of the classifier.
321
- # @return [nil]
322
- def delete_classifier(classifier_id:)
323
- raise ArgumentError.new("classifier_id must be provided") if classifier_id.nil?
324
-
322
+ # @!method list_classifiers(verbose: nil)
323
+ # Retrieve a list of classifiers.
324
+ # @param verbose [Boolean] Specify `true` to return details about the classifiers. Omit this parameter to
325
+ # return a brief list of classifiers.
326
+ # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
327
+ def list_classifiers(verbose: nil)
325
328
  headers = {
326
329
  }
327
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V3", "delete_classifier")
330
+ sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V3", "list_classifiers")
328
331
  headers.merge!(sdk_headers)
329
332
 
330
333
  params = {
331
- "version" => @version
334
+ "version" => @version,
335
+ "verbose" => verbose
332
336
  }
333
337
 
334
- method_url = "/v3/classifiers/%s" % [ERB::Util.url_encode(classifier_id)]
338
+ method_url = "/v3/classifiers"
335
339
 
336
- request(
337
- method: "DELETE",
340
+ response = request(
341
+ method: "GET",
338
342
  url: method_url,
339
343
  headers: headers,
340
344
  params: params,
341
345
  accept_json: true
342
346
  )
343
- nil
347
+ response
344
348
  end
345
349
 
346
350
  ##
@@ -373,42 +377,13 @@ module IBMWatson
373
377
  response
374
378
  end
375
379
 
376
- ##
377
- # @!method list_classifiers(verbose: nil)
378
- # Retrieve a list of classifiers.
379
- # @param verbose [Boolean] Specify `true` to return details about the classifiers. Omit this parameter to
380
- # return a brief list of classifiers.
381
- # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
382
- def list_classifiers(verbose: nil)
383
- headers = {
384
- }
385
- sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V3", "list_classifiers")
386
- headers.merge!(sdk_headers)
387
-
388
- params = {
389
- "version" => @version,
390
- "verbose" => verbose
391
- }
392
-
393
- method_url = "/v3/classifiers"
394
-
395
- response = request(
396
- method: "GET",
397
- url: method_url,
398
- headers: headers,
399
- params: params,
400
- accept_json: true
401
- )
402
- response
403
- end
404
-
405
380
  ##
406
381
  # @!method update_classifier(classifier_id:, positive_examples: nil, negative_examples: nil, negative_examples_filename: nil)
407
382
  # Update a classifier.
408
383
  # Update a custom classifier by adding new positive or negative classes or by adding
409
384
  # new images to existing classes. You must supply at least one set of positive or
410
385
  # negative examples. For details, see [Updating custom
411
- # classifiers](https://cloud.ibm.com/docs/services/visual-recognition/customizing.html#updating-custom-classifiers).
386
+ # classifiers](https://cloud.ibm.com/docs/services/visual-recognition?topic=visual-recognition-customizing#updating-custom-classifiers).
412
387
  #
413
388
  # Encode all names in UTF-8 if they contain non-ASCII characters (.zip and image
414
389
  # file names, and classifier and class names). The service assumes UTF-8 encoding if
@@ -483,6 +458,35 @@ module IBMWatson
483
458
  )
484
459
  response
485
460
  end
461
+
462
+ ##
463
+ # @!method delete_classifier(classifier_id:)
464
+ # Delete a classifier.
465
+ # @param classifier_id [String] The ID of the classifier.
466
+ # @return [nil]
467
+ def delete_classifier(classifier_id:)
468
+ raise ArgumentError.new("classifier_id must be provided") if classifier_id.nil?
469
+
470
+ headers = {
471
+ }
472
+ sdk_headers = Common.new.get_sdk_headers("watson_vision_combined", "V3", "delete_classifier")
473
+ headers.merge!(sdk_headers)
474
+
475
+ params = {
476
+ "version" => @version
477
+ }
478
+
479
+ method_url = "/v3/classifiers/%s" % [ERB::Util.url_encode(classifier_id)]
480
+
481
+ request(
482
+ method: "DELETE",
483
+ url: method_url,
484
+ headers: headers,
485
+ params: params,
486
+ accept_json: true
487
+ )
488
+ nil
489
+ end
486
490
  #########################
487
491
  # Core ML
488
492
  #########################
@@ -530,7 +534,7 @@ module IBMWatson
530
534
  # You associate a customer ID with data by passing the `X-Watson-Metadata` header
531
535
  # with a request that passes data. For more information about personal data and
532
536
  # customer IDs, see [Information
533
- # security](https://cloud.ibm.com/docs/services/visual-recognition/information-security.html).
537
+ # security](https://cloud.ibm.com/docs/services/visual-recognition?topic=visual-recognition-information-security).
534
538
  # @param customer_id [String] The customer ID for which all data is to be deleted.
535
539
  # @return [nil]
536
540
  def delete_user_data(customer_id:)
@@ -17,7 +17,6 @@ if !ENV["LANGUAGE_TRANSLATOR_APIKEY"].nil? && !ENV["LANGUAGE_TRANSLATOR_URL"].ni
17
17
  )
18
18
  @service.add_default_headers(
19
19
  headers: {
20
- "X-Watson-Learning-Opt-Out" => "1",
21
20
  "X-Watson-Test" => "1"
22
21
  }
23
22
  )
@@ -59,6 +58,43 @@ if !ENV["LANGUAGE_TRANSLATOR_APIKEY"].nil? && !ENV["LANGUAGE_TRANSLATOR_URL"].ni
59
58
  refute(service_response.nil?)
60
59
  end
61
60
 
61
+ def test_translate_document
62
+ @service = IBMWatson::LanguageTranslatorV3.new(
63
+ iam_apikey: ENV["LANGUAGE_TRANSLATOR_APIKEY"],
64
+ url: ENV["LANGUAGE_TRANSLATOR_URL"],
65
+ version: "2018-05-01"
66
+ )
67
+ @service.add_default_headers(
68
+ headers: {
69
+ "X-Watson-Test" => "1"
70
+ }
71
+ )
72
+
73
+ File.open(Dir.getwd + "/resources/translation_doc.txt") do |file_info|
74
+ service_response = service.translate_document(
75
+ file: file_info,
76
+ filename: "translation_doc.txt",
77
+ model_id: "en-fr"
78
+ ).result
79
+ refute(service_response.nil?)
80
+ end
81
+ end
82
+
83
+ def test_list_documents
84
+ @service = IBMWatson::LanguageTranslatorV3.new(
85
+ iam_apikey: ENV["LANGUAGE_TRANSLATOR_APIKEY"],
86
+ url: ENV["LANGUAGE_TRANSLATOR_URL"],
87
+ version: "2018-05-01"
88
+ )
89
+ @service.add_default_headers(
90
+ headers: {
91
+ "X-Watson-Test" => "1"
92
+ }
93
+ )
94
+ service_response = service.list_documents.result
95
+ refute(service_response.nil?)
96
+ end
97
+
62
98
  def test_list_identifiable_languages
63
99
  service_response = service.list_identifiable_languages.result
64
100
  refute(service_response.nil?)
@@ -9,14 +9,14 @@ WebMock.disable_net_connect!(allow_localhost: true)
9
9
  # Unit tests for the Language Translator V3 Service
10
10
  class LanguageTranslatorV3Test < Minitest::Test
11
11
  def test_translate_source_target
12
- stub_request(:post, "https://iam.bluemix.net/identity/token")
12
+ stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
13
13
  .with(
14
14
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
15
15
  headers: {
16
16
  "Accept" => "application/json",
17
17
  "Authorization" => "Basic Yng6Yng=",
18
18
  "Content-Type" => "application/x-www-form-urlencoded",
19
- "Host" => "iam.bluemix.net"
19
+ "Host" => "iam.cloud.ibm.com"
20
20
  }
21
21
  ).to_return(
22
22
  status: 200,
@@ -57,14 +57,14 @@ class LanguageTranslatorV3Test < Minitest::Test
57
57
  end
58
58
 
59
59
  def test_translate_model_id
60
- stub_request(:post, "https://iam.bluemix.net/identity/token")
60
+ stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
61
61
  .with(
62
62
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
63
63
  headers: {
64
64
  "Accept" => "application/json",
65
65
  "Authorization" => "Basic Yng6Yng=",
66
66
  "Content-Type" => "application/x-www-form-urlencoded",
67
- "Host" => "iam.bluemix.net"
67
+ "Host" => "iam.cloud.ibm.com"
68
68
  }
69
69
  ).to_return(
70
70
  status: 200,
@@ -108,14 +108,14 @@ class LanguageTranslatorV3Test < Minitest::Test
108
108
  end
109
109
 
110
110
  def test_identify
111
- stub_request(:post, "https://iam.bluemix.net/identity/token")
111
+ stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
112
112
  .with(
113
113
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
114
114
  headers: {
115
115
  "Accept" => "application/json",
116
116
  "Authorization" => "Basic Yng6Yng=",
117
117
  "Content-Type" => "application/x-www-form-urlencoded",
118
- "Host" => "iam.bluemix.net"
118
+ "Host" => "iam.cloud.ibm.com"
119
119
  }
120
120
  ).to_return(
121
121
  status: 200,
@@ -165,14 +165,14 @@ class LanguageTranslatorV3Test < Minitest::Test
165
165
  end
166
166
 
167
167
  def test_list_identifiable_languages
168
- stub_request(:post, "https://iam.bluemix.net/identity/token")
168
+ stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
169
169
  .with(
170
170
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
171
171
  headers: {
172
172
  "Accept" => "application/json",
173
173
  "Authorization" => "Basic Yng6Yng=",
174
174
  "Content-Type" => "application/x-www-form-urlencoded",
175
- "Host" => "iam.bluemix.net"
175
+ "Host" => "iam.cloud.ibm.com"
176
176
  }
177
177
  ).to_return(
178
178
  status: 200,
@@ -230,14 +230,14 @@ class LanguageTranslatorV3Test < Minitest::Test
230
230
  end
231
231
 
232
232
  def test_create_model
233
- stub_request(:post, "https://iam.bluemix.net/identity/token")
233
+ stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
234
234
  .with(
235
235
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
236
236
  headers: {
237
237
  "Accept" => "application/json",
238
238
  "Authorization" => "Basic Yng6Yng=",
239
239
  "Content-Type" => "application/x-www-form-urlencoded",
240
- "Host" => "iam.bluemix.net"
240
+ "Host" => "iam.cloud.ibm.com"
241
241
  }
242
242
  ).to_return(
243
243
  status: 200,
@@ -300,14 +300,14 @@ class LanguageTranslatorV3Test < Minitest::Test
300
300
  end
301
301
 
302
302
  def test_delete_model
303
- stub_request(:post, "https://iam.bluemix.net/identity/token")
303
+ stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
304
304
  .with(
305
305
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
306
306
  headers: {
307
307
  "Accept" => "application/json",
308
308
  "Authorization" => "Basic Yng6Yng=",
309
309
  "Content-Type" => "application/x-www-form-urlencoded",
310
- "Host" => "iam.bluemix.net"
310
+ "Host" => "iam.cloud.ibm.com"
311
311
  }
312
312
  ).to_return(
313
313
  status: 200,
@@ -342,14 +342,14 @@ class LanguageTranslatorV3Test < Minitest::Test
342
342
  end
343
343
 
344
344
  def test_get_model
345
- stub_request(:post, "https://iam.bluemix.net/identity/token")
345
+ stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
346
346
  .with(
347
347
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
348
348
  headers: {
349
349
  "Accept" => "application/json",
350
350
  "Authorization" => "Basic Yng6Yng=",
351
351
  "Content-Type" => "application/x-www-form-urlencoded",
352
- "Host" => "iam.bluemix.net"
352
+ "Host" => "iam.cloud.ibm.com"
353
353
  }
354
354
  ).to_return(
355
355
  status: 200,
@@ -393,14 +393,14 @@ class LanguageTranslatorV3Test < Minitest::Test
393
393
  end
394
394
 
395
395
  def test_list_models
396
- stub_request(:post, "https://iam.bluemix.net/identity/token")
396
+ stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
397
397
  .with(
398
398
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
399
399
  headers: {
400
400
  "Accept" => "application/json",
401
401
  "Authorization" => "Basic Yng6Yng=",
402
402
  "Content-Type" => "application/x-www-form-urlencoded",
403
- "Host" => "iam.bluemix.net"
403
+ "Host" => "iam.cloud.ibm.com"
404
404
  }
405
405
  ).to_return(
406
406
  status: 200,
@@ -456,4 +456,189 @@ class LanguageTranslatorV3Test < Minitest::Test
456
456
  service_response = service.list_models
457
457
  assert_equal(expected, service_response.result)
458
458
  end
459
+
460
+ def test_lis_documents
461
+ stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
462
+ .with(
463
+ body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
464
+ headers: {
465
+ "Accept" => "application/json",
466
+ "Authorization" => "Basic Yng6Yng=",
467
+ "Content-Type" => "application/x-www-form-urlencoded",
468
+ "Host" => "iam.cloud.ibm.com"
469
+ }
470
+ ).to_return(
471
+ status: 200,
472
+ body: {
473
+ "access_token" => "oAeisG8yqPY7sFR_x66Z15",
474
+ "token_type" => "Bearer",
475
+ "expires_in" => 3600,
476
+ "expiration" => 1_524_167_011,
477
+ "refresh_token" => "jy4gl91BQ"
478
+ }.to_json,
479
+ headers: {}
480
+ )
481
+ service = IBMWatson::LanguageTranslatorV3.new(
482
+ version: "2018-05-01",
483
+ iam_apikey: "iam_apikey"
484
+ )
485
+ expected = {}
486
+ stub_request(:get, "https://gateway.watsonplatform.net/language-translator/api/v3/documents?version=2018-05-01")
487
+ .with(
488
+ headers: {
489
+ "Accept" => "application/json",
490
+ "Authorization" => "Bearer oAeisG8yqPY7sFR_x66Z15",
491
+ "Host" => "gateway.watsonplatform.net"
492
+ }
493
+ ).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
494
+ service_response = service.list_documents
495
+ assert_equal(expected, service_response.result)
496
+ end
497
+
498
+ def test_translate_document
499
+ stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
500
+ .with(
501
+ body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
502
+ headers: {
503
+ "Accept" => "application/json",
504
+ "Authorization" => "Basic Yng6Yng=",
505
+ "Content-Type" => "application/x-www-form-urlencoded",
506
+ "Host" => "iam.cloud.ibm.com"
507
+ }
508
+ ).to_return(
509
+ status: 200,
510
+ body: {
511
+ "access_token" => "oAeisG8yqPY7sFR_x66Z15",
512
+ "token_type" => "Bearer",
513
+ "expires_in" => 3600,
514
+ "expiration" => 1_524_167_011,
515
+ "refresh_token" => "jy4gl91BQ"
516
+ }.to_json,
517
+ headers: {}
518
+ )
519
+ service = IBMWatson::LanguageTranslatorV3.new(
520
+ version: "2018-05-01",
521
+ iam_apikey: "iam_apikey"
522
+ )
523
+ stub_request(:post, "https://gateway.watsonplatform.net/language-translator/api/v3/documents?version=2018-05-01")
524
+ .with do |req|
525
+ assert_equal req.headers["Accept"], "application/json"
526
+ assert_match %r{\Amultipart/form-data}, req.headers["Content-Type"]
527
+ end
528
+ file = File.open(Dir.getwd + "/resources/translation_doc.txt")
529
+ service.translate_document(file: file, filename: "file")
530
+ end
531
+
532
+ def test_get_document_status
533
+ stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
534
+ .with(
535
+ body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
536
+ headers: {
537
+ "Accept" => "application/json",
538
+ "Authorization" => "Basic Yng6Yng=",
539
+ "Content-Type" => "application/x-www-form-urlencoded",
540
+ "Host" => "iam.cloud.ibm.com"
541
+ }
542
+ ).to_return(
543
+ status: 200,
544
+ body: {
545
+ "access_token" => "oAeisG8yqPY7sFR_x66Z15",
546
+ "token_type" => "Bearer",
547
+ "expires_in" => 3600,
548
+ "expiration" => 1_524_167_011,
549
+ "refresh_token" => "jy4gl91BQ"
550
+ }.to_json,
551
+ headers: {}
552
+ )
553
+ service = IBMWatson::LanguageTranslatorV3.new(
554
+ version: "2018-05-01",
555
+ iam_apikey: "iam_apikey"
556
+ )
557
+ expected = {}
558
+ stub_request(:get, "https://gateway.watsonplatform.net/language-translator/api/v3/documents/id?version=2018-05-01")
559
+ .with(
560
+ headers: {
561
+ "Accept" => "application/json",
562
+ "Authorization" => "Bearer oAeisG8yqPY7sFR_x66Z15",
563
+ "Host" => "gateway.watsonplatform.net"
564
+ }
565
+ ).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
566
+ service_response = service.get_document_status(document_id: "id")
567
+ assert_equal(expected, service_response.result)
568
+ end
569
+
570
+ def test_get_translated_document
571
+ stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
572
+ .with(
573
+ body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
574
+ headers: {
575
+ "Accept" => "application/json",
576
+ "Authorization" => "Basic Yng6Yng=",
577
+ "Content-Type" => "application/x-www-form-urlencoded",
578
+ "Host" => "iam.cloud.ibm.com"
579
+ }
580
+ ).to_return(
581
+ status: 200,
582
+ body: {
583
+ "access_token" => "oAeisG8yqPY7sFR_x66Z15",
584
+ "token_type" => "Bearer",
585
+ "expires_in" => 3600,
586
+ "expiration" => 1_524_167_011,
587
+ "refresh_token" => "jy4gl91BQ"
588
+ }.to_json,
589
+ headers: {}
590
+ )
591
+ service = IBMWatson::LanguageTranslatorV3.new(
592
+ version: "2018-05-01",
593
+ iam_apikey: "iam_apikey"
594
+ )
595
+ expected = {}
596
+ stub_request(:get, "https://gateway.watsonplatform.net/language-translator/api/v3/documents/id/translated_document?version=2018-05-01")
597
+ .with(
598
+ headers: {
599
+ "Accept" => "application/json",
600
+ "Authorization" => "Bearer oAeisG8yqPY7sFR_x66Z15",
601
+ "Host" => "gateway.watsonplatform.net"
602
+ }
603
+ ).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
604
+ service_response = service.get_translated_document(document_id: "id")
605
+ assert_equal(expected, service_response.result)
606
+ end
607
+
608
+ def test_delete_document
609
+ stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
610
+ .with(
611
+ body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
612
+ headers: {
613
+ "Accept" => "application/json",
614
+ "Authorization" => "Basic Yng6Yng=",
615
+ "Content-Type" => "application/x-www-form-urlencoded",
616
+ "Host" => "iam.cloud.ibm.com"
617
+ }
618
+ ).to_return(
619
+ status: 200,
620
+ body: {
621
+ "access_token" => "oAeisG8yqPY7sFR_x66Z15",
622
+ "token_type" => "Bearer",
623
+ "expires_in" => 3600,
624
+ "expiration" => 1_524_167_011,
625
+ "refresh_token" => "jy4gl91BQ"
626
+ }.to_json,
627
+ headers: {}
628
+ )
629
+ service = IBMWatson::LanguageTranslatorV3.new(
630
+ version: "2018-05-01",
631
+ iam_apikey: "iam_apikey"
632
+ )
633
+ expected = {}
634
+ stub_request(:delete, "https://gateway.watsonplatform.net/language-translator/api/v3/documents/id?version=2018-05-01")
635
+ .with(
636
+ headers: {
637
+ "Authorization" => "Bearer oAeisG8yqPY7sFR_x66Z15",
638
+ "Host" => "gateway.watsonplatform.net"
639
+ }
640
+ ).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
641
+ service_response = service.delete_document(document_id: "id")
642
+ assert_nil(service_response)
643
+ end
459
644
  end
@@ -280,7 +280,7 @@ class SpeechToTextV1Test < Minitest::Test
280
280
  service_response = service.train_language_model(
281
281
  customization_id: "customid"
282
282
  )
283
- assert_nil(service_response)
283
+ refute_nil(service_response)
284
284
 
285
285
  stub_request(:get, "https://stream.watsonplatform.net/speech-to-text/api/v1/customizations/modelid")
286
286
  .with(
@@ -353,7 +353,7 @@ class SpeechToTextV1Test < Minitest::Test
353
353
  service_response = service.train_acoustic_model(
354
354
  customization_id: "customid"
355
355
  )
356
- assert_nil(service_response)
356
+ refute_nil(service_response)
357
357
 
358
358
  stub_request(:get, "https://stream.watsonplatform.net/speech-to-text/api/v1/acoustic_customizations/modelid")
359
359
  .with(