Skip to content

Commit 07e1899

Browse files
maxnussbaumGERMAN ATTANASIO RUIZ
authored andcommitted
chore(examples): Add more information about authentication to examples
1 parent b67b4ee commit 07e1899

10 files changed

+74
-19
lines changed

examples/assistant_v1.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
require("watson_apis/assistant_v1")
22

3+
# If using IAM
34
assistant = AssistantV1(
4-
# username: "YOUR SERVICE USERNAME",
5-
# password: "YOUR SERVICE PASSWORD",
65
iam_api_key: "IAM API KEY",
76
version: "2018-02-16"
87
)
98

9+
# If you have username & password in your credentials use:
10+
# assistant = AssistantV1(
11+
# username: "YOUR SERVICE USERNAME",
12+
# password: "YOUR SERVICE PASSWORD",
13+
# version: "2018-02-16"
14+
# )
15+
1016
#########################
1117
# Workspaces
1218
#########################

examples/discovery_v1.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
require("watson_apis/discovery_v1")
22

3+
# If using IAM
34
discovery = WatsonAPIs::DiscoveryV1.new(
4-
# username: "username",
5-
# password: "password",
65
iam_api_key: "IAM API KEY",
76
version: "2018-03-05"
87
)
98

9+
# If you have username & password in your credentials use:
10+
# discovery = WatsonAPIs::DiscoveryV1.new(
11+
# username: "username",
12+
# password: "password",
13+
# version: "2018-03-05"
14+
# )
15+
1016
environments = discovery.list_environments.body
1117
p environments
1218

examples/language_translator_v3.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
require("watson_apis/language_translator_v3")
22

3+
# If using IAM
34
language_translator = WatsonAPIs::LanguageTranslatorV3.new(
45
version: "2018-05-31",
56
### url is optional, and defaults to the URL below. Use the correct URL for your region.
67
# url: "https://gateway.watsonplatform.net/language-translator/api",
78
iam_api_key: "your_api_key"
89
)
910

10-
## Authenticate with username/password if your service instance doesn't provide an API key
11+
# If you have username & password in your credentials use:
1112
# language_translator = WatsonAPIs::LanguageTranslatorV3.new(
1213
# version: "2018-05-31",
13-
# username: "your_username",
14-
# password: "your_password"
14+
# username: "username",
15+
# password: "password"
1516
# )
1617

1718
## Translate

examples/natural_language_classifier_v1.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
require("watson_apis/natural_language_classifier_v1")
22

3+
# If using IAM
34
natural_language_classifier = WatsonAPIs::NaturalLanguageClassifierV1.new(
4-
# username: "YOUR SERVICE USERNAME",
5-
# password: "YOUR SERVICE PASSWORD"
65
iam_api_key: "IAM API KEY"
76
)
87

8+
# If you have username & password in your credentials use:
9+
# natural_language_classifier = WatsonAPIs::NaturalLanguageClassifierV1.new(
10+
# username: "YOUR SERVICE USERNAME",
11+
# password: "YOUR SERVICE PASSWORD"
12+
# )
13+
914
classifiers = natural_language_classifier.list_classifiers.body
1015
p classifiers
1116

examples/natural_language_understanding_v1.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
require("watson_apis/natural_language_understanding_v1")
22

3+
# If using IAM
34
natural_language_understanding = WatsonAPIs::NaturalLanguageUnderstandingV1.new(
4-
# username: "YOUR SERVICE USERNAME",
5-
# password: "YOUR SERVICE PASSWORD",
65
iam_api_key: "IAM API KEY",
76
version: "2018-03-16"
87
)
98

9+
# If you have username & password in your credentials use:
10+
# natural_language_understanding = WatsonAPIs::NaturalLanguageUnderstandingV1.new(
11+
# username: "YOUR SERVICE USERNAME",
12+
# password: "YOUR SERVICE PASSWORD",
13+
# version: "2018-03-16"
14+
# )
15+
1016
response = natural_language_understanding.analyze(
1117
text: "Bruce Banner is the Hulk and Bruce Wayne is BATMAN! " \
1218
"Superman fears not Banner, but Wayne",

examples/personality_insights_v3.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33
# The example returns a JSON response whose content is the same as that in
44
# ../resources/personality-v3-expect2.txt
55

6+
# If using IAM
67
personality_insights = WatsonAPIs::PersonalityInsightsV3.new(
7-
# username: "YOUR SERVICE USERNAME",
8-
# password: "YOUR SERVICE PASSWORD",
98
iam_api_key: "IAM API KEY",
109
version: "2017-10-13"
1110
)
11+
12+
# If you have username & password in your credentials use:
13+
# personality_insights = WatsonAPIs::PersonalityInsightsV3.new(
14+
# username: "YOUR SERVICE USERNAME",
15+
# password: "YOUR SERVICE PASSWORD",
16+
# version: "2017-10-13"
17+
# )
18+
1219
profile = nil
1320
File.open(Dir.getwd + "/resources/personality-v3.json") do |profile_json|
1421
profile = personality_insights.profile(

examples/speech_to_text_v1.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
require("watson_apis/speech_to_text_v1")
22
require("watson_apis/recognize_callback")
33

4+
# If using IAM
45
speech_to_text = WatsonAPIs::SpeechToTextV1.new(
5-
# username: "YOUR SERVICE USERNAME",
6-
# password: "YOUR SERVICE PASSWORD"
76
iam_api_key: "IAM API KEY"
87
)
98

9+
# If you have username & password in your credentials use:
10+
# speech_to_text = WatsonAPIs::SpeechToTextV1.new(
11+
# username: "YOUR SERVICE USERNAME",
12+
# password: "YOUR SERVICE PASSWORD"
13+
# )
14+
1015
p speech_to_text.list_models.body
1116

1217
p speech_to_text.get_model(model_id: "en-US_BroadbandModel").body

examples/text_to_speech_v1.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
require("watson_apis/text_to_speech_v1")
22

3+
# If using IAM
34
text_to_speech = WatsonAPIs::TextToSpeechV1.new(
4-
# username: "YOUR SERVICE USERNAME",
5-
# password: "YOUR SERVICE PASSWORD"
65
iam_api_key: "IAM API KEY"
76
)
87

8+
# If you have username & password in your credentials use:
9+
# text_to_speech = WatsonAPIs::TextToSpeechV1.new(
10+
# username: "YOUR SERVICE USERNAME",
11+
# password: "YOUR SERVICE PASSWORD"
12+
# )
13+
914
p text_to_speech.list_voices.body
1015

1116
File.new("output.wav", "w+") do |audio_file|

examples/tone_analyzer_v3.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
require("watson_apis/tone_analyzer_v3")
22
require("json")
33

4+
# If using IAM
45
tone_analyzer = ToneAnalyzerV3(
5-
# username: "YOUR SERVICE USERNAME",
6-
# password: "YOUR SERVICE PASSWORD",
76
iam_api_key: "IAM API KEY",
87
version: "2017-09-21"
98
)
109

10+
# If you have username & password in your credentials use:
11+
# tone_analyzer = ToneAnalyzerV3(
12+
# username: "YOUR SERVICE USERNAME",
13+
# password: "YOUR SERVICE PASSWORD",
14+
# version: "2017-09-21"
15+
# )
16+
1117
utterances = [
1218
{
1319
"text" => "I am very happy.",

examples/visual_recognition_v3.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@
22

33
test_url = "https://www.ibm.com/ibm/ginni/images/ginni_bio_780x981_v4_03162016.jpg".freeze
44

5+
# If using IAM
56
visual_recognition = WatsonAPIs::VisualRecognitionV3.new(
67
version: "2018-03-19",
78
iam_api_key: "IAM API KEY"
89
)
910

11+
# If you have username & password in your credentials use:
12+
# visual_recognition = WatsonAPIs::VisualRecognitionV3.new(
13+
# version: "2018-03-19",
14+
# username: "YOUR SERVICE USERNAME",
15+
# password: "YOUR SERVICE PASSWORD"
16+
# )
17+
1018
# cars = File.open(Dir.getwd + "/resources/cars.zip")
1119
# trucks = File.open(Dir.getwd + "/resources/trucks.zip")
1220
# p visual_recognition.create_classifier(

0 commit comments

Comments
 (0)