ibm_watson 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +40 -4
- data/lib/ibm_watson/assistant_v1.rb +54 -8
- data/lib/ibm_watson/assistant_v2.rb +5 -1
- data/lib/ibm_watson/compare_comply_v1.rb +27 -16
- data/lib/ibm_watson/discovery_v1.rb +96 -0
- data/lib/ibm_watson/language_translator_v3.rb +8 -0
- data/lib/ibm_watson/natural_language_classifier_v1.rb +8 -1
- data/lib/ibm_watson/natural_language_understanding_v1.rb +11 -7
- data/lib/ibm_watson/personality_insights_v3.rb +16 -9
- data/lib/ibm_watson/speech_to_text_v1.rb +70 -11
- data/lib/ibm_watson/text_to_speech_v1.rb +42 -23
- data/lib/ibm_watson/tone_analyzer_v3.rb +5 -2
- data/lib/ibm_watson/version.rb +1 -1
- data/lib/ibm_watson/visual_recognition_v3.rb +10 -0
- data/lib/ibm_watson/watson_service.rb +59 -13
- data/test/unit/test_discovery_v1.rb +21 -2
- data/test/unit/test_watson_service.rb +15 -0
- metadata +2 -2
@@ -85,6 +85,7 @@ module IBMWatson
|
|
85
85
|
args = defaults.merge(args)
|
86
86
|
args[:vcap_services_name] = "text_to_speech"
|
87
87
|
super
|
88
|
+
args[:display_name] = "Text to Speech"
|
88
89
|
end
|
89
90
|
|
90
91
|
#########################
|
@@ -99,11 +100,12 @@ module IBMWatson
|
|
99
100
|
# about a specific voice, use the **Get a voice** method.
|
100
101
|
#
|
101
102
|
# **See also:** [Specifying a
|
102
|
-
# voice](https://
|
103
|
+
# voice](https://cloud.ibm.com/docs/services/text-to-speech/http.html#voices).
|
103
104
|
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
|
104
105
|
def list_voices
|
105
106
|
headers = {
|
106
107
|
}
|
108
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=text_to_speech;service_version=V1;operation_id=list_voices"
|
107
109
|
|
108
110
|
method_url = "/v1/voices"
|
109
111
|
|
@@ -125,7 +127,7 @@ module IBMWatson
|
|
125
127
|
# information about all available voices, use the **List voices** method.
|
126
128
|
#
|
127
129
|
# **See also:** [Specifying a
|
128
|
-
# voice](https://
|
130
|
+
# voice](https://cloud.ibm.com/docs/services/text-to-speech/http.html#voices).
|
129
131
|
# @param voice [String] The voice for which information is to be returned.
|
130
132
|
# @param customization_id [String] The customization ID (GUID) of a custom voice model for which information is to be
|
131
133
|
# returned. You must make the request with service credentials created for the
|
@@ -137,6 +139,7 @@ module IBMWatson
|
|
137
139
|
|
138
140
|
headers = {
|
139
141
|
}
|
142
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=text_to_speech;service_version=V1;operation_id=get_voice"
|
140
143
|
|
141
144
|
params = {
|
142
145
|
"customization_id" => customization_id
|
@@ -168,7 +171,7 @@ module IBMWatson
|
|
168
171
|
# pass a maximum of 5 KB of text to the service.
|
169
172
|
#
|
170
173
|
# **See also:** [Synthesizing text to
|
171
|
-
# audio](https://
|
174
|
+
# audio](https://cloud.ibm.com/docs/services/text-to-speech/http.html#synthesize).
|
172
175
|
#
|
173
176
|
# ### Audio formats (accept types)
|
174
177
|
#
|
@@ -236,7 +239,7 @@ module IBMWatson
|
|
236
239
|
#
|
237
240
|
# For more information about specifying an audio format, including additional
|
238
241
|
# details about some of the formats, see [Specifying an audio
|
239
|
-
# format](https://
|
242
|
+
# format](https://cloud.ibm.com/docs/services/text-to-speech/http.html#format).
|
240
243
|
#
|
241
244
|
# ### Warning messages
|
242
245
|
#
|
@@ -266,6 +269,7 @@ module IBMWatson
|
|
266
269
|
headers = {
|
267
270
|
"Accept" => accept
|
268
271
|
}
|
272
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=text_to_speech;service_version=V1;operation_id=synthesize"
|
269
273
|
|
270
274
|
params = {
|
271
275
|
"voice" => voice,
|
@@ -303,7 +307,7 @@ module IBMWatson
|
|
303
307
|
# **Note:** This method is currently a beta release.
|
304
308
|
#
|
305
309
|
# **See also:** [Querying a word from a
|
306
|
-
# language](https://
|
310
|
+
# language](https://cloud.ibm.com/docs/services/text-to-speech/custom-entries.html#cuWordsQueryLanguage).
|
307
311
|
# @param text [String] The word for which the pronunciation is requested.
|
308
312
|
# @param voice [String] A voice that specifies the language in which the pronunciation is to be returned.
|
309
313
|
# All voices for the same language (for example, `en-US`) return the same
|
@@ -323,6 +327,7 @@ module IBMWatson
|
|
323
327
|
|
324
328
|
headers = {
|
325
329
|
}
|
330
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=text_to_speech;service_version=V1;operation_id=get_pronunciation"
|
326
331
|
|
327
332
|
params = {
|
328
333
|
"text" => text,
|
@@ -357,7 +362,7 @@ module IBMWatson
|
|
357
362
|
# **Note:** This method is currently a beta release.
|
358
363
|
#
|
359
364
|
# **See also:** [Creating a custom
|
360
|
-
# model](https://
|
365
|
+
# model](https://cloud.ibm.com/docs/services/text-to-speech/custom-models.html#cuModelsCreate).
|
361
366
|
# @param name [String] The name of the new custom voice model.
|
362
367
|
# @param language [String] The language of the new custom voice model. Omit the parameter to use the the
|
363
368
|
# default language, `en-US`.
|
@@ -369,6 +374,7 @@ module IBMWatson
|
|
369
374
|
|
370
375
|
headers = {
|
371
376
|
}
|
377
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=text_to_speech;service_version=V1;operation_id=create_voice_model"
|
372
378
|
|
373
379
|
data = {
|
374
380
|
"name" => name,
|
@@ -401,7 +407,7 @@ module IBMWatson
|
|
401
407
|
# **Note:** This method is currently a beta release.
|
402
408
|
#
|
403
409
|
# **See also:** [Querying all custom
|
404
|
-
# models](https://
|
410
|
+
# models](https://cloud.ibm.com/docs/services/text-to-speech/custom-models.html#cuModelsQueryAll).
|
405
411
|
# @param language [String] The language for which custom voice models that are owned by the requesting
|
406
412
|
# service credentials are to be returned. Omit the parameter to see all custom voice
|
407
413
|
# models that are owned by the requester.
|
@@ -409,6 +415,7 @@ module IBMWatson
|
|
409
415
|
def list_voice_models(language: nil)
|
410
416
|
headers = {
|
411
417
|
}
|
418
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=text_to_speech;service_version=V1;operation_id=list_voice_models"
|
412
419
|
|
413
420
|
params = {
|
414
421
|
"language" => language
|
@@ -454,10 +461,11 @@ module IBMWatson
|
|
454
461
|
#
|
455
462
|
# **See also:**
|
456
463
|
# * [Updating a custom
|
457
|
-
# model](https://
|
464
|
+
# model](https://cloud.ibm.com/docs/services/text-to-speech/custom-models.html#cuModelsUpdate)
|
458
465
|
# * [Adding words to a Japanese custom
|
459
|
-
# model](https://
|
460
|
-
# * [Understanding
|
466
|
+
# model](https://cloud.ibm.com/docs/services/text-to-speech/custom-entries.html#cuJapaneseAdd)
|
467
|
+
# * [Understanding
|
468
|
+
# customization](https://cloud.ibm.com/docs/services/text-to-speech/custom-intro.html).
|
461
469
|
# @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
|
462
470
|
# with service credentials created for the instance of the service that owns the
|
463
471
|
# custom model.
|
@@ -472,6 +480,7 @@ module IBMWatson
|
|
472
480
|
|
473
481
|
headers = {
|
474
482
|
}
|
483
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=text_to_speech;service_version=V1;operation_id=update_voice_model"
|
475
484
|
|
476
485
|
data = {
|
477
486
|
"name" => name,
|
@@ -502,7 +511,7 @@ module IBMWatson
|
|
502
511
|
# **Note:** This method is currently a beta release.
|
503
512
|
#
|
504
513
|
# **See also:** [Querying a custom
|
505
|
-
# model](https://
|
514
|
+
# model](https://cloud.ibm.com/docs/services/text-to-speech/custom-models.html#cuModelsQuery).
|
506
515
|
# @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
|
507
516
|
# with service credentials created for the instance of the service that owns the
|
508
517
|
# custom model.
|
@@ -512,6 +521,7 @@ module IBMWatson
|
|
512
521
|
|
513
522
|
headers = {
|
514
523
|
}
|
524
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=text_to_speech;service_version=V1;operation_id=get_voice_model"
|
515
525
|
|
516
526
|
method_url = "/v1/customizations/%s" % [ERB::Util.url_encode(customization_id)]
|
517
527
|
|
@@ -533,7 +543,7 @@ module IBMWatson
|
|
533
543
|
# **Note:** This method is currently a beta release.
|
534
544
|
#
|
535
545
|
# **See also:** [Deleting a custom
|
536
|
-
# model](https://
|
546
|
+
# model](https://cloud.ibm.com/docs/services/text-to-speech/custom-models.html#cuModelsDelete).
|
537
547
|
# @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
|
538
548
|
# with service credentials created for the instance of the service that owns the
|
539
549
|
# custom model.
|
@@ -543,6 +553,7 @@ module IBMWatson
|
|
543
553
|
|
544
554
|
headers = {
|
545
555
|
}
|
556
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=text_to_speech;service_version=V1;operation_id=delete_voice_model"
|
546
557
|
|
547
558
|
method_url = "/v1/customizations/%s" % [ERB::Util.url_encode(customization_id)]
|
548
559
|
|
@@ -585,10 +596,11 @@ module IBMWatson
|
|
585
596
|
#
|
586
597
|
# **See also:**
|
587
598
|
# * [Adding multiple words to a custom
|
588
|
-
# model](https://
|
599
|
+
# model](https://cloud.ibm.com/docs/services/text-to-speech/custom-entries.html#cuWordsAdd)
|
589
600
|
# * [Adding words to a Japanese custom
|
590
|
-
# model](https://
|
591
|
-
# * [Understanding
|
601
|
+
# model](https://cloud.ibm.com/docs/services/text-to-speech/custom-entries.html#cuJapaneseAdd)
|
602
|
+
# * [Understanding
|
603
|
+
# customization](https://cloud.ibm.com/docs/services/text-to-speech/custom-intro.html).
|
592
604
|
# @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
|
593
605
|
# with service credentials created for the instance of the service that owns the
|
594
606
|
# custom model.
|
@@ -608,6 +620,7 @@ module IBMWatson
|
|
608
620
|
|
609
621
|
headers = {
|
610
622
|
}
|
623
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=text_to_speech;service_version=V1;operation_id=add_words"
|
611
624
|
|
612
625
|
data = {
|
613
626
|
"words" => words
|
@@ -636,7 +649,7 @@ module IBMWatson
|
|
636
649
|
# **Note:** This method is currently a beta release.
|
637
650
|
#
|
638
651
|
# **See also:** [Querying all words from a custom
|
639
|
-
# model](https://
|
652
|
+
# model](https://cloud.ibm.com/docs/services/text-to-speech/custom-entries.html#cuWordsQueryModel).
|
640
653
|
# @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
|
641
654
|
# with service credentials created for the instance of the service that owns the
|
642
655
|
# custom model.
|
@@ -646,6 +659,7 @@ module IBMWatson
|
|
646
659
|
|
647
660
|
headers = {
|
648
661
|
}
|
662
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=text_to_speech;service_version=V1;operation_id=list_words"
|
649
663
|
|
650
664
|
method_url = "/v1/customizations/%s/words" % [ERB::Util.url_encode(customization_id)]
|
651
665
|
|
@@ -685,10 +699,11 @@ module IBMWatson
|
|
685
699
|
#
|
686
700
|
# **See also:**
|
687
701
|
# * [Adding a single word to a custom
|
688
|
-
# model](https://
|
702
|
+
# model](https://cloud.ibm.com/docs/services/text-to-speech/custom-entries.html#cuWordAdd)
|
689
703
|
# * [Adding words to a Japanese custom
|
690
|
-
# model](https://
|
691
|
-
# * [Understanding
|
704
|
+
# model](https://cloud.ibm.com/docs/services/text-to-speech/custom-entries.html#cuJapaneseAdd)
|
705
|
+
# * [Understanding
|
706
|
+
# customization](https://cloud.ibm.com/docs/services/text-to-speech/custom-intro.html).
|
692
707
|
# @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
|
693
708
|
# with service credentials created for the instance of the service that owns the
|
694
709
|
# custom model.
|
@@ -702,7 +717,7 @@ module IBMWatson
|
|
702
717
|
# with or without a single part of speech, for any word; you cannot create multiple
|
703
718
|
# entries with different parts of speech for the same word. For more information,
|
704
719
|
# see [Working with Japanese
|
705
|
-
# entries](https://
|
720
|
+
# entries](https://cloud.ibm.com/docs/services/text-to-speech/custom-rules.html#jaNotes).
|
706
721
|
# @return [nil]
|
707
722
|
def add_word(customization_id:, word:, translation:, part_of_speech: nil)
|
708
723
|
raise ArgumentError.new("customization_id must be provided") if customization_id.nil?
|
@@ -713,6 +728,7 @@ module IBMWatson
|
|
713
728
|
|
714
729
|
headers = {
|
715
730
|
}
|
731
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=text_to_speech;service_version=V1;operation_id=add_word"
|
716
732
|
|
717
733
|
data = {
|
718
734
|
"translation" => translation,
|
@@ -741,7 +757,7 @@ module IBMWatson
|
|
741
757
|
# **Note:** This method is currently a beta release.
|
742
758
|
#
|
743
759
|
# **See also:** [Querying a single word from a custom
|
744
|
-
# model](https://
|
760
|
+
# model](https://cloud.ibm.com/docs/services/text-to-speech/custom-entries.html#cuWordQueryModel).
|
745
761
|
# @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
|
746
762
|
# with service credentials created for the instance of the service that owns the
|
747
763
|
# custom model.
|
@@ -754,6 +770,7 @@ module IBMWatson
|
|
754
770
|
|
755
771
|
headers = {
|
756
772
|
}
|
773
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=text_to_speech;service_version=V1;operation_id=get_word"
|
757
774
|
|
758
775
|
method_url = "/v1/customizations/%s/words/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(word)]
|
759
776
|
|
@@ -776,7 +793,7 @@ module IBMWatson
|
|
776
793
|
# **Note:** This method is currently a beta release.
|
777
794
|
#
|
778
795
|
# **See also:** [Deleting a word from a custom
|
779
|
-
# model](https://
|
796
|
+
# model](https://cloud.ibm.com/docs/services/text-to-speech/custom-entries.html#cuWordDelete).
|
780
797
|
# @param customization_id [String] The customization ID (GUID) of the custom voice model. You must make the request
|
781
798
|
# with service credentials created for the instance of the service that owns the
|
782
799
|
# custom model.
|
@@ -789,6 +806,7 @@ module IBMWatson
|
|
789
806
|
|
790
807
|
headers = {
|
791
808
|
}
|
809
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=text_to_speech;service_version=V1;operation_id=delete_word"
|
792
810
|
|
793
811
|
method_url = "/v1/customizations/%s/words/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(word)]
|
794
812
|
|
@@ -817,7 +835,7 @@ module IBMWatson
|
|
817
835
|
# with a request that passes the data.
|
818
836
|
#
|
819
837
|
# **See also:** [Information
|
820
|
-
# security](https://
|
838
|
+
# security](https://cloud.ibm.com/docs/services/text-to-speech/information-security.html).
|
821
839
|
# @param customer_id [String] The customer ID for which all data is to be deleted.
|
822
840
|
# @return [nil]
|
823
841
|
def delete_user_data(customer_id:)
|
@@ -825,6 +843,7 @@ module IBMWatson
|
|
825
843
|
|
826
844
|
headers = {
|
827
845
|
}
|
846
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=text_to_speech;service_version=V1;operation_id=delete_user_data"
|
828
847
|
|
829
848
|
params = {
|
830
849
|
"customer_id" => customer_id
|
@@ -90,6 +90,7 @@ module IBMWatson
|
|
90
90
|
args[:vcap_services_name] = "tone_analyzer"
|
91
91
|
super
|
92
92
|
@version = args[:version]
|
93
|
+
args[:display_name] = "Tone Analyzer"
|
93
94
|
end
|
94
95
|
|
95
96
|
#########################
|
@@ -118,7 +119,7 @@ module IBMWatson
|
|
118
119
|
# analyzes only the textual content.
|
119
120
|
#
|
120
121
|
# **See also:** [Using the general-purpose
|
121
|
-
# endpoint](https://
|
122
|
+
# endpoint](https://cloud.ibm.com/docs/services/tone-analyzer/using-tone.html#using-the-general-purpose-endpoint).
|
122
123
|
# @param tone_input [ToneInput] JSON, plain text, or HTML input that contains the content to be analyzed. For JSON
|
123
124
|
# input, provide an object of type `ToneInput`.
|
124
125
|
# @param content_type [String] The type of the input. A character encoding can be specified by including a
|
@@ -153,6 +154,7 @@ module IBMWatson
|
|
153
154
|
"Content-Language" => content_language,
|
154
155
|
"Accept-Language" => accept_language
|
155
156
|
}
|
157
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=tone_analyzer;service_version=V3;operation_id=tone"
|
156
158
|
|
157
159
|
params = {
|
158
160
|
"version" => @version,
|
@@ -195,7 +197,7 @@ module IBMWatson
|
|
195
197
|
# character encoding for JSON content is effectively always UTF-8.
|
196
198
|
#
|
197
199
|
# **See also:** [Using the customer-engagement
|
198
|
-
# endpoint](https://
|
200
|
+
# endpoint](https://cloud.ibm.com/docs/services/tone-analyzer/using-tone-chat.html#using-the-customer-engagement-endpoint).
|
199
201
|
# @param utterances [Array[Utterance]] An array of `Utterance` objects that provides the input content that the service
|
200
202
|
# is to analyze.
|
201
203
|
# @param content_language [String] The language of the input text for the request: English or French. Regional
|
@@ -217,6 +219,7 @@ module IBMWatson
|
|
217
219
|
"Content-Language" => content_language,
|
218
220
|
"Accept-Language" => accept_language
|
219
221
|
}
|
222
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=tone_analyzer;service_version=V3;operation_id=tone_chat"
|
220
223
|
|
221
224
|
params = {
|
222
225
|
"version" => @version
|
data/lib/ibm_watson/version.rb
CHANGED
@@ -70,6 +70,7 @@ module IBMWatson
|
|
70
70
|
args[:vcap_services_name] = "watson_vision_combined"
|
71
71
|
super
|
72
72
|
@version = args[:version]
|
73
|
+
args[:display_name] = "Visual Recognition"
|
73
74
|
end
|
74
75
|
|
75
76
|
#########################
|
@@ -119,6 +120,7 @@ module IBMWatson
|
|
119
120
|
headers = {
|
120
121
|
"Accept-Language" => accept_language
|
121
122
|
}
|
123
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=watson_vision_combined;service_version=V3;operation_id=classify"
|
122
124
|
|
123
125
|
params = {
|
124
126
|
"version" => @version
|
@@ -197,6 +199,7 @@ module IBMWatson
|
|
197
199
|
headers = {
|
198
200
|
"Accept-Language" => accept_language
|
199
201
|
}
|
202
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=watson_vision_combined;service_version=V3;operation_id=detect_faces"
|
200
203
|
|
201
204
|
params = {
|
202
205
|
"version" => @version
|
@@ -271,6 +274,7 @@ module IBMWatson
|
|
271
274
|
|
272
275
|
headers = {
|
273
276
|
}
|
277
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=watson_vision_combined;service_version=V3;operation_id=create_classifier"
|
274
278
|
|
275
279
|
params = {
|
276
280
|
"version" => @version
|
@@ -320,6 +324,7 @@ module IBMWatson
|
|
320
324
|
def list_classifiers(verbose: nil)
|
321
325
|
headers = {
|
322
326
|
}
|
327
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=watson_vision_combined;service_version=V3;operation_id=list_classifiers"
|
323
328
|
|
324
329
|
params = {
|
325
330
|
"version" => @version,
|
@@ -349,6 +354,7 @@ module IBMWatson
|
|
349
354
|
|
350
355
|
headers = {
|
351
356
|
}
|
357
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=watson_vision_combined;service_version=V3;operation_id=get_classifier"
|
352
358
|
|
353
359
|
params = {
|
354
360
|
"version" => @version
|
@@ -412,6 +418,7 @@ module IBMWatson
|
|
412
418
|
|
413
419
|
headers = {
|
414
420
|
}
|
421
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=watson_vision_combined;service_version=V3;operation_id=update_classifier"
|
415
422
|
|
416
423
|
params = {
|
417
424
|
"version" => @version
|
@@ -460,6 +467,7 @@ module IBMWatson
|
|
460
467
|
|
461
468
|
headers = {
|
462
469
|
}
|
470
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=watson_vision_combined;service_version=V3;operation_id=delete_classifier"
|
463
471
|
|
464
472
|
params = {
|
465
473
|
"version" => @version
|
@@ -492,6 +500,7 @@ module IBMWatson
|
|
492
500
|
|
493
501
|
headers = {
|
494
502
|
}
|
503
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=watson_vision_combined;service_version=V3;operation_id=get_core_ml_model"
|
495
504
|
|
496
505
|
params = {
|
497
506
|
"version" => @version
|
@@ -529,6 +538,7 @@ module IBMWatson
|
|
529
538
|
|
530
539
|
headers = {
|
531
540
|
}
|
541
|
+
headers["X-IBMCloud-SDK-Analytics"] = "service_name=watson_vision_combined;service_version=V3;operation_id=delete_user_data"
|
532
542
|
|
533
543
|
params = {
|
534
544
|
"version" => @version,
|
@@ -18,9 +18,11 @@ require_relative("./version.rb")
|
|
18
18
|
# config.log_response = true
|
19
19
|
# end
|
20
20
|
|
21
|
+
DEFAULT_CREDENTIALS_FILE_NAME = "ibm-credentials.env"
|
22
|
+
|
21
23
|
# Class for interacting with the Watson API
|
22
24
|
class WatsonService
|
23
|
-
attr_accessor :password, :url, :username
|
25
|
+
attr_accessor :password, :url, :username, :display_name
|
24
26
|
attr_reader :conn, :token_manager
|
25
27
|
def initialize(vars)
|
26
28
|
defaults = {
|
@@ -30,7 +32,8 @@ class WatsonService
|
|
30
32
|
use_vcap_services: true,
|
31
33
|
iam_apikey: nil,
|
32
34
|
iam_access_token: nil,
|
33
|
-
iam_url: nil
|
35
|
+
iam_url: nil,
|
36
|
+
display_name: nil
|
34
37
|
}
|
35
38
|
vars = defaults.merge(vars)
|
36
39
|
@url = vars[:url]
|
@@ -41,6 +44,7 @@ class WatsonService
|
|
41
44
|
@temp_headers = nil
|
42
45
|
@icp_prefix = vars[:password]&.start_with?("icp-") ? true : false
|
43
46
|
@disable_ssl = false
|
47
|
+
@display_name = vars[:display_name]
|
44
48
|
|
45
49
|
user_agent_string = "watson-apis-ruby-sdk-" + IBMWatson::VERSION
|
46
50
|
user_agent_string += " #{RbConfig::CONFIG["host"]}"
|
@@ -49,17 +53,6 @@ class WatsonService
|
|
49
53
|
headers = {
|
50
54
|
"User-Agent" => user_agent_string
|
51
55
|
}
|
52
|
-
if vars[:use_vcap_services]
|
53
|
-
@vcap_service_credentials = load_from_vcap_services(service_name: vars[:vcap_services_name])
|
54
|
-
if !@vcap_service_credentials.nil? && @vcap_service_credentials.instance_of?(Hash)
|
55
|
-
@url = @vcap_service_credentials["url"]
|
56
|
-
@username = @vcap_service_credentials["username"] if @vcap_service_credentials.key?("username")
|
57
|
-
@password = @vcap_service_credentials["password"] if @vcap_service_credentials.key?("password")
|
58
|
-
@iam_apikey = @vcap_service_credentials["iam_apikey"] if @vcap_service_credentials.key?("iam_apikey")
|
59
|
-
@iam_access_token = @vcap_service_credentials["iam_access_token"] if @vcap_service_credentials.key?("iam_access_token")
|
60
|
-
@iam_url = @vcap_service_credentials["iam_url"] if @vcap_service_credentials.key?("iam_url")
|
61
|
-
end
|
62
|
-
end
|
63
56
|
|
64
57
|
if !vars[:iam_access_token].nil? || !vars[:iam_apikey].nil?
|
65
58
|
set_token_manager(iam_apikey: vars[:iam_apikey], iam_access_token: vars[:iam_access_token], iam_url: vars[:iam_url])
|
@@ -71,6 +64,24 @@ class WatsonService
|
|
71
64
|
@password = vars[:password]
|
72
65
|
end
|
73
66
|
end
|
67
|
+
|
68
|
+
if @display_name && !@username && !@iam_apikey
|
69
|
+
service_name = @display_name.sub(" ", "_").downcase
|
70
|
+
load_from_credential_file(service_name)
|
71
|
+
end
|
72
|
+
|
73
|
+
if vars[:use_vcap_services] && !@username && !@iam_apikey
|
74
|
+
@vcap_service_credentials = load_from_vcap_services(service_name: vars[:vcap_services_name])
|
75
|
+
if !@vcap_service_credentials.nil? && @vcap_service_credentials.instance_of?(Hash)
|
76
|
+
@url = @vcap_service_credentials["url"]
|
77
|
+
@username = @vcap_service_credentials["username"] if @vcap_service_credentials.key?("username")
|
78
|
+
@password = @vcap_service_credentials["password"] if @vcap_service_credentials.key?("password")
|
79
|
+
@iam_apikey = @vcap_service_credentials["iam_apikey"] if @vcap_service_credentials.key?("iam_apikey")
|
80
|
+
@iam_access_token = @vcap_service_credentials["iam_access_token"] if @vcap_service_credentials.key?("iam_access_token")
|
81
|
+
@iam_url = @vcap_service_credentials["iam_url"] if @vcap_service_credentials.key?("iam_url")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
74
85
|
raise ArgumentError.new('The username shouldn\'t start or end with curly brackets or quotes. Be sure to remove any {} and \" characters surrounding your username') if check_bad_first_or_last_char(@username)
|
75
86
|
raise ArgumentError.new('The password shouldn\'t start or end with curly brackets or quotes. Be sure to remove any {} and \" characters surrounding your password') if check_bad_first_or_last_char(@password)
|
76
87
|
raise ArgumentError.new('The url shouldn\'t start or end with curly brackets or quotes. Be sure to remove any {} and \" characters surrounding your url') if check_bad_first_or_last_char(@url)
|
@@ -81,6 +92,31 @@ class WatsonService
|
|
81
92
|
)
|
82
93
|
end
|
83
94
|
|
95
|
+
# Initiates the credentials based on the credential file
|
96
|
+
def load_from_credential_file(service_name, separator = "=")
|
97
|
+
credential_file_path = ENV["IBM_CREDENTIALS_FILE"]
|
98
|
+
|
99
|
+
# Home directory
|
100
|
+
if credential_file_path.nil?
|
101
|
+
file_path = ENV["HOME"] + DEFAULT_CREDENTIALS_FILE_NAME
|
102
|
+
credential_file_path = file_path if File.exist?(file_path)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Top-level directory of the project
|
106
|
+
if credential_file_path.nil?
|
107
|
+
file_path = File.join(File.dirname(__FILE__), "/../../" + DEFAULT_CREDENTIALS_FILE_NAME)
|
108
|
+
credential_file_path = file_path if File.exist?(file_path)
|
109
|
+
end
|
110
|
+
|
111
|
+
return if credential_file_path.nil?
|
112
|
+
|
113
|
+
file_contents = File.open(credential_file_path, "r")
|
114
|
+
file_contents.each_line do |line|
|
115
|
+
key_val = line.strip.split(separator)
|
116
|
+
set_credential_based_on_type(service_name, key_val[0].downcase, key_val[1].downcase) if key_val.length == 2
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
84
120
|
def load_from_vcap_services(service_name:)
|
85
121
|
vcap_services = ENV["VCAP_SERVICES"]
|
86
122
|
unless vcap_services.nil?
|
@@ -200,6 +236,16 @@ class WatsonService
|
|
200
236
|
|
201
237
|
private
|
202
238
|
|
239
|
+
def set_credential_based_on_type(service_name, key, value)
|
240
|
+
return unless key.include?(service_name)
|
241
|
+
|
242
|
+
@iam_apikey = value if key.include?("iam_apikey")
|
243
|
+
@iam_url = value if key.include?("iam_url")
|
244
|
+
@url = value if key.include?("url")
|
245
|
+
@username = value if key.include?("username")
|
246
|
+
@password = value if key.include?("password")
|
247
|
+
end
|
248
|
+
|
203
249
|
def check_bad_first_or_last_char(str)
|
204
250
|
return str.start_with?("{", "\"") || str.end_with?("}", "\"") unless str.nil?
|
205
251
|
end
|
@@ -1369,14 +1369,33 @@ class DiscoveryV1Test < Minitest::Test
|
|
1369
1369
|
assert_equal({ "updated" => "true" }, service_response.result)
|
1370
1370
|
end
|
1371
1371
|
|
1372
|
+
def test_get_stopword_list_status
|
1373
|
+
service = IBMWatson::DiscoveryV1.new(
|
1374
|
+
username: "username",
|
1375
|
+
password: "password",
|
1376
|
+
version: "2018-03-05"
|
1377
|
+
)
|
1378
|
+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/word_lists/stopwords?version=2018-03-05")
|
1379
|
+
.with(
|
1380
|
+
headers: {
|
1381
|
+
"Accept" => "application/json",
|
1382
|
+
"Authorization" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
|
1383
|
+
"Host" => "gateway.watsonplatform.net"
|
1384
|
+
}
|
1385
|
+
).to_return(status: 200, body: { "received" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
|
1386
|
+
service_response = service.get_stopword_list_status(
|
1387
|
+
environment_id: "envid",
|
1388
|
+
collection_id: "collid"
|
1389
|
+
)
|
1390
|
+
assert_equal({ "received" => "true" }, service_response.result)
|
1391
|
+
end
|
1392
|
+
|
1372
1393
|
def test_create_stopword_list
|
1373
1394
|
service = IBMWatson::DiscoveryV1.new(
|
1374
1395
|
username: "username",
|
1375
1396
|
password: "password",
|
1376
1397
|
version: "2018-03-05"
|
1377
1398
|
)
|
1378
|
-
stub_request(:post, "https://gateway.watsonplatform.net/compare-comply/api/v1/element_classification").with do |req|
|
1379
|
-
end
|
1380
1399
|
|
1381
1400
|
stub_request(:post, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/colid/word_lists/stopwords?version=2018-03-05").with do |req|
|
1382
1401
|
assert_equal(req.headers["Accept"], "application/json")
|
@@ -41,4 +41,19 @@ class WatsonServiceTest < Minitest::Test
|
|
41
41
|
)
|
42
42
|
refute_nil(service)
|
43
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::AssistantV1.new(display_name: "Visual Recognition")
|
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(display_name: "Visual Recognition")
|
56
|
+
assert_equal(service.url, "https://gateway.watsonplatform.net/assistant/api")
|
57
|
+
refute_nil(service)
|
58
|
+
end
|
44
59
|
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: 0.
|
4
|
+
version: 0.12.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: 2019-
|
11
|
+
date: 2019-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|