ibm_watson 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39527e09ad94eb91baf66ef1539c84bb1189e3f716fe9a331d87b8d3718be34d
4
- data.tar.gz: dc8dea01d68683c4b4274b42c7d87e79818423ba9b6cfd643e4734de22136e61
3
+ metadata.gz: 868d3ceaf3c16cb68e7cdbc3054175208e98bc69d365611ef2f75190bcc277e7
4
+ data.tar.gz: ce849cfda5a4f67e84b3228fba74b81f16291a9252a9af4803a9284889b1116f
5
5
  SHA512:
6
- metadata.gz: cff3d3cc8cc96b4be31731ccd030d36f2e4ca519a4952ae53d9f4195a78982e262c443d190fabbca5c515bf4cd2bf225ce4f77c7459fae923e021ddb3aaa1a5f
7
- data.tar.gz: e2ca88a6ec674b1b853146cbb01521a61bad2cde784db37172387413ba0722e30df0e3b6690839e06351feba9d14cb4c19ee7b257fbea7ff5b6609c8aea0af6b
6
+ metadata.gz: 45b17fbfa01f07b1717a751a5df6fcc188aa80d131e98e1bd25647bdeaf5f7519bc05092d63840c71a8386bc3a318dd72e789e920a137ab59e98a93134464035
7
+ data.tar.gz: b20a075d858ba826389826fa177949686823c6f4329388f7d6a73f45118739105b9de3ebc416735b7f91fb581eb33b5a8c7f5827cdd0fd03dbbec55f93eb1bfd
data/README.md CHANGED
@@ -341,6 +341,37 @@ thr.join # Wait for the thread to finish before ending the program or running ot
341
341
 
342
342
  Note: `recognize_with_websocket` has been **deprecated** in favor of **`recognize_using_websocket`**
343
343
 
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
+
344
375
  ## Ruby version
345
376
 
346
377
  Tested on:
@@ -69,6 +69,14 @@ module IBMWatson
69
69
  # 'https://iam.cloud.ibm.com/identity/token'.
70
70
  # @option args iam_client_id [String] An optional client id for the IAM service API.
71
71
  # @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.
72
80
  def initialize(args = {})
73
81
  @__async_initialized__ = false
74
82
  defaults = {}
@@ -81,6 +89,9 @@ module IBMWatson
81
89
  defaults[:iam_url] = nil
82
90
  defaults[:iam_client_id] = nil
83
91
  defaults[:iam_client_secret] = nil
92
+ defaults[:icp4d_access_token] = nil
93
+ defaults[:icp4d_url] = nil
94
+ defaults[:authetication_type] = nil
84
95
  args = defaults.merge(args)
85
96
  args[:vcap_services_name] = "conversation"
86
97
  super
@@ -69,6 +69,14 @@ module IBMWatson
69
69
  # 'https://iam.cloud.ibm.com/identity/token'.
70
70
  # @option args iam_client_id [String] An optional client id for the IAM service API.
71
71
  # @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.
72
80
  def initialize(args = {})
73
81
  @__async_initialized__ = false
74
82
  defaults = {}
@@ -81,6 +89,9 @@ module IBMWatson
81
89
  defaults[:iam_url] = nil
82
90
  defaults[:iam_client_id] = nil
83
91
  defaults[:iam_client_secret] = nil
92
+ defaults[:icp4d_access_token] = nil
93
+ defaults[:icp4d_url] = nil
94
+ defaults[:authetication_type] = nil
84
95
  args = defaults.merge(args)
85
96
  args[:vcap_services_name] = "conversation"
86
97
  super
@@ -58,6 +58,14 @@ module IBMWatson
58
58
  # 'https://iam.cloud.ibm.com/identity/token'.
59
59
  # @option args iam_client_id [String] An optional client id for the IAM service API.
60
60
  # @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.
61
69
  def initialize(args = {})
62
70
  @__async_initialized__ = false
63
71
  defaults = {}
@@ -68,6 +76,9 @@ module IBMWatson
68
76
  defaults[:iam_url] = nil
69
77
  defaults[:iam_client_id] = nil
70
78
  defaults[:iam_client_secret] = nil
79
+ defaults[:icp4d_access_token] = nil
80
+ defaults[:icp4d_url] = nil
81
+ defaults[:authetication_type] = nil
71
82
  args = defaults.merge(args)
72
83
  args[:vcap_services_name] = "compare-comply"
73
84
  super
@@ -71,6 +71,14 @@ module IBMWatson
71
71
  # 'https://iam.cloud.ibm.com/identity/token'.
72
72
  # @option args iam_client_id [String] An optional client id for the IAM service API.
73
73
  # @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.
74
82
  def initialize(args = {})
75
83
  @__async_initialized__ = false
76
84
  defaults = {}
@@ -83,6 +91,9 @@ module IBMWatson
83
91
  defaults[:iam_url] = nil
84
92
  defaults[:iam_client_id] = nil
85
93
  defaults[:iam_client_secret] = nil
94
+ defaults[:icp4d_access_token] = nil
95
+ defaults[:icp4d_url] = nil
96
+ defaults[:authetication_type] = nil
86
97
  args = defaults.merge(args)
87
98
  args[:vcap_services_name] = "discovery"
88
99
  super
@@ -71,6 +71,14 @@ module IBMWatson
71
71
  # 'https://iam.cloud.ibm.com/identity/token'.
72
72
  # @option args iam_client_id [String] An optional client id for the IAM service API.
73
73
  # @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.
74
82
  def initialize(args = {})
75
83
  @__async_initialized__ = false
76
84
  defaults = {}
@@ -83,6 +91,9 @@ module IBMWatson
83
91
  defaults[:iam_url] = nil
84
92
  defaults[:iam_client_id] = nil
85
93
  defaults[:iam_client_secret] = nil
94
+ defaults[:icp4d_access_token] = nil
95
+ defaults[:icp4d_url] = nil
96
+ defaults[:authetication_type] = nil
86
97
  args = defaults.merge(args)
87
98
  args[:vcap_services_name] = "language_translator"
88
99
  super
@@ -60,6 +60,14 @@ module IBMWatson
60
60
  # 'https://iam.cloud.ibm.com/identity/token'.
61
61
  # @option args iam_client_id [String] An optional client id for the IAM service API.
62
62
  # @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.
63
71
  def initialize(args = {})
64
72
  @__async_initialized__ = false
65
73
  defaults = {}
@@ -71,6 +79,9 @@ module IBMWatson
71
79
  defaults[:iam_url] = nil
72
80
  defaults[:iam_client_id] = nil
73
81
  defaults[:iam_client_secret] = nil
82
+ defaults[:icp4d_access_token] = nil
83
+ defaults[:icp4d_url] = nil
84
+ defaults[:authetication_type] = nil
74
85
  args = defaults.merge(args)
75
86
  args[:vcap_services_name] = "natural_language_classifier"
76
87
  super
@@ -75,6 +75,14 @@ module IBMWatson
75
75
  # 'https://iam.cloud.ibm.com/identity/token'.
76
76
  # @option args iam_client_id [String] An optional client id for the IAM service API.
77
77
  # @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.
78
86
  def initialize(args = {})
79
87
  @__async_initialized__ = false
80
88
  defaults = {}
@@ -87,6 +95,9 @@ module IBMWatson
87
95
  defaults[:iam_url] = nil
88
96
  defaults[:iam_client_id] = nil
89
97
  defaults[:iam_client_secret] = nil
98
+ defaults[:icp4d_access_token] = nil
99
+ defaults[:icp4d_url] = nil
100
+ defaults[:authetication_type] = nil
90
101
  args = defaults.merge(args)
91
102
  args[:vcap_services_name] = "natural-language-understanding"
92
103
  super
@@ -86,6 +86,14 @@ module IBMWatson
86
86
  # 'https://iam.cloud.ibm.com/identity/token'.
87
87
  # @option args iam_client_id [String] An optional client id for the IAM service API.
88
88
  # @option args iam_client_secret [String] An optional client secret for the IAM service API.
89
+ # @option args icp4d_access_token [STRING] A ICP4D(IBM Cloud Pak for Data) access token is
90
+ # fully managed by the application. Responsibility falls on the application to
91
+ # refresh the token, either before it expires or reactively upon receiving a 401
92
+ # from the service as any requests made with an expired token will fail.
93
+ # @option args icp4d_url [STRING] In order to use an SDK-managed token with ICP4D authentication, this
94
+ # URL must be passed in.
95
+ # @option args authentication_type [STRING] Specifies the authentication pattern to use. Values that it
96
+ # takes are basic, iam or icp4d.
89
97
  def initialize(args = {})
90
98
  @__async_initialized__ = false
91
99
  defaults = {}
@@ -98,6 +106,9 @@ module IBMWatson
98
106
  defaults[:iam_url] = nil
99
107
  defaults[:iam_client_id] = nil
100
108
  defaults[:iam_client_secret] = nil
109
+ defaults[:icp4d_access_token] = nil
110
+ defaults[:icp4d_url] = nil
111
+ defaults[:authetication_type] = nil
101
112
  args = defaults.merge(args)
102
113
  args[:vcap_services_name] = "personality_insights"
103
114
  super
@@ -79,6 +79,14 @@ module IBMWatson
79
79
  # 'https://iam.cloud.ibm.com/identity/token'.
80
80
  # @option args iam_client_id [String] An optional client id for the IAM service API.
81
81
  # @option args iam_client_secret [String] An optional client secret for the IAM service API.
82
+ # @option args icp4d_access_token [STRING] A ICP4D(IBM Cloud Pak for Data) access token is
83
+ # fully managed by the application. Responsibility falls on the application to
84
+ # refresh the token, either before it expires or reactively upon receiving a 401
85
+ # from the service as any requests made with an expired token will fail.
86
+ # @option args icp4d_url [STRING] In order to use an SDK-managed token with ICP4D authentication, this
87
+ # URL must be passed in.
88
+ # @option args authentication_type [STRING] Specifies the authentication pattern to use. Values that it
89
+ # takes are basic, iam or icp4d.
82
90
  def initialize(args = {})
83
91
  @__async_initialized__ = false
84
92
  defaults = {}
@@ -90,6 +98,9 @@ module IBMWatson
90
98
  defaults[:iam_url] = nil
91
99
  defaults[:iam_client_id] = nil
92
100
  defaults[:iam_client_secret] = nil
101
+ defaults[:icp4d_access_token] = nil
102
+ defaults[:icp4d_url] = nil
103
+ defaults[:authetication_type] = nil
93
104
  args = defaults.merge(args)
94
105
  args[:vcap_services_name] = "speech_to_text"
95
106
  super
@@ -73,6 +73,14 @@ module IBMWatson
73
73
  # 'https://iam.cloud.ibm.com/identity/token'.
74
74
  # @option args iam_client_id [String] An optional client id for the IAM service API.
75
75
  # @option args iam_client_secret [String] An optional client secret for the IAM service API.
76
+ # @option args icp4d_access_token [STRING] A ICP4D(IBM Cloud Pak for Data) access token is
77
+ # fully managed by the application. Responsibility falls on the application to
78
+ # refresh the token, either before it expires or reactively upon receiving a 401
79
+ # from the service as any requests made with an expired token will fail.
80
+ # @option args icp4d_url [STRING] In order to use an SDK-managed token with ICP4D authentication, this
81
+ # URL must be passed in.
82
+ # @option args authentication_type [STRING] Specifies the authentication pattern to use. Values that it
83
+ # takes are basic, iam or icp4d.
76
84
  def initialize(args = {})
77
85
  @__async_initialized__ = false
78
86
  defaults = {}
@@ -84,6 +92,9 @@ module IBMWatson
84
92
  defaults[:iam_url] = nil
85
93
  defaults[:iam_client_id] = nil
86
94
  defaults[:iam_client_secret] = nil
95
+ defaults[:icp4d_access_token] = nil
96
+ defaults[:icp4d_url] = nil
97
+ defaults[:authetication_type] = nil
87
98
  args = defaults.merge(args)
88
99
  args[:vcap_services_name] = "text_to_speech"
89
100
  super
@@ -77,6 +77,14 @@ module IBMWatson
77
77
  # 'https://iam.cloud.ibm.com/identity/token'.
78
78
  # @option args iam_client_id [String] An optional client id for the IAM service API.
79
79
  # @option args iam_client_secret [String] An optional client secret for the IAM service API.
80
+ # @option args icp4d_access_token [STRING] A ICP4D(IBM Cloud Pak for Data) access token is
81
+ # fully managed by the application. Responsibility falls on the application to
82
+ # refresh the token, either before it expires or reactively upon receiving a 401
83
+ # from the service as any requests made with an expired token will fail.
84
+ # @option args icp4d_url [STRING] In order to use an SDK-managed token with ICP4D authentication, this
85
+ # URL must be passed in.
86
+ # @option args authentication_type [STRING] Specifies the authentication pattern to use. Values that it
87
+ # takes are basic, iam or icp4d.
80
88
  def initialize(args = {})
81
89
  @__async_initialized__ = false
82
90
  defaults = {}
@@ -89,6 +97,9 @@ module IBMWatson
89
97
  defaults[:iam_url] = nil
90
98
  defaults[:iam_client_id] = nil
91
99
  defaults[:iam_client_secret] = nil
100
+ defaults[:icp4d_access_token] = nil
101
+ defaults[:icp4d_url] = nil
102
+ defaults[:authetication_type] = nil
92
103
  args = defaults.merge(args)
93
104
  args[:vcap_services_name] = "tone_analyzer"
94
105
  super
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IBMWatson
4
- VERSION = "0.17.0"
4
+ VERSION = "0.18.0"
5
5
  end
@@ -59,6 +59,14 @@ module IBMWatson
59
59
  # 'https://iam.cloud.ibm.com/identity/token'.
60
60
  # @option args iam_client_id [String] An optional client id for the IAM service API.
61
61
  # @option args iam_client_secret [String] An optional client secret for the IAM service API.
62
+ # @option args icp4d_access_token [STRING] A ICP4D(IBM Cloud Pak for Data) access token is
63
+ # fully managed by the application. Responsibility falls on the application to
64
+ # refresh the token, either before it expires or reactively upon receiving a 401
65
+ # from the service as any requests made with an expired token will fail.
66
+ # @option args icp4d_url [STRING] In order to use an SDK-managed token with ICP4D authentication, this
67
+ # URL must be passed in.
68
+ # @option args authentication_type [STRING] Specifies the authentication pattern to use. Values that it
69
+ # takes are basic, iam or icp4d.
62
70
  def initialize(args = {})
63
71
  @__async_initialized__ = false
64
72
  defaults = {}
@@ -69,6 +77,9 @@ module IBMWatson
69
77
  defaults[:iam_url] = nil
70
78
  defaults[:iam_client_id] = nil
71
79
  defaults[:iam_client_secret] = nil
80
+ defaults[:icp4d_access_token] = nil
81
+ defaults[:icp4d_url] = nil
82
+ defaults[:authetication_type] = nil
72
83
  args = defaults.merge(args)
73
84
  args[:vcap_services_name] = "watson_vision_combined"
74
85
  super
data/lib/ibm_watson.rb CHANGED
@@ -7,6 +7,7 @@ module IBMWatson
7
7
  ApiException = IBMCloudSdkCore::ApiException
8
8
  DetailedResponse = IBMCloudSdkCore::DetailedResponse
9
9
  IAMTokenManager = IBMCloudSdkCore::IAMTokenManager
10
+ ICP4DTokenManager = IBMCloudSdkCore::ICP4DTokenManager
10
11
 
11
12
  require_relative("./ibm_watson/personality_insights_v3.rb")
12
13
  require_relative("./ibm_watson/tone_analyzer_v3.rb")
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require("json")
4
+ require("jwt")
4
5
  require_relative("./../test_helper.rb")
5
6
  require("webmock/minitest")
6
7
 
@@ -8,7 +9,32 @@ WebMock.disable_net_connect!(allow_localhost: true)
8
9
 
9
10
  # Unit tests for the Language Translator V3 Service
10
11
  class LanguageTranslatorV3Test < Minitest::Test
12
+ def token
13
+ access_token_layout = {
14
+ "username" => "dummy",
15
+ "role" => "Admin",
16
+ "permissions" => %w[administrator manage_catalog],
17
+ "sub" => "admin",
18
+ "iss" => "sss",
19
+ "aud" => "sss",
20
+ "uid" => "sss",
21
+ "iat" => 3600,
22
+ "exp" => Time.now.to_i
23
+ }
24
+
25
+ access_token = JWT.encode(access_token_layout, "secret", "HS256", "kid": "230498151c214b788dd97f22b85410a5")
26
+ token_response = {
27
+ "access_token" => access_token,
28
+ "token_type" => "Bearer",
29
+ "expires_in" => 3600,
30
+ "expiration" => 1_524_167_011,
31
+ "refresh_token" => "jy4gl91BQ"
32
+ }
33
+ token_response
34
+ end
35
+
11
36
  def test_translate_source_target
37
+ token_response = token
12
38
  stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
13
39
  .with(
14
40
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
@@ -20,13 +46,7 @@ class LanguageTranslatorV3Test < Minitest::Test
20
46
  }
21
47
  ).to_return(
22
48
  status: 200,
23
- body: {
24
- "access_token" => "oAeisG8yqPY7sFR_x66Z15",
25
- "token_type" => "Bearer",
26
- "expires_in" => 3600,
27
- "expiration" => 1_524_167_011,
28
- "refresh_token" => "jy4gl91BQ"
29
- }.to_json,
49
+ body: token_response.to_json,
30
50
  headers: {}
31
51
  )
32
52
  service = IBMWatson::LanguageTranslatorV3.new(
@@ -43,7 +63,7 @@ class LanguageTranslatorV3Test < Minitest::Test
43
63
  body: "{\"text\":\"Hola, cómo estás? €\",\"source\":\"es\",\"target\":\"en\"}",
44
64
  headers: {
45
65
  "Accept" => "application/json",
46
- "Authorization" => "Bearer oAeisG8yqPY7sFR_x66Z15",
66
+ "Authorization" => "Bearer " + token_response["access_token"],
47
67
  "Content-Type" => "application/json",
48
68
  "Host" => "gateway.watsonplatform.net"
49
69
  }
@@ -57,6 +77,7 @@ class LanguageTranslatorV3Test < Minitest::Test
57
77
  end
58
78
 
59
79
  def test_translate_model_id
80
+ token_response = token
60
81
  stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
61
82
  .with(
62
83
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
@@ -68,13 +89,7 @@ class LanguageTranslatorV3Test < Minitest::Test
68
89
  }
69
90
  ).to_return(
70
91
  status: 200,
71
- body: {
72
- "access_token" => "oAeisG8yqPY7sFR_x66Z15",
73
- "token_type" => "Bearer",
74
- "expires_in" => 3600,
75
- "expiration" => 1_524_167_011,
76
- "refresh_token" => "jy4gl91BQ"
77
- }.to_json,
92
+ body: token_response.to_json,
78
93
  headers: {}
79
94
  )
80
95
  service = IBMWatson::LanguageTranslatorV3.new(
@@ -95,7 +110,7 @@ class LanguageTranslatorV3Test < Minitest::Test
95
110
  body: "{\"text\":\"Messi is the best ever\",\"model_id\":\"en-es-conversational\"}",
96
111
  headers: {
97
112
  "Accept" => "application/json",
98
- "Authorization" => "Bearer oAeisG8yqPY7sFR_x66Z15",
113
+ "Authorization" => "Bearer " + token_response["access_token"],
99
114
  "Content-Type" => "application/json",
100
115
  "Host" => "gateway.watsonplatform.net"
101
116
  }
@@ -108,6 +123,7 @@ class LanguageTranslatorV3Test < Minitest::Test
108
123
  end
109
124
 
110
125
  def test_identify
126
+ token_response = token
111
127
  stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
112
128
  .with(
113
129
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
@@ -119,13 +135,7 @@ class LanguageTranslatorV3Test < Minitest::Test
119
135
  }
120
136
  ).to_return(
121
137
  status: 200,
122
- body: {
123
- "access_token" => "oAeisG8yqPY7sFR_x66Z15",
124
- "token_type" => "Bearer",
125
- "expires_in" => 3600,
126
- "expiration" => 1_524_167_011,
127
- "refresh_token" => "jy4gl91BQ"
128
- }.to_json,
138
+ body: token_response.to_json,
129
139
  headers: {}
130
140
  )
131
141
  service = IBMWatson::LanguageTranslatorV3.new(
@@ -153,7 +163,7 @@ class LanguageTranslatorV3Test < Minitest::Test
153
163
  body: "祝你有美好的一天",
154
164
  headers: {
155
165
  "Accept" => "application/json",
156
- "Authorization" => "Bearer oAeisG8yqPY7sFR_x66Z15",
166
+ "Authorization" => "Bearer " + token_response["access_token"],
157
167
  "Content-Type" => "text/plain",
158
168
  "Host" => "gateway.watsonplatform.net"
159
169
  }
@@ -165,6 +175,7 @@ class LanguageTranslatorV3Test < Minitest::Test
165
175
  end
166
176
 
167
177
  def test_list_identifiable_languages
178
+ token_response = token
168
179
  stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
169
180
  .with(
170
181
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
@@ -176,13 +187,7 @@ class LanguageTranslatorV3Test < Minitest::Test
176
187
  }
177
188
  ).to_return(
178
189
  status: 200,
179
- body: {
180
- "access_token" => "oAeisG8yqPY7sFR_x66Z15",
181
- "token_type" => "Bearer",
182
- "expires_in" => 3600,
183
- "expiration" => 1_524_167_011,
184
- "refresh_token" => "jy4gl91BQ"
185
- }.to_json,
190
+ body: token_response.to_json,
186
191
  headers: {}
187
192
  )
188
193
  service = IBMWatson::LanguageTranslatorV3.new(
@@ -221,8 +226,7 @@ class LanguageTranslatorV3Test < Minitest::Test
221
226
  .with(
222
227
  headers: {
223
228
  "Accept" => "application/json",
224
- "Authorization" => "Bearer oAeisG8yqPY7sFR_x66Z15",
225
- "Host" => "gateway.watsonplatform.net"
229
+ "Authorization" => "Bearer " + token_response["access_token"]
226
230
  }
227
231
  ).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
228
232
  service_response = service.list_identifiable_languages
@@ -230,6 +234,7 @@ class LanguageTranslatorV3Test < Minitest::Test
230
234
  end
231
235
 
232
236
  def test_create_model
237
+ token_response = token
233
238
  stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
234
239
  .with(
235
240
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
@@ -241,13 +246,7 @@ class LanguageTranslatorV3Test < Minitest::Test
241
246
  }
242
247
  ).to_return(
243
248
  status: 200,
244
- body: {
245
- "access_token" => "oAeisG8yqPY7sFR_x66Z15",
246
- "token_type" => "Bearer",
247
- "expires_in" => 3600,
248
- "expiration" => 1_524_167_011,
249
- "refresh_token" => "jy4gl91BQ"
250
- }.to_json,
249
+ body: token_response.to_json,
251
250
  headers: {}
252
251
  )
253
252
  service = IBMWatson::LanguageTranslatorV3.new(
@@ -270,7 +269,7 @@ class LanguageTranslatorV3Test < Minitest::Test
270
269
  .with(
271
270
  headers: {
272
271
  "Accept" => "application/json",
273
- "Authorization" => "Bearer oAeisG8yqPY7sFR_x66Z15",
272
+ "Authorization" => "Bearer " + token_response["access_token"],
274
273
  "Host" => "gateway.watsonplatform.net"
275
274
  }
276
275
  ).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
@@ -300,6 +299,7 @@ class LanguageTranslatorV3Test < Minitest::Test
300
299
  end
301
300
 
302
301
  def test_delete_model
302
+ token_response = token
303
303
  stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
304
304
  .with(
305
305
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
@@ -311,13 +311,7 @@ class LanguageTranslatorV3Test < Minitest::Test
311
311
  }
312
312
  ).to_return(
313
313
  status: 200,
314
- body: {
315
- "access_token" => "oAeisG8yqPY7sFR_x66Z15",
316
- "token_type" => "Bearer",
317
- "expires_in" => 3600,
318
- "expiration" => 1_524_167_011,
319
- "refresh_token" => "jy4gl91BQ"
320
- }.to_json,
314
+ body: token_response.to_json,
321
315
  headers: {}
322
316
  )
323
317
  service = IBMWatson::LanguageTranslatorV3.new(
@@ -331,7 +325,7 @@ class LanguageTranslatorV3Test < Minitest::Test
331
325
  .with(
332
326
  headers: {
333
327
  "Accept" => "application/json",
334
- "Authorization" => "Bearer oAeisG8yqPY7sFR_x66Z15",
328
+ "Authorization" => "Bearer " + token_response["access_token"],
335
329
  "Host" => "gateway.watsonplatform.net"
336
330
  }
337
331
  ).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
@@ -342,6 +336,7 @@ class LanguageTranslatorV3Test < Minitest::Test
342
336
  end
343
337
 
344
338
  def test_get_model
339
+ token_response = token
345
340
  stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
346
341
  .with(
347
342
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
@@ -353,13 +348,7 @@ class LanguageTranslatorV3Test < Minitest::Test
353
348
  }
354
349
  ).to_return(
355
350
  status: 200,
356
- body: {
357
- "access_token" => "oAeisG8yqPY7sFR_x66Z15",
358
- "token_type" => "Bearer",
359
- "expires_in" => 3600,
360
- "expiration" => 1_524_167_011,
361
- "refresh_token" => "jy4gl91BQ"
362
- }.to_json,
351
+ body: token_response.to_json,
363
352
  headers: {}
364
353
  )
365
354
  service = IBMWatson::LanguageTranslatorV3.new(
@@ -382,7 +371,7 @@ class LanguageTranslatorV3Test < Minitest::Test
382
371
  .with(
383
372
  headers: {
384
373
  "Accept" => "application/json",
385
- "Authorization" => "Bearer oAeisG8yqPY7sFR_x66Z15",
374
+ "Authorization" => "Bearer " + token_response["access_token"],
386
375
  "Host" => "gateway.watsonplatform.net"
387
376
  }
388
377
  ).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
@@ -393,6 +382,7 @@ class LanguageTranslatorV3Test < Minitest::Test
393
382
  end
394
383
 
395
384
  def test_list_models
385
+ token_response = token
396
386
  stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
397
387
  .with(
398
388
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
@@ -404,13 +394,7 @@ class LanguageTranslatorV3Test < Minitest::Test
404
394
  }
405
395
  ).to_return(
406
396
  status: 200,
407
- body: {
408
- "access_token" => "oAeisG8yqPY7sFR_x66Z15",
409
- "token_type" => "Bearer",
410
- "expires_in" => 3600,
411
- "expiration" => 1_524_167_011,
412
- "refresh_token" => "jy4gl91BQ"
413
- }.to_json,
397
+ body: token.to_json,
414
398
  headers: {}
415
399
  )
416
400
  service = IBMWatson::LanguageTranslatorV3.new(
@@ -449,7 +433,7 @@ class LanguageTranslatorV3Test < Minitest::Test
449
433
  .with(
450
434
  headers: {
451
435
  "Accept" => "application/json",
452
- "Authorization" => "Bearer oAeisG8yqPY7sFR_x66Z15",
436
+ "Authorization" => "Bearer " + token_response["access_token"],
453
437
  "Host" => "gateway.watsonplatform.net"
454
438
  }
455
439
  ).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
@@ -457,7 +441,8 @@ class LanguageTranslatorV3Test < Minitest::Test
457
441
  assert_equal(expected, service_response.result)
458
442
  end
459
443
 
460
- def test_lis_documents
444
+ def test_list_documents
445
+ token_response = token
461
446
  stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
462
447
  .with(
463
448
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
@@ -469,13 +454,7 @@ class LanguageTranslatorV3Test < Minitest::Test
469
454
  }
470
455
  ).to_return(
471
456
  status: 200,
472
- body: {
473
- "access_token" => "oAeisG8yqPY7sFR_x66Z15",
474
- "token_type" => "Bearer",
475
- "expires_in" => 3600,
476
- "expiration" => 1_524_167_011,
477
- "refresh_token" => "jy4gl91BQ"
478
- }.to_json,
457
+ body: token_response.to_json,
479
458
  headers: {}
480
459
  )
481
460
  service = IBMWatson::LanguageTranslatorV3.new(
@@ -487,7 +466,7 @@ class LanguageTranslatorV3Test < Minitest::Test
487
466
  .with(
488
467
  headers: {
489
468
  "Accept" => "application/json",
490
- "Authorization" => "Bearer oAeisG8yqPY7sFR_x66Z15",
469
+ "Authorization" => "Bearer " + token_response["access_token"],
491
470
  "Host" => "gateway.watsonplatform.net"
492
471
  }
493
472
  ).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
@@ -496,6 +475,7 @@ class LanguageTranslatorV3Test < Minitest::Test
496
475
  end
497
476
 
498
477
  def test_translate_document
478
+ token_response = token
499
479
  stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
500
480
  .with(
501
481
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
@@ -507,13 +487,7 @@ class LanguageTranslatorV3Test < Minitest::Test
507
487
  }
508
488
  ).to_return(
509
489
  status: 200,
510
- body: {
511
- "access_token" => "oAeisG8yqPY7sFR_x66Z15",
512
- "token_type" => "Bearer",
513
- "expires_in" => 3600,
514
- "expiration" => 1_524_167_011,
515
- "refresh_token" => "jy4gl91BQ"
516
- }.to_json,
490
+ body: token_response.to_json,
517
491
  headers: {}
518
492
  )
519
493
  service = IBMWatson::LanguageTranslatorV3.new(
@@ -530,6 +504,7 @@ class LanguageTranslatorV3Test < Minitest::Test
530
504
  end
531
505
 
532
506
  def test_get_document_status
507
+ token_response = token
533
508
  stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
534
509
  .with(
535
510
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
@@ -541,13 +516,7 @@ class LanguageTranslatorV3Test < Minitest::Test
541
516
  }
542
517
  ).to_return(
543
518
  status: 200,
544
- body: {
545
- "access_token" => "oAeisG8yqPY7sFR_x66Z15",
546
- "token_type" => "Bearer",
547
- "expires_in" => 3600,
548
- "expiration" => 1_524_167_011,
549
- "refresh_token" => "jy4gl91BQ"
550
- }.to_json,
519
+ body: token_response.to_json,
551
520
  headers: {}
552
521
  )
553
522
  service = IBMWatson::LanguageTranslatorV3.new(
@@ -559,7 +528,7 @@ class LanguageTranslatorV3Test < Minitest::Test
559
528
  .with(
560
529
  headers: {
561
530
  "Accept" => "application/json",
562
- "Authorization" => "Bearer oAeisG8yqPY7sFR_x66Z15",
531
+ "Authorization" => "Bearer " + token_response["access_token"],
563
532
  "Host" => "gateway.watsonplatform.net"
564
533
  }
565
534
  ).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
@@ -568,6 +537,7 @@ class LanguageTranslatorV3Test < Minitest::Test
568
537
  end
569
538
 
570
539
  def test_get_translated_document
540
+ token_response = token
571
541
  stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
572
542
  .with(
573
543
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
@@ -579,13 +549,7 @@ class LanguageTranslatorV3Test < Minitest::Test
579
549
  }
580
550
  ).to_return(
581
551
  status: 200,
582
- body: {
583
- "access_token" => "oAeisG8yqPY7sFR_x66Z15",
584
- "token_type" => "Bearer",
585
- "expires_in" => 3600,
586
- "expiration" => 1_524_167_011,
587
- "refresh_token" => "jy4gl91BQ"
588
- }.to_json,
552
+ body: token_response.to_json,
589
553
  headers: {}
590
554
  )
591
555
  service = IBMWatson::LanguageTranslatorV3.new(
@@ -597,7 +561,7 @@ class LanguageTranslatorV3Test < Minitest::Test
597
561
  .with(
598
562
  headers: {
599
563
  "Accept" => "application/json",
600
- "Authorization" => "Bearer oAeisG8yqPY7sFR_x66Z15",
564
+ "Authorization" => "Bearer " + token_response["access_token"],
601
565
  "Host" => "gateway.watsonplatform.net"
602
566
  }
603
567
  ).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
@@ -606,6 +570,7 @@ class LanguageTranslatorV3Test < Minitest::Test
606
570
  end
607
571
 
608
572
  def test_delete_document
573
+ token_response = token
609
574
  stub_request(:post, "https://iam.cloud.ibm.com/identity/token")
610
575
  .with(
611
576
  body: { "apikey" => "iam_apikey", "grant_type" => "urn:ibm:params:oauth:grant-type:apikey", "response_type" => "cloud_iam" },
@@ -617,13 +582,7 @@ class LanguageTranslatorV3Test < Minitest::Test
617
582
  }
618
583
  ).to_return(
619
584
  status: 200,
620
- body: {
621
- "access_token" => "oAeisG8yqPY7sFR_x66Z15",
622
- "token_type" => "Bearer",
623
- "expires_in" => 3600,
624
- "expiration" => 1_524_167_011,
625
- "refresh_token" => "jy4gl91BQ"
626
- }.to_json,
585
+ body: token_response.to_json,
627
586
  headers: {}
628
587
  )
629
588
  service = IBMWatson::LanguageTranslatorV3.new(
@@ -634,7 +593,7 @@ class LanguageTranslatorV3Test < Minitest::Test
634
593
  stub_request(:delete, "https://gateway.watsonplatform.net/language-translator/api/v3/documents/id?version=2018-05-01")
635
594
  .with(
636
595
  headers: {
637
- "Authorization" => "Bearer oAeisG8yqPY7sFR_x66Z15",
596
+ "Authorization" => "Bearer " + token_response["access_token"],
638
597
  "Host" => "gateway.watsonplatform.net"
639
598
  }
640
599
  ).to_return(status: 200, body: expected.to_json, headers: { "Content-Type" => "application/json" })
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibm_watson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Nussbaum
@@ -72,14 +72,28 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.2.0
75
+ version: 0.3.1
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.2.0
82
+ version: 0.3.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: jwt
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.2.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.2.1
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: bundler
85
99
  requirement: !ruby/object:Gem::Requirement