@@ -130,49 +130,41 @@ You supply either an IAM service **API key** or an **access token**:
130130
131131``` ruby
132132# In the constructor, letting the SDK manage the IAM token
133+ authenticator = IBMCloudSdkCore ::IamAuthenticator .new (
134+ apikey: " <iam_apikey>" ,
135+ version: " 2018-02-16" ,
136+ url: " <iam_url>" # optional - the default value is https://iam.cloud.ibm.com/identity/token
137+ )
133138discovery = IBMWatson ::DiscoveryV1 .new (
134139 version: " 2017-10-16" ,
135- iam_apikey: " <iam_apikey>" ,
136- iam_url: " <iam_url>" # optional - the default value is https://iam.cloud.ibm.com/identity/token
140+ authenticator: authenticator
137141)
138142```
139143
140- ``` ruby
141- # after instantiation, letting the SDK manage the IAM token
142- discovery = IBMWatson ::DiscoveryV1 .new (version: " 2017-10-16" )
143- discovery.iam_apikey(iam_apikey: " <iam_apikey>" )
144- ```
145-
146144#### Supplying the access token
147145
148146``` ruby
149- # in the constructor, assuming control of managing IAM token
150- discovery = IBMWatson ::DiscoveryV1 .new (
151- version: " 2017-10-16" ,
152- iam_access_token: " <iam_access_token>"
147+ authenticator = IBMCloudSdkCore ::BearerTokenAuthenticator .new (
148+ bearer_token: " <iam_access_token>"
153149)
154- ```
155-
156- ``` ruby
157- # after instantiation, assuming control of managing IAM token
158- discovery = IBMWatson ::DiscoveryV1 .new (version: " 2017-10-16" )
159- discovery.iam_access_token(iam_access_token: " <access_token>" )
150+ discovery = IBMWatson ::DiscoveryV1 .new (version: " 2017-10-16" , authenticator)
160151```
161152
162153### Username and password
163154
164155``` ruby
165156require " ibm_watson"
157+ require " ibm_cloud_sdk_core"
166158include IBMWatson
167159# In the constructor
168- discovery = DiscoveryV1 .new (version: " 2017-10-16 " , username: " <username> " , password: " <password> " )
169- ```
170-
171- ``` ruby
172- # After instantiation
173- discovery = DiscoveryV1 . new ( version: " 2017-10-16" )
174- discovery.username = " <username> "
175- discovery.password = " <password> "
160+ authenticator = IBMCloudSdkCore :: BasicAuthenticator .new (
161+ username: " <username> " ,
162+ password: " <password> "
163+ )
164+ discovery = DiscoveryV1 . new (
165+ version: " 2017-10-16" ,
166+ authenticator: authenticator
167+ )
176168```
177169
178170## Sending requests asynchronously
@@ -185,9 +177,13 @@ Requests can be sent asynchronously. There are two asynchronous methods availabl
185177When ` await ` is used, the request is made synchronously.
186178
187179``` ruby
180+ authenticator = IBMCloudSdkCore ::IamAuthenticator .new (
181+ username: " <username>" ,
182+ password: " <password>"
183+ )
184+
188185speech_to_text = IBMWatson ::SpeechToTextV1 .new (
189- username: " username" ,
190- password: " password"
186+ authenticator: authenticator
191187)
192188audio_file = File .open (Dir .getwd + " /resources/speech.wav" )
193189future = speech_to_text.await.recognize(
@@ -200,9 +196,13 @@ output = future.value # The response is accessible at future.value
200196When ` async ` is used, the request is made asynchronously
201197
202198``` ruby
199+ authenticator = IBMCloudSdkCore ::IamAuthenticator .new (
200+ username: " <username>" ,
201+ password: " <password>"
202+ )
203+
203204speech_to_text = IBMWatson ::SpeechToTextV1 .new (
204- username: " username" ,
205- password: " password"
205+ authenticator: authenticator
206206)
207207audio_file = File .open (Dir .getwd + " /resources/speech.wav" )
208208future = speech_to_text.async.recognize(
@@ -222,8 +222,7 @@ require "ibm_watson"
222222include IBMWatson
223223
224224assistant = AssistantV1 .new (
225- username: " xxx" ,
226- password: " yyy" ,
225+ authenticator: " <authenticator>"
227226 version: " 2017-04-21"
228227)
229228
@@ -241,8 +240,7 @@ require "ibm_watson"
241240include IBMWatson
242241
243242assistant = AssistantV1 .new (
244- username: " xxx" ,
245- password: " yyy" ,
243+ authenticator: " <authenticator>"
246244 version: " 2017-04-21"
247245)
248246
@@ -270,8 +268,7 @@ require "ibm_watson/assistant_v1"
270268include IBMWatson
271269
272270assistant = AssistantV1 .new (
273- username: " {username}" ,
274- password: " {password}" ,
271+ authenticator: " <authenticator>"
275272 version: " 2018-07-10"
276273)
277274
@@ -307,8 +304,7 @@ include IBMWatson
307304
308305service = AssistantV1 .new (
309306 version: " <version>" ,
310- username: " <username>" ,
311- password: " <password>" ,
307+ authenticator: " <authenticator>"
312308)
313309
314310service.configure_http_client(disable_ssl_verification: true )
@@ -341,35 +337,26 @@ thr.join # Wait for the thread to finish before ending the program or running ot
341337
342338Note: ` recognize_with_websocket ` has been ** deprecated** in favor of ** ` recognize_using_websocket ` **
343339
344- ## IBM Cloud Pak for Data(ICP4D )
340+ ## IBM Cloud Pak for Data(CP4D )
345341If your service instance is of ICP4D, below are two ways of initializing the assistant service.
346342
347- #### 1) Supplying the ` username ` , ` password ` , ` icp4d_url ` and ` authentication_type `
343+ #### Supplying the ` username ` , ` password ` , and ` url `
348344
349345The SDK will manage the token for the user
350346
351347``` ruby
352- assistant = IBMWatson ::AssistantV1 .new (
353- version: " <version>" ,
354- username: " <username>" ,
355- password: " <password>" ,
356- url: " <service url>" ,
357- icp4d_url: " <authentication url>" ,
358- authentication_type: " icp4d"
359- )
360- assistant.configure_http_client(disable_ssl_verification: true ) # MAKE SURE SSL VERIFICATION IS DISABLED
361- ```
362-
363- #### 2) Supplying the access token
364348
365- ``` ruby
366- assistant = IBMWatson ::AssistantV1 .new (
367- version: " <version>" ,
368- url: " <service url>" ,
369- icp4d_token: " <your managed access token>" ,
370- authentication_type: " icp4d"
371- )
372- assistant.configure_http_client(disable_ssl_verification: true ) # MAKE SURE SSL VERIFICATION IS DISABLED
349+ authenticator = IBMCloudSdkCore ::CLoudPakForDataAuthenticator .new (
350+ username: " <username>" ,
351+ password: " <password>" ,
352+ url: " <authentication url>" ,
353+ disable_ssl: true
354+ )
355+ assistant = IBMWatson ::AssistantV1 .new (
356+ version: " <version>" ,
357+ authenticator: authenticator
358+ )
359+ assistant.configure_http_client(disable_ssl_verification: true ) # MAKE SURE SSL VERIFICATION IS DISABLED
373360```
374361
375362## Ruby version
0 commit comments