ibm_watson 0.20.1 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +46 -60
  3. data/lib/ibm_watson.rb +0 -2
  4. data/lib/ibm_watson/assistant_v1.rb +82 -60
  5. data/lib/ibm_watson/assistant_v2.rb +8 -12
  6. data/lib/ibm_watson/compare_comply_v1.rb +21 -18
  7. data/lib/ibm_watson/discovery_v1.rb +107 -55
  8. data/lib/ibm_watson/language_translator_v3.rb +21 -23
  9. data/lib/ibm_watson/natural_language_classifier_v1.rb +15 -24
  10. data/lib/ibm_watson/natural_language_understanding_v1.rb +8 -12
  11. data/lib/ibm_watson/personality_insights_v3.rb +12 -24
  12. data/lib/ibm_watson/speech_to_text_v1.rb +90 -54
  13. data/lib/ibm_watson/text_to_speech_v1.rb +38 -32
  14. data/lib/ibm_watson/tone_analyzer_v3.rb +13 -24
  15. data/lib/ibm_watson/version.rb +1 -1
  16. data/lib/ibm_watson/visual_recognition_v3.rb +37 -25
  17. data/test/integration/test_assistant_v1.rb +8 -4
  18. data/test/integration/test_assistant_v2.rb +6 -1
  19. data/test/integration/test_compare_comply_v1.rb +6 -2
  20. data/test/integration/test_discovery_v1.rb +4 -1
  21. data/test/integration/test_language_translator_v3.rb +4 -16
  22. data/test/integration/test_natural_language_classifier_v1.rb +4 -1
  23. data/test/integration/test_natural_language_understanding_v1.rb +4 -1
  24. data/test/integration/test_personality_insights_v3.rb +5 -2
  25. data/test/integration/test_speech_to_text_v1.rb +9 -3
  26. data/test/integration/test_text_to_speech_v1.rb +5 -2
  27. data/test/integration/test_tone_analyzer_v3.rb +5 -2
  28. data/test/integration/test_visual_recognition_v3.rb +5 -2
  29. data/test/test_helper.rb +2 -0
  30. data/test/unit/test_assistant_v1.rb +269 -133
  31. data/test/unit/test_assistant_v2.rb +18 -9
  32. data/test/unit/test_compare_comply_v1.rb +72 -40
  33. data/test/unit/test_configure_http_client.rb +4 -2
  34. data/test/unit/test_discovery_v1.rb +297 -152
  35. data/test/unit/test_language_translator_v3.rb +52 -13
  36. data/test/unit/test_natural_language_classifier_v1.rb +10 -4
  37. data/test/unit/test_natural_language_understanding_v1.rb +25 -10
  38. data/test/unit/test_personality_insights_v3.rb +20 -8
  39. data/test/unit/test_speech_to_text_v1.rb +84 -21
  40. data/test/unit/test_text_to_speech_v1.rb +30 -5
  41. data/test/unit/test_tone_analyzer_v3.rb +30 -12
  42. data/test/unit/test_vcap_using_personality_insights.rb +12 -4
  43. data/test/unit/test_visual_recognition_v3.rb +37 -10
  44. metadata +8 -8
  45. data/test/unit/test_watson_service.rb +0 -59
@@ -55,10 +55,15 @@ class TextToSpeechV1Test < Minitest::Test
55
55
  "Host" => "stream.watsonplatform.net"
56
56
  }
57
57
  ).to_return(status: 200, body: voices_response.to_json, headers: { "Content-Type" => "application/json" })
58
- service = IBMWatson::TextToSpeechV1.new(
58
+ authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
59
59
  username: "username",
60
60
  password: "password"
61
61
  )
62
+ service = IBMWatson::TextToSpeechV1.new(
63
+ username: "username",
64
+ password: "password",
65
+ authenticator: authenticator
66
+ )
62
67
  service_response = service.list_voices
63
68
  assert_equal(voices_response, service_response.result)
64
69
 
@@ -94,10 +99,15 @@ class TextToSpeechV1Test < Minitest::Test
94
99
  response = {
95
100
  "pronunciation" => "pronunciation info"
96
101
  }
97
- service = IBMWatson::TextToSpeechV1.new(
102
+ authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
98
103
  username: "username",
99
104
  password: "password"
100
105
  )
106
+ service = IBMWatson::TextToSpeechV1.new(
107
+ username: "username",
108
+ password: "password",
109
+ authenticator: authenticator
110
+ )
101
111
  stub_request(:get, "https://stream.watsonplatform.net/text-to-speech/api/v1/pronunciation?text=this%20is%20some%20text")
102
112
  .with(
103
113
  headers: {
@@ -143,10 +153,15 @@ class TextToSpeechV1Test < Minitest::Test
143
153
 
144
154
  def test_custom_voice_models
145
155
  response = { "customizations" => "yep" }
146
- service = IBMWatson::TextToSpeechV1.new(
156
+ authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
147
157
  username: "username",
148
158
  password: "password"
149
159
  )
160
+ service = IBMWatson::TextToSpeechV1.new(
161
+ username: "username",
162
+ password: "password",
163
+ authenticator: authenticator
164
+ )
150
165
  stub_request(:get, "https://stream.watsonplatform.net/text-to-speech/api/v1/customizations")
151
166
  .with(
152
167
  headers: {
@@ -232,10 +247,15 @@ class TextToSpeechV1Test < Minitest::Test
232
247
 
233
248
  def test_custom_words
234
249
  response = { "customizations" => "yep" }
235
- service = IBMWatson::TextToSpeechV1.new(
250
+ authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
236
251
  username: "username",
237
252
  password: "password"
238
253
  )
254
+ service = IBMWatson::TextToSpeechV1.new(
255
+ username: "username",
256
+ password: "password",
257
+ authenticator: authenticator
258
+ )
239
259
  stub_request(:get, "https://stream.watsonplatform.net/text-to-speech/api/v1/customizations/custid/words")
240
260
  .with(
241
261
  headers: {
@@ -313,10 +333,15 @@ class TextToSpeechV1Test < Minitest::Test
313
333
  end
314
334
 
315
335
  def test_delete_user_data
316
- service = IBMWatson::TextToSpeechV1.new(
336
+ authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
317
337
  username: "username",
318
338
  password: "password"
319
339
  )
340
+ service = IBMWatson::TextToSpeechV1.new(
341
+ username: "username",
342
+ password: "password",
343
+ authenticator: authenticator
344
+ )
320
345
  stub_request(:delete, "https://stream.watsonplatform.net/text-to-speech/api/v1/user_data?customer_id=id")
321
346
  .with(
322
347
  headers: {
@@ -25,11 +25,14 @@ class ToneAnalyzerV3Test < Minitest::Test
25
25
  "Host" => "gateway.watsonplatform.net"
26
26
  }
27
27
  ).to_return(status: 200, body: tone_response.to_json, headers: headers)
28
- service = IBMWatson::ToneAnalyzerV3.new(
29
- version: "2017-09-21",
28
+ authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
30
29
  username: "username",
31
30
  password: "password"
32
31
  )
32
+ service = IBMWatson::ToneAnalyzerV3.new(
33
+ version: "2017-09-21",
34
+ authenticator: authenticator
35
+ )
33
36
  service_response = service.tone(tone_input: tone_text, content_type: "application/json")
34
37
  assert_equal(expected_response.status, service_response.status)
35
38
  assert_equal(expected_response.result, service_response.result)
@@ -56,11 +59,14 @@ class ToneAnalyzerV3Test < Minitest::Test
56
59
  "Host" => "gateway.watsonplatform.net"
57
60
  }
58
61
  ).to_return(status: 200, body: tone_response.to_json, headers: headers)
59
- service = IBMWatson::ToneAnalyzerV3.new(
60
- version: "2017-09-21",
62
+ authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
61
63
  username: "username",
62
64
  password: "password"
63
65
  )
66
+ service = IBMWatson::ToneAnalyzerV3.new(
67
+ version: "2017-09-21",
68
+ authenticator: authenticator
69
+ )
64
70
  service_response = service.tone(tone_input: tone_text, content_type: "application/json", sentences: false)
65
71
  assert_equal(expected_response.status, service_response.status)
66
72
  assert_equal(expected_response.result, service_response.result)
@@ -86,11 +92,14 @@ class ToneAnalyzerV3Test < Minitest::Test
86
92
  "Host" => "gateway.watsonplatform.net"
87
93
  }
88
94
  ).to_return(status: 200, body: tone_response.to_json, headers: headers)
89
- service = IBMWatson::ToneAnalyzerV3.new(
90
- version: "2017-09-21",
95
+ authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
91
96
  username: "username",
92
97
  password: "password"
93
98
  )
99
+ service = IBMWatson::ToneAnalyzerV3.new(
100
+ version: "2017-09-21",
101
+ authenticator: authenticator
102
+ )
94
103
  utterances = [
95
104
  {
96
105
  "text" => "I am very happy",
@@ -128,11 +137,14 @@ class ToneAnalyzerV3Test < Minitest::Test
128
137
  "Host" => "gateway.watsonplatform.net"
129
138
  }
130
139
  ).to_return(status: 400, body: tone_response.to_json, headers: headers)
131
- service = IBMWatson::ToneAnalyzerV3.new(
132
- version: "2017-09-21",
140
+ authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
133
141
  username: "username",
134
142
  password: "password"
135
143
  )
144
+ service = IBMWatson::ToneAnalyzerV3.new(
145
+ version: "2017-09-21",
146
+ authenticator: authenticator
147
+ )
136
148
  begin
137
149
  service.tone(tone_input: text, content_type: "application/json")
138
150
  rescue IBMWatson::ApiException => e
@@ -160,11 +172,14 @@ class ToneAnalyzerV3Test < Minitest::Test
160
172
  "Custom-Header-One" => "yes"
161
173
  }
162
174
  ).to_return(status: 200, body: tone_response.to_json, headers: headers)
163
- service = IBMWatson::ToneAnalyzerV3.new(
164
- version: "2017-09-21",
175
+ authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
165
176
  username: "username",
166
177
  password: "password"
167
178
  )
179
+ service = IBMWatson::ToneAnalyzerV3.new(
180
+ version: "2017-09-21",
181
+ authenticator: authenticator
182
+ )
168
183
  service_response = service.headers(
169
184
  "Custom-Header-One" => "yes",
170
185
  "Content-Type" => "Custom/Type"
@@ -188,11 +203,14 @@ class ToneAnalyzerV3Test < Minitest::Test
188
203
  "Host" => "gateway.watsonplatform.net"
189
204
  }
190
205
  ).to_return(status: 200, body: tone_response.to_json, headers: headers)
191
- service = IBMWatson::ToneAnalyzerV3.new(
192
- version: "2017-09-21",
206
+ authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
193
207
  username: "username",
194
208
  password: "password"
195
209
  )
210
+ service = IBMWatson::ToneAnalyzerV3.new(
211
+ version: "2017-09-21",
212
+ authenticator: authenticator
213
+ )
196
214
  service_response = service.tone(tone_input: tone_text, content_type: "application/json")
197
215
  assert_equal(tone_response, service_response.result)
198
216
  end
@@ -27,8 +27,10 @@ class VcapPersonalityInsightsV3Test < Minitest::Test
27
27
  "Host" => "gateway.watsonplatform.net"
28
28
  }
29
29
  ).to_return(status: 200, body: profile_response, headers: headers)
30
+ authenticator = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "sample_service")
30
31
  service = IBMWatson::PersonalityInsightsV3.new(
31
- version: "2017-10-13"
32
+ version: "2017-10-13",
33
+ authenticator: authenticator
32
34
  )
33
35
  service_response = service.profile(
34
36
  accept: "application/json",
@@ -60,8 +62,10 @@ class VcapPersonalityInsightsV3Test < Minitest::Test
60
62
  "Host" => "gateway.watsonplatform.net"
61
63
  }
62
64
  ).to_return(status: 200, body: profile_response, headers: headers)
65
+ authenticator = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "sample_service")
63
66
  service = IBMWatson::PersonalityInsightsV3.new(
64
- version: "2017-10-13"
67
+ version: "2017-10-13",
68
+ authenticator: authenticator
65
69
  )
66
70
  service_response = service.profile(
67
71
  accept: "application/json",
@@ -95,8 +99,10 @@ class VcapPersonalityInsightsV3Test < Minitest::Test
95
99
  "Host" => "gateway.watsonplatform.net"
96
100
  }
97
101
  ).to_return(status: 200, body: profile_response, headers: headers)
102
+ authenticator = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "sample_service")
98
103
  service = IBMWatson::PersonalityInsightsV3.new(
99
- version: "2017-10-13"
104
+ version: "2017-10-13",
105
+ authenticator: authenticator
100
106
  )
101
107
  service_response = service.profile(
102
108
  content: personality_text,
@@ -133,8 +139,10 @@ class VcapPersonalityInsightsV3Test < Minitest::Test
133
139
  "Host" => "gateway.watsonplatform.net"
134
140
  }
135
141
  ).to_return(status: 200, body: profile_response.to_json, headers: headers)
142
+ authenticator = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: "sample_service")
136
143
  service = IBMWatson::PersonalityInsightsV3.new(
137
- version: "2017-10-13"
144
+ version: "2017-10-13",
145
+ authenticator: authenticator
138
146
  )
139
147
  service_response = service.profile(
140
148
  accept: "application/json",
@@ -9,10 +9,13 @@ WebMock.disable_net_connect!(allow_localhost: true)
9
9
  # Unit tests for the Visual Recognition V3 Service
10
10
  class VisualRecognitionV3Test < Minitest::Test
11
11
  def test_get_classifier
12
+ authenticator = IBMCloudSdkCore::BearerTokenAuthenticator.new(
13
+ bearer_token: "bogus_access_token"
14
+ )
12
15
  service = IBMWatson::VisualRecognitionV3.new(
13
- version: "2018-03-19"
16
+ version: "2018-03-19",
17
+ authenticator: authenticator
14
18
  )
15
- service.iam_access_token(iam_access_token: "bogus_access_token")
16
19
  response = {
17
20
  "classifier_id" => "bogusnumber",
18
21
  "name" => "Dog Breeds",
@@ -40,9 +43,12 @@ class VisualRecognitionV3Test < Minitest::Test
40
43
  end
41
44
 
42
45
  def test_delete_classifier
46
+ authenticator = IBMCloudSdkCore::BearerTokenAuthenticator.new(
47
+ bearer_token: "bogus_access_token"
48
+ )
43
49
  service = IBMWatson::VisualRecognitionV3.new(
44
50
  version: "2018-03-19",
45
- iam_access_token: "bogus_access_token"
51
+ authenticator: authenticator
46
52
  )
47
53
  stub_request(:delete, "https://gateway.watsonplatform.net/visual-recognition/api/v3/classifiers/bogusnumber?version=2018-03-19")
48
54
  .with(
@@ -59,9 +65,12 @@ class VisualRecognitionV3Test < Minitest::Test
59
65
  end
60
66
 
61
67
  def test_list_classifiers
68
+ authenticator = IBMCloudSdkCore::BearerTokenAuthenticator.new(
69
+ bearer_token: "bogus_access_token"
70
+ )
62
71
  service = IBMWatson::VisualRecognitionV3.new(
63
72
  version: "2018-03-19",
64
- iam_access_token: "bogus_access_token"
73
+ authenticator: authenticator
65
74
  )
66
75
  response = {
67
76
  "classifiers" =>
@@ -91,9 +100,12 @@ class VisualRecognitionV3Test < Minitest::Test
91
100
  end
92
101
 
93
102
  def test_create_classifier
103
+ authenticator = IBMCloudSdkCore::BearerTokenAuthenticator.new(
104
+ bearer_token: "bogus_access_token"
105
+ )
94
106
  service = IBMWatson::VisualRecognitionV3.new(
95
107
  version: "2018-03-19",
96
- iam_access_token: "bogus_access_token"
108
+ authenticator: authenticator
97
109
  )
98
110
  response = {
99
111
  "classifier_id" => "DogBreeds_2014254824",
@@ -130,9 +142,12 @@ class VisualRecognitionV3Test < Minitest::Test
130
142
  end
131
143
 
132
144
  def test_update_classifier
145
+ authenticator = IBMCloudSdkCore::BearerTokenAuthenticator.new(
146
+ bearer_token: "bogus_access_token"
147
+ )
133
148
  service = IBMWatson::VisualRecognitionV3.new(
134
149
  version: "2018-03-19",
135
- iam_access_token: "bogus_access_token"
150
+ authenticator: authenticator
136
151
  )
137
152
  response = {
138
153
  "classifier_id" => "bogusid",
@@ -170,9 +185,12 @@ class VisualRecognitionV3Test < Minitest::Test
170
185
  end
171
186
 
172
187
  def test_classify
188
+ authenticator = IBMCloudSdkCore::BearerTokenAuthenticator.new(
189
+ bearer_token: "bogus_access_token"
190
+ )
173
191
  service = IBMWatson::VisualRecognitionV3.new(
174
192
  version: "2018-03-19",
175
- iam_access_token: "bogus_access_token"
193
+ authenticator: authenticator
176
194
  )
177
195
  response = {
178
196
  "images" =>
@@ -240,9 +258,12 @@ class VisualRecognitionV3Test < Minitest::Test
240
258
  end
241
259
 
242
260
  def test_detect_faces
261
+ authenticator = IBMCloudSdkCore::BearerTokenAuthenticator.new(
262
+ bearer_token: "bogus_access_token"
263
+ )
243
264
  service = IBMWatson::VisualRecognitionV3.new(
244
265
  version: "2018-03-19",
245
- iam_access_token: "bogus_access_token"
266
+ authenticator: authenticator
246
267
  )
247
268
  response = {
248
269
  "images" => [
@@ -304,9 +325,12 @@ class VisualRecognitionV3Test < Minitest::Test
304
325
  end
305
326
 
306
327
  def test_delete_user_data
328
+ authenticator = IBMCloudSdkCore::BearerTokenAuthenticator.new(
329
+ bearer_token: "bogus_access_token"
330
+ )
307
331
  service = IBMWatson::VisualRecognitionV3.new(
308
332
  version: "2018-03-19",
309
- iam_access_token: "bogus_access_token"
333
+ authenticator: authenticator
310
334
  )
311
335
  stub_request(:delete, "https://gateway.watsonplatform.net/visual-recognition/api/v3/user_data?customer_id=id&version=2018-03-19")
312
336
  .with(
@@ -323,9 +347,12 @@ class VisualRecognitionV3Test < Minitest::Test
323
347
  end
324
348
 
325
349
  def test_get_core_ml_model
350
+ authenticator = IBMCloudSdkCore::BearerTokenAuthenticator.new(
351
+ bearer_token: "bogus_access_token"
352
+ )
326
353
  service = IBMWatson::VisualRecognitionV3.new(
327
354
  version: "2018-03-19",
328
- iam_access_token: "bogus_access_token"
355
+ authenticator: authenticator
329
356
  )
330
357
  stub_request(:get, "https://gateway.watsonplatform.net/visual-recognition/api/v3/classifiers/classifierid/core_ml_model?version=2018-03-19")
331
358
  .with(
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: 0.20.1
4
+ version: 1.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Nussbaum
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-13 00:00:00.000000000 Z
11
+ date: 2019-08-30 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: 0.3.3
75
+ version: 1.0.0.rc2
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: 0.3.3
82
+ version: 1.0.0.rc2
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: jwt
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -318,7 +318,6 @@ files:
318
318
  - test/unit/test_tone_analyzer_v3.rb
319
319
  - test/unit/test_vcap_using_personality_insights.rb
320
320
  - test/unit/test_visual_recognition_v3.rb
321
- - test/unit/test_watson_service.rb
322
321
  homepage: https://www.github.com/watson-developer-cloud
323
322
  licenses:
324
323
  - Apache-2.0
@@ -337,11 +336,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
337
336
  version: '2.3'
338
337
  required_rubygems_version: !ruby/object:Gem::Requirement
339
338
  requirements:
340
- - - ">="
339
+ - - ">"
341
340
  - !ruby/object:Gem::Version
342
- version: '0'
341
+ version: 1.3.1
343
342
  requirements: []
344
- rubygems_version: 3.0.4
343
+ rubyforge_project:
344
+ rubygems_version: 2.7.8
345
345
  signing_key:
346
346
  specification_version: 4
347
347
  summary: Official client library to use the IBM Watson Services
@@ -1,59 +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
- # Unit tests for the watson_service
10
- class WatsonServiceTest < Minitest::Test
11
- def test_wrong_username
12
- assert_raises do
13
- IBMWatson::AssistantV2.new(
14
- username: "\"username",
15
- password: "password"
16
- )
17
- end
18
- end
19
-
20
- def test_wrong_apikey
21
- assert_raises do
22
- IBMWatson::AssistantV1.new(
23
- iam_apikey: "{apikey"
24
- )
25
- end
26
- end
27
-
28
- def test_wrong_url
29
- assert_raises do
30
- IBMWatson::AssistantV1.new(
31
- iam_apikey: "apikey",
32
- url: "url}"
33
- )
34
- end
35
- end
36
-
37
- def test_correct_creds
38
- service = IBMWatson::AssistantV1.new(
39
- username: "username",
40
- password: "password"
41
- )
42
- refute_nil(service)
43
- end
44
-
45
- def test_set_credentials_from_path_in_env
46
- file_path = File.join(File.dirname(__FILE__), "../../resources/ibm-credentials.env")
47
- ENV["IBM_CREDENTIALS_FILE"] = file_path
48
- service = IBMWatson::VisualRecognitionV3.new
49
- assert_equal(service.url, "https://gateway.ronaldo.com")
50
- refute_nil(service)
51
- ENV.delete("IBM_CREDENTIALS_FILE")
52
- end
53
-
54
- def test_set_credentials_when_no_file
55
- service = IBMWatson::AssistantV1.new
56
- assert_equal(service.url, "https://gateway.watsonplatform.net/assistant/api")
57
- refute_nil(service)
58
- end
59
- end