ibm_watson 1.2.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +33 -5
  3. data/lib/ibm_watson/assistant_v1.rb +153 -209
  4. data/lib/ibm_watson/assistant_v2.rb +168 -15
  5. data/lib/ibm_watson/compare_comply_v1.rb +11 -5
  6. data/lib/ibm_watson/discovery_v1.rb +14 -8
  7. data/lib/ibm_watson/discovery_v2.rb +605 -12
  8. data/lib/ibm_watson/language_translator_v3.rb +166 -47
  9. data/lib/ibm_watson/natural_language_classifier_v1.rb +10 -4
  10. data/lib/ibm_watson/natural_language_understanding_v1.rb +19 -15
  11. data/lib/ibm_watson/personality_insights_v3.rb +17 -11
  12. data/lib/ibm_watson/speech_to_text_v1.rb +323 -195
  13. data/lib/ibm_watson/text_to_speech_v1.rb +75 -59
  14. data/lib/ibm_watson/tone_analyzer_v3.rb +11 -5
  15. data/lib/ibm_watson/version.rb +1 -1
  16. data/lib/ibm_watson/visual_recognition_v3.rb +11 -5
  17. data/lib/ibm_watson/visual_recognition_v4.rb +199 -4
  18. data/test/integration/test_assistant_v2.rb +25 -0
  19. data/test/integration/test_compare_comply_v1.rb +1 -12
  20. data/test/integration/test_discovery_v2.rb +118 -6
  21. data/test/integration/test_language_translator_v3.rb +5 -0
  22. data/test/integration/test_speech_to_text_v1.rb +2 -0
  23. data/test/integration/test_visual_recognition_v4.rb +9 -0
  24. data/test/unit/test_assistant_v1.rb +98 -98
  25. data/test/unit/test_assistant_v2.rb +102 -8
  26. data/test/unit/test_compare_comply_v1.rb +20 -20
  27. data/test/unit/test_discovery_v1.rb +125 -125
  28. data/test/unit/test_discovery_v2.rb +262 -29
  29. data/test/unit/test_language_translator_v3.rb +85 -24
  30. data/test/unit/test_natural_language_classifier_v1.rb +17 -17
  31. data/test/unit/test_natural_language_understanding_v1.rb +10 -10
  32. data/test/unit/test_personality_insights_v3.rb +14 -10
  33. data/test/unit/test_speech_to_text_v1.rb +97 -97
  34. data/test/unit/test_text_to_speech_v1.rb +41 -41
  35. data/test/unit/test_tone_analyzer_v3.rb +12 -12
  36. data/test/unit/test_visual_recognition_v3.rb +16 -16
  37. data/test/unit/test_visual_recognition_v4.rb +117 -30
  38. metadata +5 -6
  39. data/test/unit/test_vcap_using_personality_insights.rb +0 -161
@@ -20,7 +20,7 @@ class VisualRecognitionV4Test < Minitest::Test
20
20
 
21
21
  def test_analyze
22
22
  file = File.open(Dir.getwd + "/resources/cnc_test.pdf")
23
- stub_request(:post, "https://gateway.watsonplatform.net/visual-recognition/api/v4/analyze?version=2018-03-19").with do |req|
23
+ stub_request(:post, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/analyze?version=2018-03-19").with do |req|
24
24
  assert_equal(req.headers["Accept"], "application/json")
25
25
  assert_match(%r{\Amultipart/form-data}, req.headers["Content-Type"])
26
26
  assert_match(/Content-Disposition: form-data/, req.body)
@@ -40,7 +40,7 @@ class VisualRecognitionV4Test < Minitest::Test
40
40
  end
41
41
 
42
42
  def test_analyze_url
43
- stub_request(:post, "https://gateway.watsonplatform.net/visual-recognition/api/v4/analyze?version=2018-03-19").with do |req|
43
+ stub_request(:post, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/analyze?version=2018-03-19").with do |req|
44
44
  assert_equal(req.headers["Accept"], "application/json")
45
45
  assert_match(%r{\Amultipart/form-data}, req.headers["Content-Type"])
46
46
  assert_match(/Content-Disposition: form-data; name="image_url"/, req.body)
@@ -67,11 +67,11 @@ class VisualRecognitionV4Test < Minitest::Test
67
67
  }
68
68
  ]
69
69
  }
70
- stub_request(:post, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections?version=2018-03-19")
70
+ stub_request(:post, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections?version=2018-03-19")
71
71
  .with(
72
72
  headers: {
73
73
  "Accept" => "application/json",
74
- "Host" => "gateway.watsonplatform.net"
74
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
75
75
  }
76
76
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
77
77
  service_response = service.create_collection(
@@ -85,11 +85,11 @@ class VisualRecognitionV4Test < Minitest::Test
85
85
  response = {
86
86
  "collections" => []
87
87
  }
88
- stub_request(:get, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections?version=2018-03-19")
88
+ stub_request(:get, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections?version=2018-03-19")
89
89
  .with(
90
90
  headers: {
91
91
  "Accept" => "application/json",
92
- "Host" => "gateway.watsonplatform.net"
92
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
93
93
  }
94
94
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
95
95
  service_response = service.list_collections
@@ -109,11 +109,11 @@ class VisualRecognitionV4Test < Minitest::Test
109
109
  }
110
110
  ]
111
111
  }
112
- stub_request(:get, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid?version=2018-03-19")
112
+ stub_request(:get, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid?version=2018-03-19")
113
113
  .with(
114
114
  headers: {
115
115
  "Accept" => "application/json",
116
- "Host" => "gateway.watsonplatform.net"
116
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
117
117
  }
118
118
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
119
119
  service_response = service.get_collection(
@@ -135,11 +135,11 @@ class VisualRecognitionV4Test < Minitest::Test
135
135
  }
136
136
  ]
137
137
  }
138
- stub_request(:post, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid?version=2018-03-19")
138
+ stub_request(:post, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid?version=2018-03-19")
139
139
  .with(
140
140
  headers: {
141
141
  "Accept" => "application/json",
142
- "Host" => "gateway.watsonplatform.net"
142
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
143
143
  }
144
144
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
145
145
  service_response = service.update_collection(
@@ -150,11 +150,11 @@ class VisualRecognitionV4Test < Minitest::Test
150
150
 
151
151
  def test_delete_collection
152
152
  response = {}
153
- stub_request(:delete, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid?version=2018-03-19")
153
+ stub_request(:delete, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid?version=2018-03-19")
154
154
  .with(
155
155
  headers: {
156
156
  "Accept" => "application/json",
157
- "Host" => "gateway.watsonplatform.net"
157
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
158
158
  }
159
159
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
160
160
  service_response = service.delete_collection(
@@ -168,11 +168,11 @@ class VisualRecognitionV4Test < Minitest::Test
168
168
  "collection_id" => "collid"
169
169
  }
170
170
  file = File.open(Dir.getwd + "/resources/cnc_test.pdf")
171
- stub_request(:post, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid/images?version=2018-03-19")
171
+ stub_request(:post, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/images?version=2018-03-19")
172
172
  .with(
173
173
  headers: {
174
174
  "Accept" => "application/json",
175
- "Host" => "gateway.watsonplatform.net"
175
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
176
176
  }
177
177
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
178
178
  service_response = service.add_images(
@@ -192,11 +192,11 @@ class VisualRecognitionV4Test < Minitest::Test
192
192
  response = {
193
193
  "collections" => []
194
194
  }
195
- stub_request(:get, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid/images?version=2018-03-19")
195
+ stub_request(:get, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/images?version=2018-03-19")
196
196
  .with(
197
197
  headers: {
198
198
  "Accept" => "application/json",
199
- "Host" => "gateway.watsonplatform.net"
199
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
200
200
  }
201
201
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
202
202
  service_response = service.list_images(
@@ -209,11 +209,11 @@ class VisualRecognitionV4Test < Minitest::Test
209
209
  response = {
210
210
  "collection_id" => "collid"
211
211
  }
212
- stub_request(:get, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid/images/imageid?version=2018-03-19")
212
+ stub_request(:get, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/images/imageid?version=2018-03-19")
213
213
  .with(
214
214
  headers: {
215
215
  "Accept" => "application/json",
216
- "Host" => "gateway.watsonplatform.net"
216
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
217
217
  }
218
218
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
219
219
  service_response = service.get_image_details(
@@ -225,11 +225,11 @@ class VisualRecognitionV4Test < Minitest::Test
225
225
 
226
226
  def test_delete_image
227
227
  response = {}
228
- stub_request(:delete, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid/images/imageid?version=2018-03-19")
228
+ stub_request(:delete, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/images/imageid?version=2018-03-19")
229
229
  .with(
230
230
  headers: {
231
231
  "Accept" => "application/json",
232
- "Host" => "gateway.watsonplatform.net"
232
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
233
233
  }
234
234
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
235
235
  service_response = service.delete_image(
@@ -243,10 +243,10 @@ class VisualRecognitionV4Test < Minitest::Test
243
243
  response = {
244
244
  "collection_id" => "collid"
245
245
  }
246
- stub_request(:get, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid/images/imageid/jpeg?version=2018-03-19")
246
+ stub_request(:get, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/images/imageid/jpeg?version=2018-03-19")
247
247
  .with(
248
248
  headers: {
249
- "Host" => "gateway.watsonplatform.net"
249
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
250
250
  }
251
251
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
252
252
  service_response = service.get_jpeg_image(
@@ -260,10 +260,10 @@ class VisualRecognitionV4Test < Minitest::Test
260
260
  response = {
261
261
  "collection_id" => "collid"
262
262
  }
263
- stub_request(:post, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid/train?version=2018-03-19")
263
+ stub_request(:post, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/train?version=2018-03-19")
264
264
  .with(
265
265
  headers: {
266
- "Host" => "gateway.watsonplatform.net"
266
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
267
267
  }
268
268
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
269
269
  service_response = service.train(
@@ -276,11 +276,11 @@ class VisualRecognitionV4Test < Minitest::Test
276
276
  response = {
277
277
  "collection_id" => "collid"
278
278
  }
279
- stub_request(:post, "https://gateway.watsonplatform.net/visual-recognition/api/v4/collections/collid/images/imageid/training_data?version=2018-03-19")
279
+ stub_request(:post, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/images/imageid/training_data?version=2018-03-19")
280
280
  .with(
281
281
  headers: {
282
282
  "Accept" => "application/json",
283
- "Host" => "gateway.watsonplatform.net"
283
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
284
284
  }
285
285
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
286
286
  service_response = service.add_image_training_data(
@@ -303,11 +303,11 @@ class VisualRecognitionV4Test < Minitest::Test
303
303
 
304
304
  def test_delete_user_data
305
305
  response = {}
306
- stub_request(:delete, "https://gateway.watsonplatform.net/visual-recognition/api/v4/user_data?version=2018-03-19&customer_id=customer")
306
+ stub_request(:delete, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/user_data?version=2018-03-19&customer_id=customer")
307
307
  .with(
308
308
  headers: {
309
309
  "Accept" => "application/json",
310
- "Host" => "gateway.watsonplatform.net"
310
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
311
311
  }
312
312
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
313
313
  service_response = service.delete_user_data(
@@ -320,10 +320,10 @@ class VisualRecognitionV4Test < Minitest::Test
320
320
  response = {
321
321
  "usage" => "usage"
322
322
  }
323
- stub_request(:get, "https://gateway.watsonplatform.net/visual-recognition/api/v4/training_usage?end_time=end&start_time=start&version=2018-03-19")
323
+ stub_request(:get, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/training_usage?end_time=end&start_time=start&version=2018-03-19")
324
324
  .with(
325
325
  headers: {
326
- "Host" => "gateway.watsonplatform.net"
326
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
327
327
  }
328
328
  ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
329
329
  service_response = service.get_training_usage(
@@ -332,4 +332,91 @@ class VisualRecognitionV4Test < Minitest::Test
332
332
  )
333
333
  assert_equal(response, service_response.result)
334
334
  end
335
+
336
+ def test_list_object_metadata
337
+ response = {
338
+ "objects" => []
339
+ }
340
+ stub_request(:get, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/objects?version=2018-03-19")
341
+ .with(
342
+ headers: {
343
+ "Accept" => "application/json",
344
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
345
+ }
346
+ ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
347
+ service_response = service.list_object_metadata(
348
+ collection_id: "collid"
349
+ )
350
+ assert_equal(response, service_response.result)
351
+ end
352
+
353
+ def test_update_object_metadata
354
+ response = {
355
+ "objects" => []
356
+ }
357
+ stub_request(:post, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/objects/old_object?version=2018-03-19")
358
+ .with(
359
+ headers: {
360
+ "Accept" => "application/json",
361
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
362
+ }
363
+ ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
364
+ service_response = service.update_object_metadata(
365
+ collection_id: "collid",
366
+ object: "old_object",
367
+ new_object: "new_object"
368
+ )
369
+ assert_equal(response, service_response.result)
370
+ end
371
+
372
+ def test_get_object_metadata
373
+ response = {
374
+ "objects" => []
375
+ }
376
+ stub_request(:get, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/objects/object?version=2018-03-19")
377
+ .with(
378
+ headers: {
379
+ "Accept" => "application/json",
380
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
381
+ }
382
+ ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
383
+ service_response = service.get_object_metadata(
384
+ collection_id: "collid",
385
+ object: "object"
386
+ )
387
+ assert_equal(response, service_response.result)
388
+ end
389
+
390
+ def test_delete_object
391
+ stub_request(:delete, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/objects/object?version=2018-03-19")
392
+ .with(
393
+ headers: {
394
+ "Accept" => "application/json",
395
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
396
+ }
397
+ ).to_return(status: 200, body: {}.to_json, headers: { "Content-Type" => "application/json" })
398
+ service_response = service.delete_object(
399
+ collection_id: "collid",
400
+ object: "object"
401
+ )
402
+ assert_nil(service_response)
403
+ end
404
+
405
+ def test_get_model_file
406
+ response = {
407
+ "binary" => []
408
+ }
409
+ stub_request(:get, "https://api.us-south.visual-recognition.watson.cloud.ibm.com/v4/collections/collid/model?feature=objects&model_format=rscnn_ready&version=2018-03-19")
410
+ .with(
411
+ headers: {
412
+ "Host" => "api.us-south.visual-recognition.watson.cloud.ibm.com"
413
+ }
414
+ ).to_return(status: 200, body: response.to_json, headers: { "Content-Type" => "application/json" })
415
+ service_response = service.get_model_file(
416
+ collection_id: "collid",
417
+ feature: "objects",
418
+ model_format: "rscnn_ready"
419
+ )
420
+ assert_equal(response, service_response.result)
421
+ end
335
422
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibm_watson
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Nussbaum
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-15 00:00:00.000000000 Z
11
+ date: 2020-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.1'
75
+ version: 1.1.1
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.1'
82
+ version: 1.1.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: jwt
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -322,7 +322,6 @@ files:
322
322
  - test/unit/test_speech_to_text_v1.rb
323
323
  - test/unit/test_text_to_speech_v1.rb
324
324
  - test/unit/test_tone_analyzer_v3.rb
325
- - test/unit/test_vcap_using_personality_insights.rb
326
325
  - test/unit/test_visual_recognition_v3.rb
327
326
  - test/unit/test_visual_recognition_v4.rb
328
327
  homepage: https://www.github.com/watson-developer-cloud
@@ -347,7 +346,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
347
346
  - !ruby/object:Gem::Version
348
347
  version: '0'
349
348
  requirements: []
350
- rubygems_version: 3.1.2
349
+ rubygems_version: 3.1.4
351
350
  signing_key:
352
351
  specification_version: 4
353
352
  summary: Official client library to use the IBM Watson Services
@@ -1,161 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require("json")
4
- require_relative("./../test_helper.rb")
5
- require("webmock/minitest")
6
-
7
- WebMock.disable_net_connect!(allow_localhost: true)
8
-
9
- ENV["VCAP_SERVICES"] = JSON.parse(File.read(Dir.getwd + "/resources/vcap-testing.json")).to_json
10
-
11
- # Unit tests for VCAP Services using the Personality Insights V3 Service
12
- class VcapPersonalityInsightsV3Test < Minitest::Test
13
- def test_plain_to_json
14
- profile_response = File.read(Dir.getwd + "/resources/personality-v3-expect1.txt")
15
- personality_text = File.read(Dir.getwd + "/resources/personality-v3.txt")
16
- headers = {
17
- "Content-Type" => "application/json"
18
- }
19
- expected_response = IBMWatson::DetailedResponse.new(status: 200, body: JSON.parse(profile_response), headers: headers)
20
- stub_request(:post, "https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13")
21
- .with(
22
- body: personality_text,
23
- headers: {
24
- "Accept" => "application/json",
25
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
26
- "Content-Type" => "text/plain;charset=utf-8",
27
- "Host" => "gateway.watsonplatform.net"
28
- }
29
- ).to_return(status: 200, body: profile_response, headers: headers)
30
- authenticator = IBMWatson::Authenticators::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "sample_service")
31
- service = IBMWatson::PersonalityInsightsV3.new(
32
- version: "2017-10-13",
33
- authenticator: authenticator
34
- )
35
- service_response = service.profile(
36
- accept: "application/json",
37
- content: personality_text,
38
- content_type: "text/plain;charset=utf-8"
39
- )
40
- assert_equal(expected_response.status, service_response.status)
41
- assert_equal(expected_response.result, service_response.result)
42
- expected_response.headers.each_key do |key|
43
- assert(service_response.headers.key?(key))
44
- assert(expected_response.headers[key] == service_response.headers[key])
45
- end
46
- end
47
-
48
- def test_json_to_json
49
- profile_response = File.read(Dir.getwd + "/resources/personality-v3-expect2.txt")
50
- personality_text = File.read(Dir.getwd + "/resources/personality-v3.json")
51
- headers = {
52
- "Content-Type" => "applicaiton/json"
53
- }
54
- expected_response = IBMWatson::DetailedResponse.new(status: 200, body: profile_response, headers: headers)
55
- stub_request(:post, "https://gateway.watsonplatform.net/personality-insights/api/v3/profile?consumption_preferences=true&raw_scores=true&version=2017-10-13")
56
- .with(
57
- body: personality_text,
58
- headers: {
59
- "Accept" => "application/json",
60
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
61
- "Content-Type" => "application/json",
62
- "Host" => "gateway.watsonplatform.net"
63
- }
64
- ).to_return(status: 200, body: profile_response, headers: headers)
65
- authenticator = IBMWatson::Authenticators::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "sample_service")
66
- service = IBMWatson::PersonalityInsightsV3.new(
67
- version: "2017-10-13",
68
- authenticator: authenticator
69
- )
70
- service_response = service.profile(
71
- accept: "application/json",
72
- content: personality_text,
73
- content_type: "application/json",
74
- raw_scores: true,
75
- consumption_preferences: true
76
- )
77
- assert_equal(expected_response.status, service_response.status)
78
- assert_equal(expected_response.result, service_response.result)
79
- expected_response.headers.each_key do |key|
80
- assert(service_response.headers.key?(key))
81
- assert(expected_response.headers[key] == service_response.headers[key])
82
- end
83
- end
84
-
85
- def test_json_to_csv
86
- profile_response = File.read(Dir.getwd + "/resources/personality-v3-expect3.txt")
87
- personality_text = File.read(Dir.getwd + "/resources/personality-v3.json")
88
- headers = {
89
- "Content-Type" => "text/csv"
90
- }
91
- expected_response = IBMWatson::DetailedResponse.new(status: 200, body: profile_response, headers: headers)
92
- stub_request(:post, "https://gateway.watsonplatform.net/personality-insights/api/v3/profile?consumption_preferences=true&csv_headers=true&raw_scores=true&version=2017-10-13")
93
- .with(
94
- body: personality_text,
95
- headers: {
96
- "Accept" => "text/csv",
97
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
98
- "Content-Type" => "application/json",
99
- "Host" => "gateway.watsonplatform.net"
100
- }
101
- ).to_return(status: 200, body: profile_response, headers: headers)
102
- authenticator = IBMWatson::Authenticators::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "sample_service")
103
- service = IBMWatson::PersonalityInsightsV3.new(
104
- version: "2017-10-13",
105
- authenticator: authenticator
106
- )
107
- service_response = service.profile(
108
- content: personality_text,
109
- content_type: "application/json",
110
- accept: "text/csv",
111
- csv_headers: true,
112
- raw_scores: true,
113
- consumption_preferences: true
114
- )
115
- assert_equal(expected_response.status, service_response.status)
116
- assert_equal(expected_response.result, service_response.result)
117
- expected_response.headers.each_key do |key|
118
- assert(service_response.headers.key?(key))
119
- assert(expected_response.headers[key] == service_response.headers[key])
120
- end
121
- end
122
-
123
- def test_plain_to_json_es
124
- profile_response = JSON.parse(File.read(Dir.getwd + "/resources/personality-v3-expect4.txt"))
125
- personality_text = File.read(Dir.getwd + "/resources/personality-v3-es.txt")
126
- headers = {
127
- "Content-Type" => "application/json"
128
- }
129
- expected_response = IBMWatson::DetailedResponse.new(status: 200, body: profile_response, headers: headers)
130
- stub_request(:post, "https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13")
131
- .with(
132
- body: personality_text,
133
- headers: {
134
- "Accept" => "application/json",
135
- "Accept-Language" => "es",
136
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
137
- "Content-Language" => "es",
138
- "Content-Type" => "text/plain;charset=utf-8",
139
- "Host" => "gateway.watsonplatform.net"
140
- }
141
- ).to_return(status: 200, body: profile_response.to_json, headers: headers)
142
- authenticator = IBMWatson::Authenticators::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "sample_service")
143
- service = IBMWatson::PersonalityInsightsV3.new(
144
- version: "2017-10-13",
145
- authenticator: authenticator
146
- )
147
- service_response = service.profile(
148
- accept: "application/json",
149
- content: personality_text,
150
- content_type: "text/plain;charset=utf-8",
151
- content_language: "es",
152
- accept_language: "es"
153
- )
154
- assert_equal(expected_response.status, service_response.status)
155
- assert_equal(expected_response.result, service_response.result)
156
- expected_response.headers.each_key do |key|
157
- assert(service_response.headers.key?(key))
158
- assert(expected_response.headers[key] == service_response.headers[key])
159
- end
160
- end
161
- end