Skip to content

Commit 112b703

Browse files
committed
docs: add migration guide and update readme
1 parent bbbc537 commit 112b703

File tree

4 files changed

+205
-10
lines changed

4 files changed

+205
-10
lines changed

MIGRATION-v1.md

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
### Ruby SDK V1 Migration guide
2+
3+
#### Authentication
4+
5+
##### v0.x.x
6+
7+
Previously different parameters were passed into the service constructor for authentication.
8+
9+
```ruby
10+
def example
11+
service = IBMWatson::AssistantV1.new(
12+
iam_apikey: "{iam_apikey}",
13+
url: "{service_endpoint}",
14+
version: "{version_date}"
15+
);
16+
service.url = "{service_endpoint}";
17+
end
18+
```
19+
20+
##### v1.x.x
21+
22+
Now we use an `Authenticator` to authenticate the service. Available authentication schemes include `IamAuthenticator`, `BasicAuthenticator`, `CloudPakForDataAuthenticator` and `BearerTokenAuthenticator`
23+
24+
###### IamAuthenticator
25+
26+
```ruby
27+
def example
28+
authenticator = IBMWatson::Authenticators::IamAuthenticator.new(
29+
apikey: "{apikey}"
30+
)
31+
service = IBMWatson::AssistantV1.new(
32+
authenticator: authenticator,
33+
version: "{version_date}"
34+
);
35+
service.service_url = "{serviceUrl}";
36+
end
37+
```
38+
39+
##### BasicAuthenticator
40+
41+
```ruby
42+
def example
43+
authenticator = IBMWatson::Authenticators::BasicAuthenticator.new(
44+
username: "{username}",
45+
password: "{password}"
46+
)
47+
service = IBMWatson::AssistantV1.new(
48+
authenticator: authenticator,
49+
version: "{version_date}"
50+
);
51+
service.service_url = "{serviceUrl}";
52+
end
53+
```
54+
55+
###### BearerTokenAuthenticator
56+
57+
```ruby
58+
authenticator = IBMWatson::Authenticators::BearerTokenAuthenticator.new(
59+
bearer_token: "{bearerToken}"
60+
)
61+
service = IBMWatson::AssistantV1.new(
62+
authenticator: authenticator,
63+
version: "{version_date}"
64+
);
65+
service.service_url = "{serviceUrl}";
66+
```
67+
68+
###### CloudPakForDataAuthenticator
69+
70+
```ruby
71+
authenticator = IBMWatson::Authenticators::CloudPakForDataAuthenticator.new(
72+
url: "https://{cp4d_cluster_host}{:port}",
73+
username: "{username}",
74+
password: "{password}"
75+
)
76+
service = IBMWatson::AssistantV1.new(
77+
authenticator: authenticator,
78+
version: "{version_date}"
79+
);
80+
service.service_url = "{serviceUrl}";
81+
```
82+
83+
#### Supplying credentials
84+
85+
You can supply credentials to your service using external `ibm-credentials.env` files.
86+
87+
```ruby
88+
service = IBMWatson::AssistantV1.new(
89+
version: "{version_date}"
90+
);
91+
response = service.list_workspaces.result
92+
puts JSON.pretty_generate(response)
93+
```
94+
95+
##### v0.x.x
96+
97+
Previously we would look for these files first in the system `home` directory, followed by the current project directory.
98+
99+
##### v1.x.x
100+
Now in order to allow developers to have different configurations for each project we look first in the current project directory, followed by the home directory.
101+
102+
#### Setting the service url
103+
104+
##### v0.x.x
105+
106+
Previously we set the service url by setting url.
107+
108+
```ruby
109+
def example
110+
service = IBMWatson::AssistantV1.new(
111+
iam_apikey: "{iam_apikey}",
112+
url: "{service_endpoint}",
113+
version: "{version_date}"
114+
);
115+
service.url = "{service_endpoint}";
116+
end
117+
```
118+
119+
##### v1.x.x
120+
121+
Now we set the service url by calling the `service_url` setter.
122+
123+
```ruby
124+
def example
125+
authenticator = IBMWatson::Authenticators::IamAuthenticator.new(
126+
apikey: "{apikey}"
127+
)
128+
service = IBMWatson::AssistantV1.new(
129+
authenticator: authenticator,
130+
version: "{version_date}"
131+
);
132+
service.service_url = "{serviceUrl}";
133+
end
134+
```
135+
136+
#### Service changes
137+
138+
##### Assistant v1
139+
140+
* `include_count` is no longer a parameter of the `list_workspaces()` method
141+
* `include_count` is no longer a parameter of the `list_intents()` method
142+
* `include_count` is no longer a parameter of the `list_examples()` method
143+
* `include_count` is no longer a parameter of the `list_counterexamples()` method
144+
* `include_count` is no longer a parameter of the `list_entities()` method
145+
* `include_count` is no longer a parameter of the `list_values()` method
146+
* `include_count` is no longer a parameter of the `list_synonyms()` method
147+
* `include_count` is no longer a parameter of the `list_dialogNodes()` method
148+
* `value_type` was renamed to `type` in the `calue()` method
149+
* `new_value_type` was renamed to `newType` in the `update_value()` method
150+
* `node_type` was renamed to `type` in the `create_dialog_node()` method
151+
* `node_type` was renamed to `type` in the `create_dialog_node()` method
152+
* `new_node_type` was renamed to `new_type` in the `update_dialog_node()` method
153+
154+
##### Compare Comply v1
155+
156+
* `convert_to_html()` method does not require a `filename` parameter
157+
158+
##### Discovery v1
159+
160+
* `return_fields` was renamed to `_return` in the `query()` method
161+
* `logging_optOut` was renamed to `x_watson_logging_optOut` in the `query()` method
162+
* `spelling_suggestions` was added to the `query()` method
163+
* `collection_ids` is no longer a parameter of the `query()` method
164+
* `return_fields` was renamed to `_return` in the `QueryNotices()` method
165+
* `logging_optOut` was renamed to `x_watson_logging_optOut` in the `federated_query()` method
166+
* `collection_ids` is now required in the `federated_query()` method
167+
* `collection_ids` changed position in the `federated_query()` method
168+
* `return_fields` was renamed to `_return` in the `federated_query()` method
169+
* `return_fields` was renamed to `_return` in the `federated_query_notices()` method
170+
* `test_configuration_in_environment()` method was removed
171+
* `query_entities()` method was removed
172+
* `query_relations()` method was removed
173+
174+
##### Language Translator v3
175+
176+
* `default_models` was renamed to `_default` in the `list_models()` method
177+
178+
##### Natural Language Classifier v1
179+
180+
* `metadata` was renamed to `training_metadata` in the `create_classifier()` method
181+
182+
##### Speech to Text v1
183+
184+
* `strict` is no longer a parameter of the `train_acoustic_model()` method
185+
* `recognize_with_websocket()` method was removed
186+
187+
##### Visual Recognition v3
188+
189+
* `detect_faces()` method was removed
190+
191+
##### Visual Recognition v4
192+
193+
* New service!

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ With a credential file, you just need to put the file in the right place and the
9292

9393
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):
9494

95-
* Your system's home directory
9695
* The top-level directory of the project you're using the SDK in
96+
* Your system's home directory
9797

9898
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:
9999

@@ -130,7 +130,7 @@ 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(
133+
authenticator = IBMWatson::Authenticators::::IamAuthenticator.new(
134134
apikey: "<iam_apikey>",
135135
url: "<iam_url>" # optional - the default value is https://iam.cloud.ibm.com/identity/token
136136
)
@@ -144,7 +144,7 @@ discover.service_url = "<service-url>" # setting service url
144144
#### Supplying the access token
145145

146146
```ruby
147-
authenticator = IBMCloudSdkCore::BearerTokenAuthenticator.new(
147+
authenticator = IBMWatson::Authenticators::::BearerTokenAuthenticator.new(
148148
bearer_token: "<access_token>"
149149
)
150150
discovery = IBMWatson::DiscoveryV1.new(version: "2017-10-16", authenticator)
@@ -157,7 +157,7 @@ require "ibm_watson"
157157
require "ibm_cloud_sdk_core"
158158
include IBMWatson
159159
# In the constructor
160-
authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
160+
authenticator = IBMWatson::Authenticators::::BasicAuthenticator.new(
161161
username: "<username>",
162162
password: "<password>"
163163
)
@@ -177,7 +177,7 @@ Requests can be sent asynchronously. There are two asynchronous methods availabl
177177
When `await` is used, the request is made synchronously.
178178

179179
```ruby
180-
authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
180+
authenticator = IBMWatson::Authenticators::::BasicAuthenticator.new(
181181
username: "<username>",
182182
password: "<password>"
183183
)
@@ -196,7 +196,7 @@ output = future.value # The response is accessible at future.value
196196
When `async` is used, the request is made asynchronously
197197

198198
```ruby
199-
authenticator = IBMCloudSdkCore::BasicAuthenticator.new(
199+
authenticator = IBMWatson::Authenticators::::BasicAuthenticator.new(
200200
username: "<username>",
201201
password: "<password>"
202202
)
@@ -350,7 +350,7 @@ The SDK will manage the token for the user
350350

351351
```ruby
352352

353-
authenticator = IBMCloudSdkCore::CLoudPakForDataAuthenticator.new(
353+
authenticator = IBMWatson::Authenticators::::CLoudPakForDataAuthenticator.new(
354354
username: "<username>",
355355
password: "<password>",
356356
url: "<authentication url>",
@@ -394,4 +394,4 @@ We'd love to highlight cool open-source projects that use this SDK! If you'd lik
394394
[license]: http://www.apache.org/licenses/LICENSE-2.0
395395
[vcap_services]: https://cloud.ibm.com/docs/services/watson?topic=watson-vcapServices
396396
[ibm-cloud-onboarding]: http://cloud.ibm.com/registration?target=/developer/watson&cm_sp=WatsonPlatform-WatsonServices-_-OnPageNavLink-IBMWatson_SDKs-_-Ruby
397-
[ivar]: http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/IVar.html
397+
[ivar]: http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/IVar.html

examples/personality_insights_v3.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "ibm_watson/personality_insights_v3"
4+
require "ibm_watson/authenticators"
45
require "json"
56

67
# The example returns a JSON response whose content is the same as that in

test/unit/test_discovery_v1.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ def test_get_autocompletion
10381038
version: "2018-03-05",
10391039
authenticator: authenticator
10401040
)
1041-
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/autocompletion?version=2018-03-05")
1041+
stub_request(:get, "https://gateway.watsonplatform.net/discovery/api/v1/environments/envid/collections/collid/autocompletion?prefix=hi&version=2018-03-05")
10421042
.with(
10431043
headers: {
10441044
"Accept" => "application/json",
@@ -1048,7 +1048,8 @@ def test_get_autocompletion
10481048
).to_return(status: 200, body: { "received" => "true" }.to_json, headers: { "Content-Type" => "application/json" })
10491049
service_response = service.get_autocompletion(
10501050
environment_id: "envid",
1051-
collection_id: "collid"
1051+
collection_id: "collid",
1052+
prefix: "hi"
10521053
)
10531054
assert_equal({ "received" => "true" }, service_response.result)
10541055
end

0 commit comments

Comments
 (0)