ibm_watson 0.16.1 → 0.17.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 +34 -12
- data/lib/ibm_watson/assistant_v1.rb +745 -720
- data/lib/ibm_watson/assistant_v2.rb +23 -19
- data/lib/ibm_watson/compare_comply_v1.rb +94 -89
- data/lib/ibm_watson/discovery_v1.rb +684 -687
- data/lib/ibm_watson/language_translator_v3.rb +234 -33
- data/lib/ibm_watson/natural_language_classifier_v1.rb +33 -29
- data/lib/ibm_watson/natural_language_understanding_v1.rb +33 -29
- data/lib/ibm_watson/personality_insights_v3.rb +18 -14
- data/lib/ibm_watson/speech_to_text_v1.rb +799 -725
- data/lib/ibm_watson/text_to_speech_v1.rb +201 -196
- data/lib/ibm_watson/tone_analyzer_v3.rb +15 -11
- data/lib/ibm_watson/version.rb +1 -1
- data/lib/ibm_watson/visual_recognition_v3.rb +52 -48
- data/test/integration/test_language_translator_v3.rb +37 -1
- data/test/unit/test_language_translator_v3.rb +201 -16
- data/test/unit/test_speech_to_text_v1.rb +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39527e09ad94eb91baf66ef1539c84bb1189e3f716fe9a331d87b8d3718be34d
|
4
|
+
data.tar.gz: dc8dea01d68683c4b4274b42c7d87e79818423ba9b6cfd643e4734de22136e61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cff3d3cc8cc96b4be31731ccd030d36f2e4ca519a4952ae53d9f4195a78982e262c443d190fabbca5c515bf4cd2bf225ce4f77c7459fae923e021ddb3aaa1a5f
|
7
|
+
data.tar.gz: e2ca88a6ec674b1b853146cbb01521a61bad2cde784db37172387413ba0722e30df0e3b6690839e06351feba9d14cb4c19ee7b257fbea7ff5b6609c8aea0af6b
|
data/README.md
CHANGED
@@ -29,10 +29,12 @@ Ruby gem to quickly get started with the various [IBM Watson][wdc] services.
|
|
29
29
|
* [Ruby version](#ruby-version)
|
30
30
|
* [Contributing](#contributing)
|
31
31
|
* [License](#license)
|
32
|
+
* [Featured Projects](#featured-projects)
|
32
33
|
|
33
34
|
</details>
|
34
35
|
|
35
36
|
## Before you begin
|
37
|
+
|
36
38
|
* You need an [IBM Cloud][ibm-cloud-onboarding] account.
|
37
39
|
|
38
40
|
## Installation
|
@@ -71,6 +73,7 @@ Watson services are migrating to token-based Identity and Access Management (IAM
|
|
71
73
|
- In other instances, you authenticate by providing the **[username and password](#username-and-password)** for the service instance.
|
72
74
|
|
73
75
|
### Getting credentials
|
76
|
+
|
74
77
|
To find out which authentication to use, view the service credentials. You find the service credentials for authentication the same way for all Watson services:
|
75
78
|
|
76
79
|
1. Go to the IBM Cloud [Dashboard](https://cloud.ibm.com/) page.
|
@@ -79,17 +82,17 @@ To find out which authentication to use, view the service credentials. You find
|
|
79
82
|
|
80
83
|
On this page, you should be able to see your credentials for accessing your service instance.
|
81
84
|
|
82
|
-
|
85
|
+
### Supplying credentials
|
83
86
|
|
84
87
|
There are two ways to supply the credentials you found above to the SDK for authentication.
|
85
88
|
|
86
|
-
|
89
|
+
#### Credential file (easier!)
|
87
90
|
|
88
|
-
|
91
|
+
With a credential file, you just need to put the file in the right place and the SDK will do the work of parsing and authenticating. You can get this file by clicking the **Download** button for the credentials in the **Manage** tab of your service instance.
|
89
92
|
|
90
|
-
|
93
|
+
The file downloaded will be called `ibm-credentials.env`. This is the name the SDK will search for and **must** be preserved unless you want to configure the file path (more on that later). The SDK will look for your `ibm-credentials.env` file in the following places (in order):
|
91
94
|
|
92
|
-
|
95
|
+
- Your system's home directory
|
93
96
|
- The top-level directory of the project you're using the SDK in
|
94
97
|
|
95
98
|
As long as you set that up correctly, you don't have to worry about setting any authentication options in your code. So, for example, if you created and downloaded the credential file for your Discovery instance, you just need to do the following:
|
@@ -110,7 +113,8 @@ export IBM_CREDENTIALS_FILE="<path>"
|
|
110
113
|
|
111
114
|
where `<path>` is something like `/home/user/Downloads/<file_name>.env`.
|
112
115
|
|
113
|
-
|
116
|
+
#### Manually
|
117
|
+
|
114
118
|
If you'd prefer to set authentication values manually in your code, the SDK supports that as well. The way you'll do this depends on what type of credentials your service instance gives you.
|
115
119
|
|
116
120
|
### IAM
|
@@ -120,7 +124,7 @@ IBM Cloud is migrating to token-based Identity and Access Management (IAM) authe
|
|
120
124
|
You supply either an IAM service **API key** or an **access token**:
|
121
125
|
|
122
126
|
- Use the API key to have the SDK manage the lifecycle of the access token. The SDK requests an access token, ensures that the access token is valid, and refreshes it if necessary.
|
123
|
-
- Use the access token if you want to manage the lifecycle yourself. For details, see [Authenticating with IAM tokens](https://
|
127
|
+
- Use the access token if you want to manage the lifecycle yourself. For details, see [Authenticating with IAM tokens](https://cloud.ibm.com/docs/services/watson?topic=watson-iam).
|
124
128
|
|
125
129
|
#### Supplying the IAM API key
|
126
130
|
|
@@ -129,7 +133,7 @@ You supply either an IAM service **API key** or an **access token**:
|
|
129
133
|
discovery = IBMWatson::DiscoveryV1.new(
|
130
134
|
version: "2017-10-16",
|
131
135
|
iam_apikey: "<iam_apikey>",
|
132
|
-
iam_url: "<iam_url>" # optional - the default value is https://iam.
|
136
|
+
iam_url: "<iam_url>" # optional - the default value is https://iam.cloud.ibm.com/identity/token
|
133
137
|
)
|
134
138
|
```
|
135
139
|
|
@@ -140,6 +144,7 @@ discovery.iam_apikey(iam_apikey: "<iam_apikey>")
|
|
140
144
|
```
|
141
145
|
|
142
146
|
#### Supplying the access token
|
147
|
+
|
143
148
|
```ruby
|
144
149
|
# in the constructor, assuming control of managing IAM token
|
145
150
|
discovery = IBMWatson::DiscoveryV1.new(
|
@@ -155,6 +160,7 @@ discovery.iam_access_token(iam_access_token: "<access_token>")
|
|
155
160
|
```
|
156
161
|
|
157
162
|
### Username and password
|
163
|
+
|
158
164
|
```ruby
|
159
165
|
require "ibm_watson"
|
160
166
|
include IBMWatson
|
@@ -170,11 +176,14 @@ discovery.password = "<password>"
|
|
170
176
|
```
|
171
177
|
|
172
178
|
## Sending requests asynchronously
|
179
|
+
|
173
180
|
Requests can be sent asynchronously. There are two asynchronous methods available for the user, `async` & `await`. When used, these methods return an [Ivar][ivar] object.
|
181
|
+
|
174
182
|
* To call a method asynchronously, simply insert `.await` or `.async` into the call: `service.translate` would be `service.async.translate`
|
175
183
|
* To access the response from an [Ivar][ivar] object called `future`, simply call `future.value`
|
176
184
|
|
177
185
|
When `await` is used, the request is made synchronously.
|
186
|
+
|
178
187
|
```ruby
|
179
188
|
speech_to_text = IBMWatson::SpeechToTextV1.new(
|
180
189
|
username: "username",
|
@@ -189,6 +198,7 @@ output = future.value # The response is accessible at future.value
|
|
189
198
|
```
|
190
199
|
|
191
200
|
When `async` is used, the request is made asynchronously
|
201
|
+
|
192
202
|
```ruby
|
193
203
|
speech_to_text = IBMWatson::SpeechToTextV1.new(
|
194
204
|
username: "username",
|
@@ -205,6 +215,7 @@ output = future.value
|
|
205
215
|
```
|
206
216
|
|
207
217
|
## Sending request headers
|
218
|
+
|
208
219
|
Custom headers can be passed in any request in the form of a `Hash` as a parameter to the `headers` chainable method. For example, to send a header called `Custom-Header` to a call in Watson Assistant, pass the headers as a parameter to the `headers` chainable method:
|
209
220
|
```ruby
|
210
221
|
require "ibm_watson"
|
@@ -222,7 +233,9 @@ response = assistant.headers(
|
|
222
233
|
```
|
223
234
|
|
224
235
|
## Parsing HTTP response info
|
236
|
+
|
225
237
|
HTTP requests all return `DetailedResponse` objects that have a `result`, `status`, and `headers`
|
238
|
+
|
226
239
|
```ruby
|
227
240
|
require "ibm_watson"
|
228
241
|
include IBMWatson
|
@@ -325,6 +338,7 @@ thr = Thread.new do # Start the websocket inside of a thread
|
|
325
338
|
end
|
326
339
|
thr.join # Wait for the thread to finish before ending the program or running other code
|
327
340
|
```
|
341
|
+
|
328
342
|
Note: `recognize_with_websocket` has been **deprecated** in favor of **`recognize_using_websocket`**
|
329
343
|
|
330
344
|
## Ruby version
|
@@ -341,12 +355,20 @@ See [CONTRIBUTING.md][CONTRIBUTING].
|
|
341
355
|
|
342
356
|
This library is licensed under the [Apache 2.0 license][license].
|
343
357
|
|
358
|
+
## Featured projects
|
359
|
+
|
360
|
+
Here are some projects that have been using the SDK:
|
361
|
+
|
362
|
+
* [GuardianCity](https://github.com/TalentoBogotaFedesoft/ULIBRE-061-grupo-2)
|
363
|
+
|
364
|
+
We'd love to highlight cool open-source projects that use this SDK! If you'd like to get your project added to the list, feel free to make an issue linking us to it.
|
365
|
+
|
344
366
|
[wdc]: http://www.ibm.com/watson/developercloud/
|
345
|
-
[ibm_cloud]: https://
|
346
|
-
[watson-dashboard]: https://
|
367
|
+
[ibm_cloud]: https://cloud.ibm.com/
|
368
|
+
[watson-dashboard]: https://cloud.ibm.com/catalog?category=ai
|
347
369
|
[examples]: https://github.com/watson-developer-cloud/ruby-sdk/tree/master/examples
|
348
370
|
[CONTRIBUTING]: https://github.com/watson-developer-cloud/ruby-sdk/blob/master/CONTRIBUTING.md
|
349
371
|
[license]: http://www.apache.org/licenses/LICENSE-2.0
|
350
|
-
[vcap_services]: https://
|
351
|
-
[ibm-cloud-onboarding]: http://
|
372
|
+
[vcap_services]: https://cloud.ibm.com/docs/services/watson?topic=watson-vcapServices
|
373
|
+
[ibm-cloud-onboarding]: http://cloud.ibm.com/registration?target=/developer/watson&cm_sp=WatsonPlatform-WatsonServices-_-OnPageNavLink-IBMWatson_SDKs-_-Ruby
|
352
374
|
[ivar]: http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/IVar.html
|