ibm_watson 2.1.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -39
  3. data/lib/ibm_watson/assistant_v1.rb +5 -4
  4. data/lib/ibm_watson/assistant_v2.rb +3 -3
  5. data/lib/ibm_watson/discovery_v1.rb +7 -14
  6. data/lib/ibm_watson/discovery_v2.rb +109 -108
  7. data/lib/ibm_watson/language_translator_v3.rb +2 -2
  8. data/lib/ibm_watson/natural_language_understanding_v1.rb +12 -14
  9. data/lib/ibm_watson/speech_to_text_v1.rb +581 -402
  10. data/lib/ibm_watson/text_to_speech_v1.rb +87 -166
  11. data/lib/ibm_watson/version.rb +1 -1
  12. data/lib/ibm_watson.rb +0 -6
  13. metadata +2 -20
  14. data/lib/ibm_watson/compare_comply_v1.rb +0 -683
  15. data/lib/ibm_watson/natural_language_classifier_v1.rb +0 -258
  16. data/lib/ibm_watson/personality_insights_v3.rb +0 -223
  17. data/lib/ibm_watson/tone_analyzer_v3.rb +0 -230
  18. data/lib/ibm_watson/visual_recognition_v3.rb +0 -517
  19. data/lib/ibm_watson/visual_recognition_v4.rb +0 -930
  20. data/test/integration/test_compare_comply_v1.rb +0 -105
  21. data/test/integration/test_natural_language_classifier_v1.rb +0 -80
  22. data/test/integration/test_personality_insights_v3.rb +0 -81
  23. data/test/integration/test_tone_analyzer_v3.rb +0 -66
  24. data/test/integration/test_visual_recognition_v3.rb +0 -68
  25. data/test/integration/test_visual_recognition_v4.rb +0 -87
  26. data/test/unit/test_compare_comply_v1.rb +0 -232
  27. data/test/unit/test_natural_language_classifier_v1.rb +0 -191
  28. data/test/unit/test_personality_insights_v3.rb +0 -192
  29. data/test/unit/test_tone_analyzer_v3.rb +0 -217
  30. data/test/unit/test_visual_recognition_v3.rb +0 -300
  31. data/test/unit/test_visual_recognition_v4.rb +0 -422
@@ -1,232 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require("json")
4
- require_relative("./../test_helper.rb")
5
- require("webmock/minitest")
6
- SimpleCov.command_name "test:unit"
7
-
8
- WebMock.disable_net_connect!(allow_localhost: true)
9
-
10
- # Unit test for the Watson Assistant V1 Service
11
- class CompareComplyV1 < Minitest::Test
12
- include Minitest::Hooks
13
- attr_accessor :service
14
- def before_all
15
- authenticator = IBMWatson::Authenticators::NoAuthAuthenticator.new
16
- @service = IBMWatson::CompareComplyV1.new(
17
- version: "2018-10-15",
18
- authenticator: authenticator
19
- )
20
- end
21
-
22
- def test_convert_to_html
23
- file = File.open(Dir.getwd + "/resources/cnc_test.pdf")
24
- stub_request(:post, "https://api.us-south.compare-comply.watson.cloud.ibm.com/v1/html_conversion?version=2018-10-15").with do |req|
25
- # Test the headers.
26
- assert_equal(req.headers["Accept"], "application/json")
27
- assert_match(%r{\Amultipart/form-data}, req.headers["Content-Type"])
28
- end
29
- service.convert_to_html(
30
- file: file
31
- )
32
- end
33
-
34
- def test_classify_elements
35
- file = File.open(Dir.getwd + "/resources/cnc_test.pdf")
36
- stub_request(:post, "https://api.us-south.compare-comply.watson.cloud.ibm.com/v1/element_classification?version=2018-10-15").with do |req|
37
- assert_equal(req.headers["Accept"], "application/json")
38
- assert_match(%r{\Amultipart/form-data}, req.headers["Content-Type"])
39
- assert_match(/Content-Disposition: form-data/, req.body)
40
- end
41
- service.classify_elements(
42
- file: file
43
- )
44
- service.classify_elements(
45
- file: "dummy"
46
- )
47
- end
48
-
49
- def test_extract_tables
50
- file = File.open(Dir.getwd + "/resources/cnc_test.pdf")
51
- stub_request(:post, "https://api.us-south.compare-comply.watson.cloud.ibm.com/v1/tables?version=2018-10-15").with do |req|
52
- assert_equal(req.headers["Accept"], "application/json")
53
- assert_match(%r{\Amultipart/form-data}, req.headers["Content-Type"])
54
- assert_match(/Content-Disposition: form-data/, req.body)
55
- end
56
- service.extract_tables(
57
- file: file
58
- )
59
- service.extract_tables(
60
- file: "dummy"
61
- )
62
- end
63
-
64
- def test_compare_documents
65
- file = File.open(Dir.getwd + "/resources/cnc_test.pdf")
66
- stub_request(:post, "https://api.us-south.compare-comply.watson.cloud.ibm.com/v1/comparison?version=2018-10-15").with do |req|
67
- assert_equal(req.headers["Accept"], "application/json")
68
- assert_match(%r{\Amultipart/form-data}, req.headers["Content-Type"])
69
- assert_match(/Content-Disposition: form-data/, req.body)
70
- end
71
- service.compare_documents(
72
- file_1: file,
73
- file_2: file
74
- )
75
- service.compare_documents(
76
- file_1: "dummy data",
77
- file_2: "dummy data"
78
- )
79
- end
80
-
81
- def test_list_feedback
82
- message_response = {
83
- "feedback" => [
84
- {
85
- "feedback_id" => "another_one",
86
- "text" => "we the best music"
87
- }
88
- ]
89
- }
90
- headers = {
91
- "Content-Type" => "application/json"
92
- }
93
- stub_request(:get, "https://api.us-south.compare-comply.watson.cloud.ibm.com/v1/feedback?version=2018-10-15")
94
- .with(
95
- headers: {
96
- "Accept" => "application/json",
97
- "Host" => "api.us-south.compare-comply.watson.cloud.ibm.com"
98
- }
99
- ).to_return(status: 200, body: message_response.to_json, headers: headers)
100
-
101
- service_response = service.list_feedback
102
- assert_equal(message_response, service_response.result)
103
- end
104
-
105
- def test_add_feedback
106
- message_response = {
107
- "feedback_id" => "another_one"
108
- }
109
- headers = {
110
- "Content-Type" => "application/json"
111
- }
112
- stub_request(:post, "https://api.us-south.compare-comply.watson.cloud.ibm.com/v1/feedback?version=2018-10-15")
113
- .with(
114
- headers: {
115
- "Accept" => "application/json",
116
- "Host" => "api.us-south.compare-comply.watson.cloud.ibm.com"
117
- }
118
- ).to_return(status: 200, body: message_response.to_json, headers: headers)
119
-
120
- service_response = service.add_feedback(
121
- feedback_data: "we the best music"
122
- )
123
- assert_equal(message_response, service_response.result)
124
- end
125
-
126
- def test_get_feedback
127
- message_response = {
128
- "feedback_id" => "messi"
129
- }
130
- headers = {
131
- "Content-Type" => "application/json"
132
- }
133
- stub_request(:get, "https://api.us-south.compare-comply.watson.cloud.ibm.com/v1/feedback/messi?version=2018-10-15")
134
- .with(
135
- headers: {
136
- "Accept" => "application/json",
137
- "Host" => "api.us-south.compare-comply.watson.cloud.ibm.com"
138
- }
139
- ).to_return(status: 200, body: message_response.to_json, headers: headers)
140
-
141
- service_response = service.get_feedback(
142
- feedback_id: "messi"
143
- )
144
- assert_equal(message_response, service_response.result)
145
- end
146
-
147
- def test_delete_feedback
148
- message_response = "200"
149
- stub_request(:delete, "https://api.us-south.compare-comply.watson.cloud.ibm.com/v1/feedback/messi?version=2018-10-15")
150
- .with(
151
- headers: {
152
- "Accept" => "application/json",
153
- "Host" => "api.us-south.compare-comply.watson.cloud.ibm.com"
154
- }
155
- ).to_return(status: 200, body: message_response, headers: {})
156
-
157
- service_response = service.delete_feedback(
158
- feedback_id: "messi"
159
- )
160
- assert_equal(message_response, service_response.result)
161
- end
162
-
163
- def test_create_batch
164
- stub_request(:post, "https://api.us-south.compare-comply.watson.cloud.ibm.com/v1/batches?function=tables&version=2018-10-15")
165
- .with do |req|
166
- assert_equal req.headers["Accept"], "application/json"
167
- assert_match %r{\Amultipart/form-data}, req.headers["Content-Type"]
168
- end
169
-
170
- service.create_batch(
171
- function: "tables",
172
- input_credentials_file: { key: "ip" },
173
- input_bucket_location: "us",
174
- input_bucket_name: "bucket",
175
- output_credentials_file: { key: "op" },
176
- output_bucket_location: "you",
177
- output_bucket_name: "obucket"
178
- )
179
- end
180
-
181
- def test_list_batches
182
- message_response = {
183
- "batches" => []
184
- }
185
- headers = {
186
- "Content-Type" => "application/json"
187
- }
188
- stub_request(:get, "https://api.us-south.compare-comply.watson.cloud.ibm.com/v1/batches?version=2018-10-15")
189
- .with(
190
- headers: {
191
- "Accept" => "application/json",
192
- "Host" => "api.us-south.compare-comply.watson.cloud.ibm.com"
193
- }
194
- ).to_return(status: 200, body: message_response.to_json, headers: headers)
195
-
196
- service_response = service.list_batches
197
- assert_equal(message_response, service_response.result)
198
- end
199
-
200
- def test_get_batch
201
- message_response = "200"
202
- stub_request(:get, "https://api.us-south.compare-comply.watson.cloud.ibm.com/v1/batches/mo?version=2018-10-15")
203
- .with(
204
- headers: {
205
- "Accept" => "application/json",
206
- "Host" => "api.us-south.compare-comply.watson.cloud.ibm.com"
207
- }
208
- ).to_return(status: 200, body: message_response, headers: {})
209
-
210
- service_response = service.get_batch(
211
- batch_id: "mo"
212
- )
213
- assert_equal(message_response, service_response.result)
214
- end
215
-
216
- def test_update_batch
217
- message_response = "200"
218
- stub_request(:put, "https://api.us-south.compare-comply.watson.cloud.ibm.com/v1/batches/mo?action=goal&version=2018-10-15")
219
- .with(
220
- headers: {
221
- "Accept" => "application/json",
222
- "Host" => "api.us-south.compare-comply.watson.cloud.ibm.com"
223
- }
224
- ).to_return(status: 200, body: message_response, headers: {})
225
-
226
- service_response = service.update_batch(
227
- batch_id: "mo",
228
- action: "goal"
229
- )
230
- assert_equal(message_response, service_response.result)
231
- end
232
- end
@@ -1,191 +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 Natural Language Classifier V1 Service
10
- class NaturalLanguageClassifierV1Test < Minitest::Test
11
- def test_success
12
- authenticator = IBMWatson::Authenticators::BasicAuthenticator.new(
13
- username: "username",
14
- password: "password"
15
- )
16
- service = IBMWatson::NaturalLanguageClassifierV1.new(
17
- authenticator: authenticator
18
- )
19
- list_response = {
20
- "classifiers" => [
21
- {
22
- "url" => "https://api.us-south.natural-language-classifier.watson.cloud.ibm.com/natural-language-classifier-experimental/api/v1/classifiers/497EF2-nlc-00",
23
- "classifier_id" => "497EF2-nlc-00"
24
- }
25
- ]
26
- }
27
- stub_request(:get, "https://api.us-south.natural-language-classifier.watson.cloud.ibm.com/v1/classifiers")
28
- .with(
29
- headers: {
30
- "Accept" => "application/json",
31
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
32
- "Host" => "api.us-south.natural-language-classifier.watson.cloud.ibm.com"
33
- }
34
- ).to_return(status: 200, body: list_response.to_json, headers: { "Content-Type" => "application/json" })
35
- service_response = service.list_classifiers
36
- assert_equal(list_response, service_response.result)
37
-
38
- status_response = {
39
- "url" => "https://api.us-south.natural-language-classifier.watson.cloud.ibm.com/v1/classifiers/497EF2-nlc-00",
40
- "status" => "Available",
41
- "status_description" => "The classifier instance is now available and is ready to take classifier requests.",
42
- "classifier_id" => "497EF2-nlc-00"
43
- }
44
- stub_request(:get, "https://api.us-south.natural-language-classifier.watson.cloud.ibm.com/v1/classifiers/497EF2-nlc-00")
45
- .with(
46
- headers: {
47
- "Accept" => "application/json",
48
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
49
- "Host" => "api.us-south.natural-language-classifier.watson.cloud.ibm.com"
50
- }
51
- ).to_return(status: 200, body: status_response.to_json, headers: { "Content-Type" => "application/json" })
52
- service_response = service.get_classifier(
53
- classifier_id: "497EF2-nlc-00"
54
- )
55
- assert_equal(status_response, service_response.result)
56
-
57
- classify_response = {
58
- "url" => "https://api.us-south.natural-language-classifier.watson.cloud.ibm.com/v1",
59
- "text" => "test",
60
- "classes" =>
61
- [
62
- {
63
- "class_name" => "conditions",
64
- "confidence" => 0.6575315710901418
65
- },
66
- {
67
- "class_name" => "temperature",
68
- "confidence" => 0.3424684289098582
69
- }
70
- ],
71
- "classifier_id" => "497EF2-nlc-00",
72
- "top_class" => "conditions"
73
- }
74
- stub_request(:post, "https://api.us-south.natural-language-classifier.watson.cloud.ibm.com/v1/classifiers/497EF2-nlc-00/classify")
75
- .with(
76
- body: "{\"text\":\"test\"}",
77
- headers: {
78
- "Accept" => "application/json",
79
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
80
- "Content-Type" => "application/json",
81
- "Host" => "api.us-south.natural-language-classifier.watson.cloud.ibm.com"
82
- }
83
- ).to_return(status: 200, body: classify_response.to_json, headers: { "Content-Type" => "application/json" })
84
- service_response = service.classify(
85
- classifier_id: "497EF2-nlc-00",
86
- text: "test"
87
- )
88
- assert_equal(classify_response, service_response.result)
89
-
90
- create_response = {
91
- "url" => "https://api.us-south.natural-language-classifier.watson.cloud.ibm.com/v1/classifiers/497EF2-nlc-00",
92
- "status" => "Available",
93
- "status_description" => "The classifier instance is now available and is ready to take classifier requests.",
94
- "classifier_id" => "497EF2-nlc-00"
95
- }
96
- stub_request(:post, "https://api.us-south.natural-language-classifier.watson.cloud.ibm.com/v1/classifiers")
97
- .with(
98
- headers: {
99
- "Accept" => "application/json",
100
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
101
- "Host" => "api.us-south.natural-language-classifier.watson.cloud.ibm.com"
102
- }
103
- ).to_return(status: 200, body: create_response.to_json, headers: { "Content-Type" => "application/json" })
104
- training_data = File.open(Dir.getwd + "/resources/weather_data_train.csv")
105
- service_response = service.create_classifier(
106
- training_data: training_data,
107
- training_metadata: { "language" => "en" }
108
- )
109
- assert_equal(create_response, service_response.result)
110
-
111
- service_response = service.create_classifier(
112
- training_data: { "training" => "data" },
113
- training_metadata: { "language" => "en" }
114
- )
115
- assert_equal(create_response, service_response.result)
116
-
117
- stub_request(:delete, "https://api.us-south.natural-language-classifier.watson.cloud.ibm.com/v1/classifiers/497EF2-nlc-00")
118
- .with(
119
- headers: {
120
- "Accept" => "application/json",
121
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
122
- "Host" => "api.us-south.natural-language-classifier.watson.cloud.ibm.com"
123
- }
124
- ).to_return(status: 200, body: "", headers: {})
125
- service_response = service.delete_classifier(
126
- classifier_id: "497EF2-nlc-00"
127
- )
128
- assert_nil(service_response)
129
- end
130
-
131
- def test_classify_collection
132
- authenticator = IBMWatson::Authenticators::BasicAuthenticator.new(
133
- username: "username",
134
- password: "password"
135
- )
136
- service = IBMWatson::NaturalLanguageClassifierV1.new(
137
- authenticator: authenticator
138
- )
139
- classify_collection_response = {
140
- "classifier_id" => "497EF2-nlc-00",
141
- "url" => "https://api.us-south.natural-language-classifier.watson.cloud.ibm.com/v1/classifiers/10D41B-nlc-1",
142
- "collection" => [
143
- {
144
- "text" => "How hot will it be today?",
145
- "top_class" => "temperature",
146
- "classes" => [
147
- {
148
- "class_name" => "temperature",
149
- "confidence" => 0.9930558798985937
150
- },
151
- {
152
- "class_name" => "conditions",
153
- "confidence" => 0.006944120101406304
154
- }
155
- ]
156
- },
157
- {
158
- "text" => "Is it hot outside?",
159
- "top_class" => "temperature",
160
- "classes" => [
161
- {
162
- "class_name" => "temperature",
163
- "confidence" => 1
164
- },
165
- {
166
- "class_name" => "conditions",
167
- "confidence" => 0
168
- }
169
- ]
170
- }
171
- ]
172
- }
173
- classifier_id = "497EF2-nlc-00"
174
- collection = [{ "text" => "How hot will it be today?" }, { "text" => "Is it hot outside?" }]
175
- stub_request(:post, "https://api.us-south.natural-language-classifier.watson.cloud.ibm.com/v1/classifiers/497EF2-nlc-00/classify_collection")
176
- .with(
177
- body: "{\"collection\":[{\"text\":\"How hot will it be today?\"},{\"text\":\"Is it hot outside?\"}]}",
178
- headers: {
179
- "Accept" => "application/json",
180
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
181
- "Content-Type" => "application/json",
182
- "Host" => "api.us-south.natural-language-classifier.watson.cloud.ibm.com"
183
- }
184
- ).to_return(status: 200, body: classify_collection_response.to_json, headers: { "Content-Type" => "application/json" })
185
- service_response = service.classify_collection(
186
- classifier_id: classifier_id,
187
- collection: collection
188
- )
189
- assert_equal(classify_collection_response, service_response.result)
190
- end
191
- end
@@ -1,192 +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 Personality Insights V3 Service
10
- class PersonalityInsightsV3Test < Minitest::Test
11
- def test_plain_to_json
12
- profile_response = File.read(Dir.getwd + "/resources/personality-v3-expect1.txt")
13
- personality_text = File.read(Dir.getwd + "/resources/personality-v3.txt")
14
- headers = {
15
- "Content-Type" => "application/json"
16
- }
17
- expected_response = IBMWatson::DetailedResponse.new(status: 200, body: JSON.parse(profile_response), headers: headers)
18
- stub_request(:post, "https://api.us-south.personality-insights.watson.cloud.ibm.com/v3/profile?version=2017-10-13")
19
- .with(
20
- body: personality_text,
21
- headers: {
22
- "Accept" => "application/json",
23
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
24
- "Content-Type" => "text/plain;charset=utf-8",
25
- "Host" => "api.us-south.personality-insights.watson.cloud.ibm.com"
26
- }
27
- ).to_return(status: 200, body: profile_response, headers: headers)
28
- authenticator = IBMWatson::Authenticators::BasicAuthenticator.new(
29
- username: "username",
30
- password: "password"
31
- )
32
- service = IBMWatson::PersonalityInsightsV3.new(
33
- version: "2017-10-13",
34
- authenticator: authenticator
35
- )
36
- service.service_url = "https://api.us-south.personality-insights.watson.cloud.ibm.com"
37
- service_response = service.profile(
38
- accept: "application/json",
39
- content: personality_text,
40
- content_type: "text/plain;charset=utf-8"
41
- )
42
- assert_equal(expected_response.status, service_response.status)
43
- assert_equal(expected_response.result, service_response.result)
44
- expected_response.headers.each_key do |key|
45
- assert(service_response.headers.key?(key))
46
- assert(expected_response.headers[key] == service_response.headers[key])
47
- end
48
-
49
- stub_request(:post, "https://api.us-south.personality-insights.watson.cloud.ibm.com/v3/profile?version=2017-10-13")
50
- .with(
51
- body: { "personality" => "text" }.to_json,
52
- headers: {
53
- "Accept" => "application/json",
54
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
55
- "Content-Type" => "application/json",
56
- "Host" => "api.us-south.personality-insights.watson.cloud.ibm.com"
57
- }
58
- ).to_return(status: 200, body: { "profile" => "response" }.to_json, headers: headers)
59
- service_response = service.profile(
60
- accept: "application/json",
61
- content: { "personality" => "text" },
62
- content_type: "application/json"
63
- )
64
- assert_equal({ "profile" => "response" }, service_response.result)
65
- end
66
-
67
- def test_json_to_json
68
- profile_response = File.read(Dir.getwd + "/resources/personality-v3-expect2.txt")
69
- personality_text = File.read(Dir.getwd + "/resources/personality-v3.json")
70
- headers = {
71
- "Content-Type" => "application/json"
72
- }
73
- expected_response = IBMWatson::DetailedResponse.new(status: 200, body: JSON.parse(profile_response), headers: headers)
74
- stub_request(:post, "https://api.us-south.personality-insights.watson.cloud.ibm.com/v3/profile?consumption_preferences=true&raw_scores=true&version=2017-10-13")
75
- .with(
76
- body: personality_text,
77
- headers: {
78
- "Accept" => "application/json",
79
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
80
- "Content-Type" => "application/json",
81
- "Host" => "api.us-south.personality-insights.watson.cloud.ibm.com"
82
- }
83
- ).to_return(status: 200, body: profile_response, headers: headers)
84
- authenticator = IBMWatson::Authenticators::BasicAuthenticator.new(
85
- username: "username",
86
- password: "password"
87
- )
88
- service = IBMWatson::PersonalityInsightsV3.new(
89
- version: "2017-10-13",
90
- authenticator: authenticator
91
- )
92
- service.service_url = "https://api.us-south.personality-insights.watson.cloud.ibm.com"
93
- service_response = service.profile(
94
- accept: "application/json",
95
- content: personality_text,
96
- content_type: "application/json",
97
- raw_scores: true,
98
- consumption_preferences: true
99
- )
100
- assert_equal(expected_response.status, service_response.status)
101
- assert_equal(expected_response.result, service_response.result)
102
- expected_response.headers.each_key do |key|
103
- assert(service_response.headers.key?(key))
104
- assert(expected_response.headers[key] == service_response.headers[key])
105
- end
106
- end
107
-
108
- def test_json_to_csv
109
- profile_response = File.read(Dir.getwd + "/resources/personality-v3-expect3.txt")
110
- personality_text = File.read(Dir.getwd + "/resources/personality-v3.json")
111
- headers = {
112
- "Content-Type" => "text/csv"
113
- }
114
- expected_response = IBMWatson::DetailedResponse.new(status: 200, body: profile_response, headers: headers)
115
- stub_request(:post, "https://api.us-south.personality-insights.watson.cloud.ibm.com/v3/profile?consumption_preferences=true&csv_headers=true&raw_scores=true&version=2017-10-13")
116
- .with(
117
- body: personality_text,
118
- headers: {
119
- "Accept" => "text/csv",
120
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
121
- "Content-Type" => "application/json",
122
- "Host" => "api.us-south.personality-insights.watson.cloud.ibm.com"
123
- }
124
- ).to_return(status: 200, body: profile_response, headers: headers)
125
- authenticator = IBMWatson::Authenticators::BasicAuthenticator.new(
126
- username: "username",
127
- password: "password"
128
- )
129
- service = IBMWatson::PersonalityInsightsV3.new(
130
- version: "2017-10-13",
131
- authenticator: authenticator
132
- )
133
- service.service_url = "https://api.us-south.personality-insights.watson.cloud.ibm.com"
134
- service_response = service.profile(
135
- content: personality_text,
136
- content_type: "application/json",
137
- accept: "text/csv",
138
- csv_headers: true,
139
- raw_scores: true,
140
- consumption_preferences: true
141
- )
142
- assert_equal(expected_response.status, service_response.status)
143
- assert_equal(expected_response.result, service_response.result)
144
- expected_response.headers.each_key do |key|
145
- assert(service_response.headers.key?(key))
146
- assert(expected_response.headers[key] == service_response.headers[key])
147
- end
148
- end
149
-
150
- def test_plain_to_json_es
151
- profile_response = JSON.parse(File.read(Dir.getwd + "/resources/personality-v3-expect4.txt"))
152
- personality_text = File.read(Dir.getwd + "/resources/personality-v3-es.txt")
153
- headers = {
154
- "Content-Type" => "application/json"
155
- }
156
- expected_response = IBMWatson::DetailedResponse.new(status: 200, body: profile_response, headers: headers)
157
- stub_request(:post, "https://api.us-south.personality-insights.watson.cloud.ibm.com/v3/profile?version=2017-10-13")
158
- .with(
159
- body: personality_text,
160
- headers: {
161
- "Accept" => "application/json",
162
- "Accept-Language" => "es",
163
- "Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
164
- "Content-Language" => "es",
165
- "Content-Type" => "text/plain;charset=utf-8",
166
- "Host" => "api.us-south.personality-insights.watson.cloud.ibm.com"
167
- }
168
- ).to_return(status: 200, body: profile_response.to_json, headers: headers)
169
- authenticator = IBMWatson::Authenticators::BasicAuthenticator.new(
170
- username: "username",
171
- password: "password"
172
- )
173
- service = IBMWatson::PersonalityInsightsV3.new(
174
- version: "2017-10-13",
175
- authenticator: authenticator
176
- )
177
- service.service_url = "https://api.us-south.personality-insights.watson.cloud.ibm.com"
178
- service_response = service.profile(
179
- accept: "application/json",
180
- content: personality_text,
181
- content_type: "text/plain;charset=utf-8",
182
- content_language: "es",
183
- accept_language: "es"
184
- )
185
- assert_equal(expected_response.status, service_response.status)
186
- assert_equal(expected_response.result, service_response.result)
187
- expected_response.headers.each_key do |key|
188
- assert(service_response.headers.key?(key))
189
- assert(expected_response.headers[key] == service_response.headers[key])
190
- end
191
- end
192
- end