Skip to content

Commit 60179ba

Browse files
authored
Merge pull request #67 from watson-developer-cloud/feat/icp4d
feat(ICP4D): add support for ICP4D
2 parents b34d355 + cd5fe3c commit 60179ba

16 files changed

+230
-106
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,37 @@ thr.join # Wait for the thread to finish before ending the program or running ot
341341

342342
Note: `recognize_with_websocket` has been **deprecated** in favor of **`recognize_using_websocket`**
343343

344+
## IBM Cloud Pak for Data(ICP4D)
345+
If your service instance is of ICP4D, below are two ways of initializing the assistant service.
346+
347+
#### 1) Supplying the `username`, `password`, `icp4d_url` and `authentication_type`
348+
349+
The SDK will manage the token for the user
350+
351+
```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
364+
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
373+
```
374+
344375
## Ruby version
345376

346377
Tested on:

ibm_watson.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ Gem::Specification.new do |spec|
3636
spec.add_runtime_dependency "eventmachine", "~> 1.2"
3737
spec.add_runtime_dependency "faye-websocket", "~> 0.10"
3838
spec.add_runtime_dependency "http", "~> 4.1.0"
39-
spec.add_runtime_dependency "ibm_cloud_sdk_core", "~> 0.2.0"
39+
spec.add_runtime_dependency "ibm_cloud_sdk_core", "~> 0.3.1"
40+
spec.add_runtime_dependency "jwt", "~> 2.2.1"
4041

4142
spec.add_development_dependency "bundler", "~> 1.16"
4243
spec.add_development_dependency "codecov", "~> 0.1"

lib/ibm_watson.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module IBMWatson
77
ApiException = IBMCloudSdkCore::ApiException
88
DetailedResponse = IBMCloudSdkCore::DetailedResponse
99
IAMTokenManager = IBMCloudSdkCore::IAMTokenManager
10+
ICP4DTokenManager = IBMCloudSdkCore::ICP4DTokenManager
1011

1112
require_relative("./ibm_watson/personality_insights_v3.rb")
1213
require_relative("./ibm_watson/tone_analyzer_v3.rb")

lib/ibm_watson/assistant_v1.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ class AssistantV1 < IBMCloudSdkCore::BaseService
6969
# 'https://iam.cloud.ibm.com/identity/token'.
7070
# @option args iam_client_id [String] An optional client id for the IAM service API.
7171
# @option args iam_client_secret [String] An optional client secret for the IAM service API.
72+
# @option args icp4d_access_token [STRING] A ICP4D(IBM Cloud Pak for Data) access token is
73+
# fully managed by the application. Responsibility falls on the application to
74+
# refresh the token, either before it expires or reactively upon receiving a 401
75+
# from the service as any requests made with an expired token will fail.
76+
# @option args icp4d_url [STRING] In order to use an SDK-managed token with ICP4D authentication, this
77+
# URL must be passed in.
78+
# @option args authentication_type [STRING] Specifies the authentication pattern to use. Values that it
79+
# takes are basic, iam or icp4d.
7280
def initialize(args = {})
7381
@__async_initialized__ = false
7482
defaults = {}
@@ -81,6 +89,9 @@ def initialize(args = {})
8189
defaults[:iam_url] = nil
8290
defaults[:iam_client_id] = nil
8391
defaults[:iam_client_secret] = nil
92+
defaults[:icp4d_access_token] = nil
93+
defaults[:icp4d_url] = nil
94+
defaults[:authetication_type] = nil
8495
args = defaults.merge(args)
8596
args[:vcap_services_name] = "conversation"
8697
super

lib/ibm_watson/assistant_v2.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ class AssistantV2 < IBMCloudSdkCore::BaseService
6969
# 'https://iam.cloud.ibm.com/identity/token'.
7070
# @option args iam_client_id [String] An optional client id for the IAM service API.
7171
# @option args iam_client_secret [String] An optional client secret for the IAM service API.
72+
# @option args icp4d_access_token [STRING] A ICP4D(IBM Cloud Pak for Data) access token is
73+
# fully managed by the application. Responsibility falls on the application to
74+
# refresh the token, either before it expires or reactively upon receiving a 401
75+
# from the service as any requests made with an expired token will fail.
76+
# @option args icp4d_url [STRING] In order to use an SDK-managed token with ICP4D authentication, this
77+
# URL must be passed in.
78+
# @option args authentication_type [STRING] Specifies the authentication pattern to use. Values that it
79+
# takes are basic, iam or icp4d.
7280
def initialize(args = {})
7381
@__async_initialized__ = false
7482
defaults = {}
@@ -81,6 +89,9 @@ def initialize(args = {})
8189
defaults[:iam_url] = nil
8290
defaults[:iam_client_id] = nil
8391
defaults[:iam_client_secret] = nil
92+
defaults[:icp4d_access_token] = nil
93+
defaults[:icp4d_url] = nil
94+
defaults[:authetication_type] = nil
8495
args = defaults.merge(args)
8596
args[:vcap_services_name] = "conversation"
8697
super

lib/ibm_watson/compare_comply_v1.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ class CompareComplyV1 < IBMCloudSdkCore::BaseService
5858
# 'https://iam.cloud.ibm.com/identity/token'.
5959
# @option args iam_client_id [String] An optional client id for the IAM service API.
6060
# @option args iam_client_secret [String] An optional client secret for the IAM service API.
61+
# @option args icp4d_access_token [STRING] A ICP4D(IBM Cloud Pak for Data) access token is
62+
# fully managed by the application. Responsibility falls on the application to
63+
# refresh the token, either before it expires or reactively upon receiving a 401
64+
# from the service as any requests made with an expired token will fail.
65+
# @option args icp4d_url [STRING] In order to use an SDK-managed token with ICP4D authentication, this
66+
# URL must be passed in.
67+
# @option args authentication_type [STRING] Specifies the authentication pattern to use. Values that it
68+
# takes are basic, iam or icp4d.
6169
def initialize(args = {})
6270
@__async_initialized__ = false
6371
defaults = {}
@@ -68,6 +76,9 @@ def initialize(args = {})
6876
defaults[:iam_url] = nil
6977
defaults[:iam_client_id] = nil
7078
defaults[:iam_client_secret] = nil
79+
defaults[:icp4d_access_token] = nil
80+
defaults[:icp4d_url] = nil
81+
defaults[:authetication_type] = nil
7182
args = defaults.merge(args)
7283
args[:vcap_services_name] = "compare-comply"
7384
super

lib/ibm_watson/discovery_v1.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ class DiscoveryV1 < IBMCloudSdkCore::BaseService
7171
# 'https://iam.cloud.ibm.com/identity/token'.
7272
# @option args iam_client_id [String] An optional client id for the IAM service API.
7373
# @option args iam_client_secret [String] An optional client secret for the IAM service API.
74+
# @option args icp4d_access_token [STRING] A ICP4D(IBM Cloud Pak for Data) access token is
75+
# fully managed by the application. Responsibility falls on the application to
76+
# refresh the token, either before it expires or reactively upon receiving a 401
77+
# from the service as any requests made with an expired token will fail.
78+
# @option args icp4d_url [STRING] In order to use an SDK-managed token with ICP4D authentication, this
79+
# URL must be passed in.
80+
# @option args authentication_type [STRING] Specifies the authentication pattern to use. Values that it
81+
# takes are basic, iam or icp4d.
7482
def initialize(args = {})
7583
@__async_initialized__ = false
7684
defaults = {}
@@ -83,6 +91,9 @@ def initialize(args = {})
8391
defaults[:iam_url] = nil
8492
defaults[:iam_client_id] = nil
8593
defaults[:iam_client_secret] = nil
94+
defaults[:icp4d_access_token] = nil
95+
defaults[:icp4d_url] = nil
96+
defaults[:authetication_type] = nil
8697
args = defaults.merge(args)
8798
args[:vcap_services_name] = "discovery"
8899
super

lib/ibm_watson/language_translator_v3.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ class LanguageTranslatorV3 < IBMCloudSdkCore::BaseService
7171
# 'https://iam.cloud.ibm.com/identity/token'.
7272
# @option args iam_client_id [String] An optional client id for the IAM service API.
7373
# @option args iam_client_secret [String] An optional client secret for the IAM service API.
74+
# @option args icp4d_access_token [STRING] A ICP4D(IBM Cloud Pak for Data) access token is
75+
# fully managed by the application. Responsibility falls on the application to
76+
# refresh the token, either before it expires or reactively upon receiving a 401
77+
# from the service as any requests made with an expired token will fail.
78+
# @option args icp4d_url [STRING] In order to use an SDK-managed token with ICP4D authentication, this
79+
# URL must be passed in.
80+
# @option args authentication_type [STRING] Specifies the authentication pattern to use. Values that it
81+
# takes are basic, iam or icp4d.
7482
def initialize(args = {})
7583
@__async_initialized__ = false
7684
defaults = {}
@@ -83,6 +91,9 @@ def initialize(args = {})
8391
defaults[:iam_url] = nil
8492
defaults[:iam_client_id] = nil
8593
defaults[:iam_client_secret] = nil
94+
defaults[:icp4d_access_token] = nil
95+
defaults[:icp4d_url] = nil
96+
defaults[:authetication_type] = nil
8697
args = defaults.merge(args)
8798
args[:vcap_services_name] = "language_translator"
8899
super

lib/ibm_watson/natural_language_classifier_v1.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ class NaturalLanguageClassifierV1 < IBMCloudSdkCore::BaseService
6060
# 'https://iam.cloud.ibm.com/identity/token'.
6161
# @option args iam_client_id [String] An optional client id for the IAM service API.
6262
# @option args iam_client_secret [String] An optional client secret for the IAM service API.
63+
# @option args icp4d_access_token [STRING] A ICP4D(IBM Cloud Pak for Data) access token is
64+
# fully managed by the application. Responsibility falls on the application to
65+
# refresh the token, either before it expires or reactively upon receiving a 401
66+
# from the service as any requests made with an expired token will fail.
67+
# @option args icp4d_url [STRING] In order to use an SDK-managed token with ICP4D authentication, this
68+
# URL must be passed in.
69+
# @option args authentication_type [STRING] Specifies the authentication pattern to use. Values that it
70+
# takes are basic, iam or icp4d.
6371
def initialize(args = {})
6472
@__async_initialized__ = false
6573
defaults = {}
@@ -71,6 +79,9 @@ def initialize(args = {})
7179
defaults[:iam_url] = nil
7280
defaults[:iam_client_id] = nil
7381
defaults[:iam_client_secret] = nil
82+
defaults[:icp4d_access_token] = nil
83+
defaults[:icp4d_url] = nil
84+
defaults[:authetication_type] = nil
7485
args = defaults.merge(args)
7586
args[:vcap_services_name] = "natural_language_classifier"
7687
super

lib/ibm_watson/natural_language_understanding_v1.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ class NaturalLanguageUnderstandingV1 < IBMCloudSdkCore::BaseService
7575
# 'https://iam.cloud.ibm.com/identity/token'.
7676
# @option args iam_client_id [String] An optional client id for the IAM service API.
7777
# @option args iam_client_secret [String] An optional client secret for the IAM service API.
78+
# @option args icp4d_access_token [STRING] A ICP4D(IBM Cloud Pak for Data) access token is
79+
# fully managed by the application. Responsibility falls on the application to
80+
# refresh the token, either before it expires or reactively upon receiving a 401
81+
# from the service as any requests made with an expired token will fail.
82+
# @option args icp4d_url [STRING] In order to use an SDK-managed token with ICP4D authentication, this
83+
# URL must be passed in.
84+
# @option args authentication_type [STRING] Specifies the authentication pattern to use. Values that it
85+
# takes are basic, iam or icp4d.
7886
def initialize(args = {})
7987
@__async_initialized__ = false
8088
defaults = {}
@@ -87,6 +95,9 @@ def initialize(args = {})
8795
defaults[:iam_url] = nil
8896
defaults[:iam_client_id] = nil
8997
defaults[:iam_client_secret] = nil
98+
defaults[:icp4d_access_token] = nil
99+
defaults[:icp4d_url] = nil
100+
defaults[:authetication_type] = nil
90101
args = defaults.merge(args)
91102
args[:vcap_services_name] = "natural-language-understanding"
92103
super

0 commit comments

Comments
 (0)