@@ -130,49 +130,40 @@ 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+ url: " <iam_url>" # optional - the default value is https://iam.cloud.ibm.com/identity/token
136+ )
133137discovery = IBMWatson ::DiscoveryV1 .new (
134138 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
139+ authenticator: authenticator
137140)
138141```
139142
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-
146143#### Supplying the access token
147144
148145``` 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>"
146+ authenticator = IBMCloudSdkCore ::BearerTokenAuthenticator .new (
147+ bearer_token: " <iam_access_token>"
153148)
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>" )
149+ discovery = IBMWatson ::DiscoveryV1 .new (version: " 2017-10-16" , authenticator)
160150```
161151
162152### Username and password
163153
164154``` ruby
165155require " ibm_watson"
156+ require " ibm_cloud_sdk_core"
166157include IBMWatson
167158# 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> "
159+ authenticator = IBMCloudSdkCore :: BasicAuthenticator .new (
160+ username: " <username> " ,
161+ password: " <password> "
162+ )
163+ discovery = DiscoveryV1 . new (
164+ version: " 2017-10-16" ,
165+ authenticator: authenticator
166+ )
176167```
177168
178169## Sending requests asynchronously
@@ -185,9 +176,13 @@ Requests can be sent asynchronously. There are two asynchronous methods availabl
185176When ` await ` is used, the request is made synchronously.
186177
187178``` ruby
179+ authenticator = IBMCloudSdkCore ::IamAuthenticator .new (
180+ username: " <username>" ,
181+ password: " <password>"
182+ )
183+
188184speech_to_text = IBMWatson ::SpeechToTextV1 .new (
189- username: " username" ,
190- password: " password"
185+ authenticator: authenticator
191186)
192187audio_file = File .open (Dir .getwd + " /resources/speech.wav" )
193188future = speech_to_text.await.recognize(
@@ -200,9 +195,13 @@ output = future.value # The response is accessible at future.value
200195When ` async ` is used, the request is made asynchronously
201196
202197``` ruby
198+ authenticator = IBMCloudSdkCore ::IamAuthenticator .new (
199+ username: " <username>" ,
200+ password: " <password>"
201+ )
202+
203203speech_to_text = IBMWatson ::SpeechToTextV1 .new (
204- username: " username" ,
205- password: " password"
204+ authenticator: authenticator
206205)
207206audio_file = File .open (Dir .getwd + " /resources/speech.wav" )
208207future = speech_to_text.async.recognize(
@@ -222,8 +221,7 @@ require "ibm_watson"
222221include IBMWatson
223222
224223assistant = AssistantV1 .new (
225- username: " xxx" ,
226- password: " yyy" ,
224+ authenticator: " <authenticator>"
227225 version: " 2017-04-21"
228226)
229227
@@ -241,8 +239,7 @@ require "ibm_watson"
241239include IBMWatson
242240
243241assistant = AssistantV1 .new (
244- username: " xxx" ,
245- password: " yyy" ,
242+ authenticator: " <authenticator>"
246243 version: " 2017-04-21"
247244)
248245
@@ -270,8 +267,7 @@ require "ibm_watson/assistant_v1"
270267include IBMWatson
271268
272269assistant = AssistantV1 .new (
273- username: " {username}" ,
274- password: " {password}" ,
270+ authenticator: " <authenticator>"
275271 version: " 2018-07-10"
276272)
277273
@@ -307,8 +303,7 @@ include IBMWatson
307303
308304service = AssistantV1 .new (
309305 version: " <version>" ,
310- username: " <username>" ,
311- password: " <password>" ,
306+ authenticator: " <authenticator>"
312307)
313308
314309service.configure_http_client(disable_ssl_verification: true )
@@ -341,35 +336,26 @@ thr.join # Wait for the thread to finish before ending the program or running ot
341336
342337Note: ` recognize_with_websocket ` has been ** deprecated** in favor of ** ` recognize_using_websocket ` **
343338
344- ## IBM Cloud Pak for Data(ICP4D )
339+ ## IBM Cloud Pak for Data(CP4D )
345340If your service instance is of ICP4D, below are two ways of initializing the assistant service.
346341
347- #### 1) Supplying the ` username ` , ` password ` , ` icp4d_url ` and ` authentication_type `
342+ #### Supplying the ` username ` , ` password ` , and ` url `
348343
349344The SDK will manage the token for the user
350345
351346``` 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
364347
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
348+ authenticator = IBMCloudSdkCore ::CLoudPakForDataAuthenticator .new (
349+ username: " <username>" ,
350+ password: " <password>" ,
351+ url: " <authentication url>" ,
352+ disable_ssl: true
353+ )
354+ assistant = IBMWatson ::AssistantV1 .new (
355+ version: " <version>" ,
356+ authenticator: authenticator
357+ )
358+ assistant.configure_http_client(disable_ssl_verification: true ) # MAKE SURE SSL VERIFICATION IS DISABLED
373359```
374360
375361## Ruby version
0 commit comments