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.
- checksums.yaml +4 -4
- data/README.md +42 -4
- data/lib/ibm_watson/assistant_v1.rb +213 -195
- data/lib/ibm_watson/assistant_v2.rb +161 -17
- data/lib/ibm_watson/compare_comply_v1.rb +35 -21
- data/lib/ibm_watson/discovery_v1.rb +132 -13
- data/lib/ibm_watson/discovery_v2.rb +728 -21
- data/lib/ibm_watson/language_translator_v3.rb +205 -67
- data/lib/ibm_watson/natural_language_classifier_v1.rb +4 -2
- data/lib/ibm_watson/natural_language_understanding_v1.rb +21 -21
- data/lib/ibm_watson/personality_insights_v3.rb +27 -18
- data/lib/ibm_watson/speech_to_text_v1.rb +58 -46
- data/lib/ibm_watson/text_to_speech_v1.rb +113 -129
- data/lib/ibm_watson/tone_analyzer_v3.rb +12 -13
- data/lib/ibm_watson/version.rb +1 -1
- data/lib/ibm_watson/visual_recognition_v3.rb +33 -16
- data/lib/ibm_watson/visual_recognition_v4.rb +58 -17
- data/test/integration/test_assistant_v1.rb +9 -0
- data/test/integration/test_assistant_v2.rb +27 -0
- data/test/integration/test_discovery_v2.rb +132 -6
- data/test/integration/test_language_translator_v3.rb +5 -0
- data/test/integration/test_text_to_speech_v1.rb +3 -3
- data/test/unit/test_assistant_v1.rb +150 -99
- data/test/unit/test_assistant_v2.rb +91 -12
- data/test/unit/test_compare_comply_v1.rb +20 -20
- data/test/unit/test_discovery_v1.rb +125 -125
- data/test/unit/test_discovery_v2.rb +262 -29
- data/test/unit/test_language_translator_v3.rb +85 -24
- data/test/unit/test_natural_language_classifier_v1.rb +17 -17
- data/test/unit/test_natural_language_understanding_v1.rb +10 -10
- data/test/unit/test_personality_insights_v3.rb +14 -14
- data/test/unit/test_speech_to_text_v1.rb +97 -97
- data/test/unit/test_text_to_speech_v1.rb +48 -48
- data/test/unit/test_tone_analyzer_v3.rb +12 -12
- data/test/unit/test_visual_recognition_v3.rb +16 -16
- data/test/unit/test_visual_recognition_v4.rb +40 -40
- metadata +12 -11
@@ -16,16 +16,16 @@ class DiscoveryV2Test < Minitest::Test
|
|
16
16
|
@service = IBMWatson::DiscoveryV2.new(
|
17
17
|
version: "2018-03-05",
|
18
18
|
authenticator: authenticator,
|
19
|
-
service_url: "https://
|
19
|
+
service_url: "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api"
|
20
20
|
)
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_collections
|
24
|
-
stub_request(:get, "https://
|
24
|
+
stub_request(:get, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/collections?version=2018-03-05")
|
25
25
|
.with(
|
26
26
|
headers: {
|
27
27
|
"Accept" => "application/json",
|
28
|
-
"Host" => "
|
28
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
29
29
|
}
|
30
30
|
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
31
31
|
service_response = service.list_collections(
|
@@ -35,12 +35,12 @@ class DiscoveryV2Test < Minitest::Test
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_query
|
38
|
-
stub_request(:post, "https://
|
38
|
+
stub_request(:post, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/query?version=2018-03-05")
|
39
39
|
.with(
|
40
40
|
body: "{\"count\":10}",
|
41
41
|
headers: {
|
42
42
|
"Accept" => "application/json",
|
43
|
-
"Host" => "
|
43
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
44
44
|
}
|
45
45
|
).to_return(status: 200, body: { body: "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
46
46
|
service_response = service.query(
|
@@ -51,11 +51,11 @@ class DiscoveryV2Test < Minitest::Test
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_get_autocompletion
|
54
|
-
stub_request(:get, "https://
|
54
|
+
stub_request(:get, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/autocompletion?prefix=hi&version=2018-03-05")
|
55
55
|
.with(
|
56
56
|
headers: {
|
57
57
|
"Accept" => "application/json",
|
58
|
-
"Host" => "
|
58
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
59
59
|
}
|
60
60
|
).to_return(status: 200, body: { "received" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
|
61
61
|
service_response = service.get_autocompletion(
|
@@ -66,11 +66,11 @@ class DiscoveryV2Test < Minitest::Test
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def test_query_notices
|
69
|
-
stub_request(:get, "https://
|
69
|
+
stub_request(:get, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/notices?version=2018-03-05")
|
70
70
|
.with(
|
71
71
|
headers: {
|
72
72
|
"Accept" => "application/json",
|
73
|
-
"Host" => "
|
73
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
74
74
|
}
|
75
75
|
).to_return(status: 200, body: { "received" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
|
76
76
|
service_response = service.query_notices(
|
@@ -80,11 +80,11 @@ class DiscoveryV2Test < Minitest::Test
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def test_list_fields
|
83
|
-
stub_request(:get, "https://
|
83
|
+
stub_request(:get, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/fields?collection_ids=collid&version=2018-03-05")
|
84
84
|
.with(
|
85
85
|
headers: {
|
86
86
|
"Accept" => "application/json",
|
87
|
-
"Host" => "
|
87
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
88
88
|
}
|
89
89
|
).to_return(status: 200, body: { "received" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
|
90
90
|
service_response = service.list_fields(
|
@@ -95,11 +95,11 @@ class DiscoveryV2Test < Minitest::Test
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def test_get_component_settings
|
98
|
-
stub_request(:get, "https://
|
98
|
+
stub_request(:get, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/component_settings?version=2018-03-05")
|
99
99
|
.with(
|
100
100
|
headers: {
|
101
101
|
"Accept" => "application/json",
|
102
|
-
"Host" => "
|
102
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
103
103
|
}
|
104
104
|
).to_return(status: 200, body: { "received" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
|
105
105
|
service_response = service.get_component_settings(
|
@@ -109,11 +109,11 @@ class DiscoveryV2Test < Minitest::Test
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def test_add_document
|
112
|
-
stub_request(:post, "https://
|
112
|
+
stub_request(:post, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/collections/collid/documents?version=2018-03-05")
|
113
113
|
.with(
|
114
114
|
headers: {
|
115
115
|
"Accept" => "application/json",
|
116
|
-
"Host" => "
|
116
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
117
117
|
}
|
118
118
|
).to_return(status: 200, body: { body: [] }.to_json, headers: { "Content-Type" => "application/json" })
|
119
119
|
File.open(Dir.getwd + "/resources/simple.html") do |file_info|
|
@@ -127,11 +127,11 @@ class DiscoveryV2Test < Minitest::Test
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def test_update_document
|
130
|
-
stub_request(:post, "https://
|
130
|
+
stub_request(:post, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/collections/collid/documents/docid?version=2018-03-05")
|
131
131
|
.with(
|
132
132
|
headers: {
|
133
133
|
"Accept" => "application/json",
|
134
|
-
"Host" => "
|
134
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
135
135
|
}
|
136
136
|
).to_return(status: 200, body: { body: [] }.to_json, headers: { "Content-Type" => "application/json" })
|
137
137
|
service_response = service.update_document(
|
@@ -145,11 +145,11 @@ class DiscoveryV2Test < Minitest::Test
|
|
145
145
|
end
|
146
146
|
|
147
147
|
def test_delete_document
|
148
|
-
stub_request(:delete, "https://
|
148
|
+
stub_request(:delete, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/collections/collid/documents/docid?version=2018-03-05")
|
149
149
|
.with(
|
150
150
|
headers: {
|
151
151
|
"Accept" => "application/json",
|
152
|
-
"Host" => "
|
152
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
153
153
|
}
|
154
154
|
).to_return(status: 200, body: { body: [] }.to_json, headers: { "Content-Type" => "application/json" })
|
155
155
|
service_response = service.delete_document(
|
@@ -161,11 +161,11 @@ class DiscoveryV2Test < Minitest::Test
|
|
161
161
|
end
|
162
162
|
|
163
163
|
def test_list_training_queries
|
164
|
-
stub_request(:get, "https://
|
164
|
+
stub_request(:get, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/training_data/queries?version=2018-03-05")
|
165
165
|
.with(
|
166
166
|
headers: {
|
167
167
|
"Accept" => "application/json",
|
168
|
-
"Host" => "
|
168
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
169
169
|
}
|
170
170
|
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
171
171
|
service_response = service.list_training_queries(
|
@@ -175,10 +175,10 @@ class DiscoveryV2Test < Minitest::Test
|
|
175
175
|
end
|
176
176
|
|
177
177
|
def test_delete_training_queries
|
178
|
-
stub_request(:delete, "https://
|
178
|
+
stub_request(:delete, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/training_data/queries?version=2018-03-05")
|
179
179
|
.with(
|
180
180
|
headers: {
|
181
|
-
"Host" => "
|
181
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
182
182
|
}
|
183
183
|
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
184
184
|
service_response = service.delete_training_queries(
|
@@ -188,11 +188,11 @@ class DiscoveryV2Test < Minitest::Test
|
|
188
188
|
end
|
189
189
|
|
190
190
|
def test_create_training_query
|
191
|
-
stub_request(:post, "https://
|
191
|
+
stub_request(:post, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/training_data/queries?version=2018-03-05")
|
192
192
|
.with(
|
193
193
|
headers: {
|
194
194
|
"Accept" => "application/json",
|
195
|
-
"Host" => "
|
195
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
196
196
|
}
|
197
197
|
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
198
198
|
service_response = service.create_training_query(
|
@@ -204,11 +204,11 @@ class DiscoveryV2Test < Minitest::Test
|
|
204
204
|
end
|
205
205
|
|
206
206
|
def test_get_training_query
|
207
|
-
stub_request(:get, "https://
|
207
|
+
stub_request(:get, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/training_data/queries/queryid?version=2018-03-05")
|
208
208
|
.with(
|
209
209
|
headers: {
|
210
210
|
"Accept" => "application/json",
|
211
|
-
"Host" => "
|
211
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
212
212
|
}
|
213
213
|
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
214
214
|
service_response = service.get_training_query(
|
@@ -219,11 +219,11 @@ class DiscoveryV2Test < Minitest::Test
|
|
219
219
|
end
|
220
220
|
|
221
221
|
def test_update_training_query
|
222
|
-
stub_request(:post, "https://
|
222
|
+
stub_request(:post, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/training_data/queries/queryid?version=2018-03-05")
|
223
223
|
.with(
|
224
224
|
headers: {
|
225
225
|
"Accept" => "application/json",
|
226
|
-
"Host" => "
|
226
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
227
227
|
}
|
228
228
|
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
229
229
|
service_response = service.update_training_query(
|
@@ -234,4 +234,237 @@ class DiscoveryV2Test < Minitest::Test
|
|
234
234
|
)
|
235
235
|
assert_equal({ "body" => "hello" }, service_response.result)
|
236
236
|
end
|
237
|
+
|
238
|
+
def test_create_collection
|
239
|
+
stub_request(:post, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/collections?version=2018-03-05")
|
240
|
+
.with(
|
241
|
+
headers: {
|
242
|
+
"Accept" => "application/json",
|
243
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
244
|
+
}
|
245
|
+
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
246
|
+
service_response = service.create_collection(
|
247
|
+
project_id: "project",
|
248
|
+
name: "collection1"
|
249
|
+
)
|
250
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_get_collection
|
254
|
+
stub_request(:get, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/collections/collection?version=2018-03-05")
|
255
|
+
.with(
|
256
|
+
headers: {
|
257
|
+
"Accept" => "application/json",
|
258
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
259
|
+
}
|
260
|
+
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
261
|
+
service_response = service.get_collection(
|
262
|
+
project_id: "project",
|
263
|
+
collection_id: "collection"
|
264
|
+
)
|
265
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_update_collection
|
269
|
+
stub_request(:post, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/collections/collection?version=2018-03-05")
|
270
|
+
.with(
|
271
|
+
headers: {
|
272
|
+
"Accept" => "application/json",
|
273
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
274
|
+
}
|
275
|
+
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
276
|
+
service_response = service.update_collection(
|
277
|
+
project_id: "project",
|
278
|
+
collection_id: "collection"
|
279
|
+
)
|
280
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
281
|
+
end
|
282
|
+
|
283
|
+
def test_delete_collection
|
284
|
+
stub_request(:delete, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/collections/collection?version=2018-03-05")
|
285
|
+
.with(
|
286
|
+
headers: {
|
287
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
288
|
+
}
|
289
|
+
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
290
|
+
service_response = service.delete_collection(
|
291
|
+
project_id: "project",
|
292
|
+
collection_id: "collection"
|
293
|
+
)
|
294
|
+
assert_nil(service_response)
|
295
|
+
end
|
296
|
+
|
297
|
+
def test_analyze_document
|
298
|
+
# skip "not available yet"
|
299
|
+
|
300
|
+
stub_request(:post, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/collections/collid/analyze?version=2018-03-05")
|
301
|
+
.with(
|
302
|
+
headers: {
|
303
|
+
"Accept" => "application/json",
|
304
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
305
|
+
}
|
306
|
+
).to_return(status: 200, body: { body: [] }.to_json, headers: { "Content-Type" => "application/json" })
|
307
|
+
service_response = service.analyze_document(
|
308
|
+
project_id: "project",
|
309
|
+
collection_id: "collid",
|
310
|
+
file: "file",
|
311
|
+
filename: "file.name"
|
312
|
+
)
|
313
|
+
assert_equal({ "body" => [] }, service_response.result)
|
314
|
+
end
|
315
|
+
|
316
|
+
def test_delete_user_data
|
317
|
+
stub_request(:delete, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/user_data?customer_id=customer&version=2018-03-05")
|
318
|
+
.with(
|
319
|
+
headers: {
|
320
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
321
|
+
}
|
322
|
+
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
323
|
+
service_response = service.delete_user_data(
|
324
|
+
customer_id: "customer"
|
325
|
+
)
|
326
|
+
assert_nil(service_response)
|
327
|
+
end
|
328
|
+
|
329
|
+
def test_create_enrichment
|
330
|
+
stub_request(:post, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/enrichments?version=2018-03-05")
|
331
|
+
.with(
|
332
|
+
headers: {
|
333
|
+
"Accept" => "application/json",
|
334
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
335
|
+
}
|
336
|
+
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
337
|
+
service_response = service.create_enrichment(
|
338
|
+
project_id: "project",
|
339
|
+
enrichment: "enrichment1"
|
340
|
+
)
|
341
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
342
|
+
end
|
343
|
+
|
344
|
+
def test_list_enrichments
|
345
|
+
stub_request(:get, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/enrichments?version=2018-03-05")
|
346
|
+
.with(
|
347
|
+
headers: {
|
348
|
+
"Accept" => "application/json",
|
349
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
350
|
+
}
|
351
|
+
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
352
|
+
service_response = service.list_enrichments(
|
353
|
+
project_id: "project"
|
354
|
+
)
|
355
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
356
|
+
end
|
357
|
+
|
358
|
+
def test_get_enrichment
|
359
|
+
stub_request(:get, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/enrichments/enrichment?version=2018-03-05")
|
360
|
+
.with(
|
361
|
+
headers: {
|
362
|
+
"Accept" => "application/json",
|
363
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
364
|
+
}
|
365
|
+
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
366
|
+
service_response = service.get_enrichment(
|
367
|
+
project_id: "project",
|
368
|
+
enrichment_id: "enrichment"
|
369
|
+
)
|
370
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
371
|
+
end
|
372
|
+
|
373
|
+
def test_update_enrichment
|
374
|
+
stub_request(:post, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/enrichments/enrichment?version=2018-03-05")
|
375
|
+
.with(
|
376
|
+
headers: {
|
377
|
+
"Accept" => "application/json",
|
378
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
379
|
+
}
|
380
|
+
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
381
|
+
service_response = service.update_enrichment(
|
382
|
+
project_id: "project",
|
383
|
+
enrichment_id: "enrichment",
|
384
|
+
name: "newname"
|
385
|
+
)
|
386
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
387
|
+
end
|
388
|
+
|
389
|
+
def test_delete_enrichment
|
390
|
+
stub_request(:delete, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project/enrichments/enrichment?version=2018-03-05")
|
391
|
+
.with(
|
392
|
+
headers: {
|
393
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
394
|
+
}
|
395
|
+
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
396
|
+
service_response = service.delete_enrichment(
|
397
|
+
project_id: "project",
|
398
|
+
enrichment_id: "enrichment"
|
399
|
+
)
|
400
|
+
assert_nil(service_response)
|
401
|
+
end
|
402
|
+
|
403
|
+
def test_create_project
|
404
|
+
stub_request(:post, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects?version=2018-03-05")
|
405
|
+
.with(
|
406
|
+
headers: {
|
407
|
+
"Accept" => "application/json",
|
408
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
409
|
+
}
|
410
|
+
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
411
|
+
service_response = service.create_project(
|
412
|
+
name: "projectname",
|
413
|
+
type: "new"
|
414
|
+
)
|
415
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
416
|
+
end
|
417
|
+
|
418
|
+
def test_list_projects
|
419
|
+
stub_request(:get, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects?version=2018-03-05")
|
420
|
+
.with(
|
421
|
+
headers: {
|
422
|
+
"Accept" => "application/json",
|
423
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
424
|
+
}
|
425
|
+
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
426
|
+
service_response = service.list_projects
|
427
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
428
|
+
end
|
429
|
+
|
430
|
+
def test_get_project
|
431
|
+
stub_request(:get, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project?version=2018-03-05")
|
432
|
+
.with(
|
433
|
+
headers: {
|
434
|
+
"Accept" => "application/json",
|
435
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
436
|
+
}
|
437
|
+
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
438
|
+
service_response = service.get_project(
|
439
|
+
project_id: "project"
|
440
|
+
)
|
441
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
442
|
+
end
|
443
|
+
|
444
|
+
def test_update_project
|
445
|
+
stub_request(:post, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project?version=2018-03-05")
|
446
|
+
.with(
|
447
|
+
headers: {
|
448
|
+
"Accept" => "application/json",
|
449
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
450
|
+
}
|
451
|
+
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
452
|
+
service_response = service.update_project(
|
453
|
+
project_id: "project"
|
454
|
+
)
|
455
|
+
assert_equal({ "body" => "hello" }, service_response.result)
|
456
|
+
end
|
457
|
+
|
458
|
+
def test_delete_project
|
459
|
+
stub_request(:delete, "https://api.us-south.discovery.watson.cloud.ibm.com/discovery/api/v2/projects/project?version=2018-03-05")
|
460
|
+
.with(
|
461
|
+
headers: {
|
462
|
+
"Host" => "api.us-south.discovery.watson.cloud.ibm.com"
|
463
|
+
}
|
464
|
+
).to_return(status: 200, body: { "body" => "hello" }.to_json, headers: { "Content-Type" => "application/json" })
|
465
|
+
service_response = service.delete_project(
|
466
|
+
project_id: "project"
|
467
|
+
)
|
468
|
+
assert_nil(service_response)
|
469
|
+
end
|
237
470
|
end
|
@@ -60,14 +60,14 @@ class LanguageTranslatorV3Test < Minitest::Test
|
|
60
60
|
"translations" => [{ "translation" => "Hello, how are you ? \u20ac" }],
|
61
61
|
"word_count" => 4
|
62
62
|
}
|
63
|
-
stub_request(:post, "https://
|
63
|
+
stub_request(:post, "https://api.us-south.language-translator.watson.cloud.ibm.com/v3/translate?version=2018-05-01")
|
64
64
|
.with(
|
65
65
|
body: "{\"text\":\"Hola, cómo estás? €\",\"source\":\"es\",\"target\":\"en\"}",
|
66
66
|
headers: {
|
67
67
|
"Accept" => "application/json",
|
68
68
|
"Authorization" => "Bearer " + token_response["access_token"],
|
69
69
|
"Content-Type" => "application/json",
|
70
|
-
"Host" => "
|
70
|
+
"Host" => "api.us-south.language-translator.watson.cloud.ibm.com"
|
71
71
|
}
|
72
72
|
).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
|
73
73
|
service_response = service.translate(
|
@@ -109,14 +109,14 @@ class LanguageTranslatorV3Test < Minitest::Test
|
|
109
109
|
],
|
110
110
|
"word_count" => 5
|
111
111
|
}
|
112
|
-
stub_request(:post, "https://
|
112
|
+
stub_request(:post, "https://api.us-south.language-translator.watson.cloud.ibm.com/v3/translate?version=2018-05-01")
|
113
113
|
.with(
|
114
114
|
body: "{\"text\":\"Messi is the best ever\",\"model_id\":\"en-es-conversational\"}",
|
115
115
|
headers: {
|
116
116
|
"Accept" => "application/json",
|
117
117
|
"Authorization" => "Bearer " + token_response["access_token"],
|
118
118
|
"Content-Type" => "application/json",
|
119
|
-
"Host" => "
|
119
|
+
"Host" => "api.us-south.language-translator.watson.cloud.ibm.com"
|
120
120
|
}
|
121
121
|
).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
|
122
122
|
service_response = service.translate(
|
@@ -164,14 +164,14 @@ class LanguageTranslatorV3Test < Minitest::Test
|
|
164
164
|
}
|
165
165
|
]
|
166
166
|
}
|
167
|
-
stub_request(:post, "https://
|
167
|
+
stub_request(:post, "https://api.us-south.language-translator.watson.cloud.ibm.com/v3/identify?version=2018-05-01")
|
168
168
|
.with(
|
169
169
|
body: "祝你有美好的一天",
|
170
170
|
headers: {
|
171
171
|
"Accept" => "application/json",
|
172
172
|
"Authorization" => "Bearer " + token_response["access_token"],
|
173
173
|
"Content-Type" => "text/plain",
|
174
|
-
"Host" => "
|
174
|
+
"Host" => "api.us-south.language-translator.watson.cloud.ibm.com"
|
175
175
|
}
|
176
176
|
).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
|
177
177
|
service_response = service.identify(
|
@@ -230,7 +230,7 @@ class LanguageTranslatorV3Test < Minitest::Test
|
|
230
230
|
}
|
231
231
|
]
|
232
232
|
}
|
233
|
-
stub_request(:get, "https://
|
233
|
+
stub_request(:get, "https://api.us-south.language-translator.watson.cloud.ibm.com/v3/identifiable_languages?version=2018-05-01")
|
234
234
|
.with(
|
235
235
|
headers: {
|
236
236
|
"Accept" => "application/json",
|
@@ -275,12 +275,12 @@ class LanguageTranslatorV3Test < Minitest::Test
|
|
275
275
|
"default_model" => false,
|
276
276
|
"name" => "test_glossary"
|
277
277
|
}
|
278
|
-
stub_request(:post, "https://
|
278
|
+
stub_request(:post, "https://api.us-south.language-translator.watson.cloud.ibm.com/v3/models?base_model_id=en-fr&name=test_glossary&version=2018-05-01")
|
279
279
|
.with(
|
280
280
|
headers: {
|
281
281
|
"Accept" => "application/json",
|
282
282
|
"Authorization" => "Bearer " + token_response["access_token"],
|
283
|
-
"Host" => "
|
283
|
+
"Host" => "api.us-south.language-translator.watson.cloud.ibm.com"
|
284
284
|
}
|
285
285
|
).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
|
286
286
|
custom_model = File.open(Dir.getwd + "/resources/language_translator_model.tmx")
|
@@ -333,12 +333,12 @@ class LanguageTranslatorV3Test < Minitest::Test
|
|
333
333
|
expected = {
|
334
334
|
"status" => "OK"
|
335
335
|
}
|
336
|
-
stub_request(:delete, "https://
|
336
|
+
stub_request(:delete, "https://api.us-south.language-translator.watson.cloud.ibm.com/v3/models/en-es-conversational?version=2018-05-01")
|
337
337
|
.with(
|
338
338
|
headers: {
|
339
339
|
"Accept" => "application/json",
|
340
340
|
"Authorization" => "Bearer " + token_response["access_token"],
|
341
|
-
"Host" => "
|
341
|
+
"Host" => "api.us-south.language-translator.watson.cloud.ibm.com"
|
342
342
|
}
|
343
343
|
).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
|
344
344
|
service_response = service.delete_model(
|
@@ -381,12 +381,12 @@ class LanguageTranslatorV3Test < Minitest::Test
|
|
381
381
|
"default_model" => false,
|
382
382
|
"name" => "en-es-conversational"
|
383
383
|
}
|
384
|
-
stub_request(:get, "https://
|
384
|
+
stub_request(:get, "https://api.us-south.language-translator.watson.cloud.ibm.com/v3/models/en-es-conversational?version=2018-05-01")
|
385
385
|
.with(
|
386
386
|
headers: {
|
387
387
|
"Accept" => "application/json",
|
388
388
|
"Authorization" => "Bearer " + token_response["access_token"],
|
389
|
-
"Host" => "
|
389
|
+
"Host" => "api.us-south.language-translator.watson.cloud.ibm.com"
|
390
390
|
}
|
391
391
|
).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
|
392
392
|
service_response = service.get_model(
|
@@ -445,12 +445,12 @@ class LanguageTranslatorV3Test < Minitest::Test
|
|
445
445
|
}
|
446
446
|
]
|
447
447
|
}
|
448
|
-
stub_request(:get, "https://
|
448
|
+
stub_request(:get, "https://api.us-south.language-translator.watson.cloud.ibm.com/v3/models?version=2018-05-01")
|
449
449
|
.with(
|
450
450
|
headers: {
|
451
451
|
"Accept" => "application/json",
|
452
452
|
"Authorization" => "Bearer " + token_response["access_token"],
|
453
|
-
"Host" => "
|
453
|
+
"Host" => "api.us-south.language-translator.watson.cloud.ibm.com"
|
454
454
|
}
|
455
455
|
).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
|
456
456
|
service_response = service.list_models
|
@@ -480,12 +480,12 @@ class LanguageTranslatorV3Test < Minitest::Test
|
|
480
480
|
authenticator: authenticator
|
481
481
|
)
|
482
482
|
expected = {}
|
483
|
-
stub_request(:get, "https://
|
483
|
+
stub_request(:get, "https://api.us-south.language-translator.watson.cloud.ibm.com/v3/documents?version=2018-05-01")
|
484
484
|
.with(
|
485
485
|
headers: {
|
486
486
|
"Accept" => "application/json",
|
487
487
|
"Authorization" => "Bearer " + token_response["access_token"],
|
488
|
-
"Host" => "
|
488
|
+
"Host" => "api.us-south.language-translator.watson.cloud.ibm.com"
|
489
489
|
}
|
490
490
|
).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
|
491
491
|
service_response = service.list_documents
|
@@ -514,7 +514,7 @@ class LanguageTranslatorV3Test < Minitest::Test
|
|
514
514
|
version: "2018-05-01",
|
515
515
|
authenticator: authenticator
|
516
516
|
)
|
517
|
-
stub_request(:post, "https://
|
517
|
+
stub_request(:post, "https://api.us-south.language-translator.watson.cloud.ibm.com/v3/documents?version=2018-05-01")
|
518
518
|
.with do |req|
|
519
519
|
assert_equal req.headers["Accept"], "application/json"
|
520
520
|
assert_match %r{\Amultipart/form-data}, req.headers["Content-Type"]
|
@@ -546,12 +546,12 @@ class LanguageTranslatorV3Test < Minitest::Test
|
|
546
546
|
authenticator: authenticator
|
547
547
|
)
|
548
548
|
expected = {}
|
549
|
-
stub_request(:get, "https://
|
549
|
+
stub_request(:get, "https://api.us-south.language-translator.watson.cloud.ibm.com/v3/documents/id?version=2018-05-01")
|
550
550
|
.with(
|
551
551
|
headers: {
|
552
552
|
"Accept" => "application/json",
|
553
553
|
"Authorization" => "Bearer " + token_response["access_token"],
|
554
|
-
"Host" => "
|
554
|
+
"Host" => "api.us-south.language-translator.watson.cloud.ibm.com"
|
555
555
|
}
|
556
556
|
).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
|
557
557
|
service_response = service.get_document_status(document_id: "id")
|
@@ -581,12 +581,12 @@ class LanguageTranslatorV3Test < Minitest::Test
|
|
581
581
|
authenticator: authenticator
|
582
582
|
)
|
583
583
|
expected = {}
|
584
|
-
stub_request(:get, "https://
|
584
|
+
stub_request(:get, "https://api.us-south.language-translator.watson.cloud.ibm.com/v3/documents/id/translated_document?version=2018-05-01")
|
585
585
|
.with(
|
586
586
|
headers: {
|
587
587
|
"Accept" => "application/json",
|
588
588
|
"Authorization" => "Bearer " + token_response["access_token"],
|
589
|
-
"Host" => "
|
589
|
+
"Host" => "api.us-south.language-translator.watson.cloud.ibm.com"
|
590
590
|
}
|
591
591
|
).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
|
592
592
|
service_response = service.get_translated_document(document_id: "id")
|
@@ -616,14 +616,75 @@ class LanguageTranslatorV3Test < Minitest::Test
|
|
616
616
|
authenticator: authenticator
|
617
617
|
)
|
618
618
|
expected = {}
|
619
|
-
stub_request(:delete, "https://
|
619
|
+
stub_request(:delete, "https://api.us-south.language-translator.watson.cloud.ibm.com/v3/documents/id?version=2018-05-01")
|
620
620
|
.with(
|
621
621
|
headers: {
|
622
622
|
"Authorization" => "Bearer " + token_response["access_token"],
|
623
|
-
"Host" => "
|
623
|
+
"Host" => "api.us-south.language-translator.watson.cloud.ibm.com"
|
624
624
|
}
|
625
625
|
).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
|
626
626
|
service_response = service.delete_document(document_id: "id")
|
627
627
|
assert_nil(service_response)
|
628
628
|
end
|
629
|
+
|
630
|
+
def test_list_languages
|
631
|
+
token_response = token
|
632
|
+
stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
|
633
|
+
.with(
|
634
|
+
body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
|
635
|
+
headers: {
|
636
|
+
"Accept" => "application/json",
|
637
|
+
"Content-Type" => "application/x-www-form-urlencoded",
|
638
|
+
"Host" => "iam.cloud.ibm.com"
|
639
|
+
}
|
640
|
+
).to_return(
|
641
|
+
status: 200,
|
642
|
+
body: token_response.to_json,
|
643
|
+
headers: {}
|
644
|
+
)
|
645
|
+
authenticator = IBMWatson::Authenticators::IamAuthenticator.new(
|
646
|
+
apikey: "iam_apikey"
|
647
|
+
)
|
648
|
+
service = IBMWatson::LanguageTranslatorV3.new(
|
649
|
+
version: "2018-05-01",
|
650
|
+
authenticator: authenticator
|
651
|
+
)
|
652
|
+
expected = {
|
653
|
+
"languages" => [
|
654
|
+
{
|
655
|
+
"name" => "German",
|
656
|
+
"language" => "de"
|
657
|
+
},
|
658
|
+
{
|
659
|
+
"name" => "Greek",
|
660
|
+
"language" => "el"
|
661
|
+
},
|
662
|
+
{
|
663
|
+
"name" => "English",
|
664
|
+
"language" => "en"
|
665
|
+
},
|
666
|
+
{
|
667
|
+
"name" => "Esperanto",
|
668
|
+
"language" => "eo"
|
669
|
+
},
|
670
|
+
{
|
671
|
+
"name" => "Spanish",
|
672
|
+
"language" => "es"
|
673
|
+
},
|
674
|
+
{
|
675
|
+
"name" => "Chinese",
|
676
|
+
"language" => "zh"
|
677
|
+
}
|
678
|
+
]
|
679
|
+
}
|
680
|
+
stub_request(:get, "https://api.us-south.language-translator.watson.cloud.ibm.com/v3/languages?version=2018-05-01")
|
681
|
+
.with(
|
682
|
+
headers: {
|
683
|
+
"Accept" => "application/json",
|
684
|
+
"Authorization" => "Bearer " + token_response["access_token"]
|
685
|
+
}
|
686
|
+
).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
|
687
|
+
service_response = service.list_languages
|
688
|
+
assert_equal(expected, service_response.result)
|
689
|
+
end
|
629
690
|
end
|