ibm_watson 0.2.0 → 0.3.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 +39 -3
- data/lib/ibm_watson/assistant_v1.rb +15 -0
- data/lib/ibm_watson/discovery_v1.rb +15 -0
- data/lib/ibm_watson/language_translator_v3.rb +15 -0
- data/lib/ibm_watson/natural_language_classifier_v1.rb +15 -0
- data/lib/ibm_watson/natural_language_understanding_v1.rb +15 -0
- data/lib/ibm_watson/personality_insights_v3.rb +15 -0
- data/lib/ibm_watson/speech_to_text_v1.rb +15 -0
- data/lib/ibm_watson/text_to_speech_v1.rb +15 -0
- data/lib/ibm_watson/tone_analyzer_v3.rb +15 -0
- data/lib/ibm_watson/version.rb +1 -1
- data/lib/ibm_watson/visual_recognition_v3.rb +15 -0
- data/lib/ibm_watson/watson_service.rb +48 -7
- data/test/unit/test_configure_http_client.rb +162 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e5497c0b4d5432eeebd77445b2563795c103cd37eb7110d6405c28658d10ffa
|
4
|
+
data.tar.gz: 0ff12a91d90c19d074672665a2539ed5a9a4b2bafd0922e613d0e4121441be67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 734634cbd63a3a5b3dda1e4fa6b77ba8285f7c493d4b8c107abd2119e4564b42e96eff6af4387da504c83ae2697a8a13fef8ade200e80d6b7d6142ce2fd334ef
|
7
|
+
data.tar.gz: 42d4aca1005a5a614411d10d0c8ca50d3227558f3cb9d9490fdb8386737850c0e490dbab6b8bf02a3581f4c927f657dba08575bfb99fdd6fdf91ff3c2a431a19
|
data/README.md
CHANGED
@@ -22,6 +22,7 @@ Ruby gem to quickly get started with the various [IBM Watson][wdc] services.
|
|
22
22
|
* [Sending requests asynchronously](#sending-requests-asynchronously)
|
23
23
|
* [Sending request headers](#sending-request-headers)
|
24
24
|
* [Parsing HTTP response info](#parsing-http-response-info)
|
25
|
+
* [Configuring the HTTP client](#configuring-the-http-client)
|
25
26
|
* [Using Websockets](#using-websockets)
|
26
27
|
* [Ruby version](#ruby-version)
|
27
28
|
* [Contributing](#contributing)
|
@@ -71,9 +72,9 @@ Watson services are migrating to token-based Identity and Access Management (IAM
|
|
71
72
|
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:
|
72
73
|
|
73
74
|
1. Go to the IBM Cloud **[Dashboard][watson-dashboard]** page.
|
74
|
-
|
75
|
-
|
76
|
-
|
75
|
+
2. Either click an existing Watson service instance or click **Create**.
|
76
|
+
3. Click **Show** to view your service credentials.
|
77
|
+
4. Copy the `url` and either `apikey` or `username` and `password`.
|
77
78
|
|
78
79
|
### IAM
|
79
80
|
|
@@ -211,6 +212,41 @@ Headers: "<http response headers>"
|
|
211
212
|
Result: "<response returned by service>"
|
212
213
|
```
|
213
214
|
|
215
|
+
## Configuring the HTTP client
|
216
|
+
To set client configs like timeout or proxy use the `configure_http_client` function and pass in the configurations.
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
require "ibm_watson/assistant_v1"
|
220
|
+
include IBMWatson
|
221
|
+
|
222
|
+
assistant = AssistantV1.new(
|
223
|
+
username: "{username}",
|
224
|
+
password: "{password}",
|
225
|
+
version: "2018-07-10"
|
226
|
+
)
|
227
|
+
|
228
|
+
assistant.configure_http_client(
|
229
|
+
timeout: {
|
230
|
+
# Accepts either :per_operation or :global
|
231
|
+
per_operation: { # The individual timeouts for each operation
|
232
|
+
read: 5,
|
233
|
+
write: 7,
|
234
|
+
connect: 10
|
235
|
+
}
|
236
|
+
# global: 30 # The total timeout time
|
237
|
+
},
|
238
|
+
proxy: {
|
239
|
+
address: "bogus_address.com",
|
240
|
+
port: 9999,
|
241
|
+
username: "username",
|
242
|
+
password: "password",
|
243
|
+
headers: {
|
244
|
+
bogus_header: true
|
245
|
+
}
|
246
|
+
}
|
247
|
+
)
|
248
|
+
```
|
249
|
+
|
214
250
|
## Using Websockets
|
215
251
|
|
216
252
|
The Speech-to-Text service supports websockets with the `recognize-with-websockets` method. The method accepts a custom callback class. The `eventmachine` loop that the websocket uses blocks the main thread by default. Here is an example of using the websockets method:
|
@@ -142,6 +142,21 @@ module IBMWatson
|
|
142
142
|
def url
|
143
143
|
@watson_service.url
|
144
144
|
end
|
145
|
+
|
146
|
+
# @!method configure_http_client(proxy: {}, timeout: {})
|
147
|
+
# Sets the http client config, currently works with timeout and proxies
|
148
|
+
# @param proxy [Hash] The hash of proxy configurations
|
149
|
+
# @option proxy address [String] The address of the proxy
|
150
|
+
# @option proxy port [Integer] The port of the proxy
|
151
|
+
# @option proxy username [String] The username of the proxy, if authentication is needed
|
152
|
+
# @option proxy password [String] The password of the proxy, if authentication is needed
|
153
|
+
# @option proxy headers [Hash] The headers to be used with the proxy
|
154
|
+
# @param timeout [Hash] The hash for configuring timeouts. `per_operation` has priority over `global`
|
155
|
+
# @option timeout per_operation [Hash] Timeouts per operation. Requires `read`, `write`, `connect`
|
156
|
+
# @option timeout global [Integer] Upper bound on total request time
|
157
|
+
def configure_http_client(proxy: {}, timeout: {})
|
158
|
+
@watson_service.configure_http_client(proxy: proxy, timeout: timeout)
|
159
|
+
end
|
145
160
|
# :nocov:
|
146
161
|
#########################
|
147
162
|
# Message
|
@@ -144,6 +144,21 @@ module IBMWatson
|
|
144
144
|
def url
|
145
145
|
@watson_service.url
|
146
146
|
end
|
147
|
+
|
148
|
+
# @!method configure_http_client(proxy: {}, timeout: {})
|
149
|
+
# Sets the http client config, currently works with timeout and proxies
|
150
|
+
# @param proxy [Hash] The hash of proxy configurations
|
151
|
+
# @option proxy address [String] The address of the proxy
|
152
|
+
# @option proxy port [Integer] The port of the proxy
|
153
|
+
# @option proxy username [String] The username of the proxy, if authentication is needed
|
154
|
+
# @option proxy password [String] The password of the proxy, if authentication is needed
|
155
|
+
# @option proxy headers [Hash] The headers to be used with the proxy
|
156
|
+
# @param timeout [Hash] The hash for configuring timeouts. `per_operation` has priority over `global`
|
157
|
+
# @option timeout per_operation [Hash] Timeouts per operation. Requires `read`, `write`, `connect`
|
158
|
+
# @option timeout global [Integer] Upper bound on total request time
|
159
|
+
def configure_http_client(proxy: {}, timeout: {})
|
160
|
+
@watson_service.configure_http_client(proxy: proxy, timeout: timeout)
|
161
|
+
end
|
147
162
|
# :nocov:
|
148
163
|
#########################
|
149
164
|
# Environments
|
@@ -144,6 +144,21 @@ module IBMWatson
|
|
144
144
|
def url
|
145
145
|
@watson_service.url
|
146
146
|
end
|
147
|
+
|
148
|
+
# @!method configure_http_client(proxy: {}, timeout: {})
|
149
|
+
# Sets the http client config, currently works with timeout and proxies
|
150
|
+
# @param proxy [Hash] The hash of proxy configurations
|
151
|
+
# @option proxy address [String] The address of the proxy
|
152
|
+
# @option proxy port [Integer] The port of the proxy
|
153
|
+
# @option proxy username [String] The username of the proxy, if authentication is needed
|
154
|
+
# @option proxy password [String] The password of the proxy, if authentication is needed
|
155
|
+
# @option proxy headers [Hash] The headers to be used with the proxy
|
156
|
+
# @param timeout [Hash] The hash for configuring timeouts. `per_operation` has priority over `global`
|
157
|
+
# @option timeout per_operation [Hash] Timeouts per operation. Requires `read`, `write`, `connect`
|
158
|
+
# @option timeout global [Integer] Upper bound on total request time
|
159
|
+
def configure_http_client(proxy: {}, timeout: {})
|
160
|
+
@watson_service.configure_http_client(proxy: proxy, timeout: timeout)
|
161
|
+
end
|
147
162
|
# :nocov:
|
148
163
|
#########################
|
149
164
|
# Translation
|
@@ -131,6 +131,21 @@ module IBMWatson
|
|
131
131
|
def url
|
132
132
|
@watson_service.url
|
133
133
|
end
|
134
|
+
|
135
|
+
# @!method configure_http_client(proxy: {}, timeout: {})
|
136
|
+
# Sets the http client config, currently works with timeout and proxies
|
137
|
+
# @param proxy [Hash] The hash of proxy configurations
|
138
|
+
# @option proxy address [String] The address of the proxy
|
139
|
+
# @option proxy port [Integer] The port of the proxy
|
140
|
+
# @option proxy username [String] The username of the proxy, if authentication is needed
|
141
|
+
# @option proxy password [String] The password of the proxy, if authentication is needed
|
142
|
+
# @option proxy headers [Hash] The headers to be used with the proxy
|
143
|
+
# @param timeout [Hash] The hash for configuring timeouts. `per_operation` has priority over `global`
|
144
|
+
# @option timeout per_operation [Hash] Timeouts per operation. Requires `read`, `write`, `connect`
|
145
|
+
# @option timeout global [Integer] Upper bound on total request time
|
146
|
+
def configure_http_client(proxy: {}, timeout: {})
|
147
|
+
@watson_service.configure_http_client(proxy: proxy, timeout: timeout)
|
148
|
+
end
|
134
149
|
# :nocov:
|
135
150
|
#########################
|
136
151
|
# Classify text
|
@@ -148,6 +148,21 @@ module IBMWatson
|
|
148
148
|
def url
|
149
149
|
@watson_service.url
|
150
150
|
end
|
151
|
+
|
152
|
+
# @!method configure_http_client(proxy: {}, timeout: {})
|
153
|
+
# Sets the http client config, currently works with timeout and proxies
|
154
|
+
# @param proxy [Hash] The hash of proxy configurations
|
155
|
+
# @option proxy address [String] The address of the proxy
|
156
|
+
# @option proxy port [Integer] The port of the proxy
|
157
|
+
# @option proxy username [String] The username of the proxy, if authentication is needed
|
158
|
+
# @option proxy password [String] The password of the proxy, if authentication is needed
|
159
|
+
# @option proxy headers [Hash] The headers to be used with the proxy
|
160
|
+
# @param timeout [Hash] The hash for configuring timeouts. `per_operation` has priority over `global`
|
161
|
+
# @option timeout per_operation [Hash] Timeouts per operation. Requires `read`, `write`, `connect`
|
162
|
+
# @option timeout global [Integer] Upper bound on total request time
|
163
|
+
def configure_http_client(proxy: {}, timeout: {})
|
164
|
+
@watson_service.configure_http_client(proxy: proxy, timeout: timeout)
|
165
|
+
end
|
151
166
|
# :nocov:
|
152
167
|
#########################
|
153
168
|
# Analyze
|
@@ -159,6 +159,21 @@ module IBMWatson
|
|
159
159
|
def url
|
160
160
|
@watson_service.url
|
161
161
|
end
|
162
|
+
|
163
|
+
# @!method configure_http_client(proxy: {}, timeout: {})
|
164
|
+
# Sets the http client config, currently works with timeout and proxies
|
165
|
+
# @param proxy [Hash] The hash of proxy configurations
|
166
|
+
# @option proxy address [String] The address of the proxy
|
167
|
+
# @option proxy port [Integer] The port of the proxy
|
168
|
+
# @option proxy username [String] The username of the proxy, if authentication is needed
|
169
|
+
# @option proxy password [String] The password of the proxy, if authentication is needed
|
170
|
+
# @option proxy headers [Hash] The headers to be used with the proxy
|
171
|
+
# @param timeout [Hash] The hash for configuring timeouts. `per_operation` has priority over `global`
|
172
|
+
# @option timeout per_operation [Hash] Timeouts per operation. Requires `read`, `write`, `connect`
|
173
|
+
# @option timeout global [Integer] Upper bound on total request time
|
174
|
+
def configure_http_client(proxy: {}, timeout: {})
|
175
|
+
@watson_service.configure_http_client(proxy: proxy, timeout: timeout)
|
176
|
+
end
|
162
177
|
# :nocov:
|
163
178
|
#########################
|
164
179
|
# Methods
|
@@ -179,6 +179,21 @@ module IBMWatson
|
|
179
179
|
def url
|
180
180
|
@watson_service.url
|
181
181
|
end
|
182
|
+
|
183
|
+
# @!method configure_http_client(proxy: {}, timeout: {})
|
184
|
+
# Sets the http client config, currently works with timeout and proxies
|
185
|
+
# @param proxy [Hash] The hash of proxy configurations
|
186
|
+
# @option proxy address [String] The address of the proxy
|
187
|
+
# @option proxy port [Integer] The port of the proxy
|
188
|
+
# @option proxy username [String] The username of the proxy, if authentication is needed
|
189
|
+
# @option proxy password [String] The password of the proxy, if authentication is needed
|
190
|
+
# @option proxy headers [Hash] The headers to be used with the proxy
|
191
|
+
# @param timeout [Hash] The hash for configuring timeouts. `per_operation` has priority over `global`
|
192
|
+
# @option timeout per_operation [Hash] Timeouts per operation. Requires `read`, `write`, `connect`
|
193
|
+
# @option timeout global [Integer] Upper bound on total request time
|
194
|
+
def configure_http_client(proxy: {}, timeout: {})
|
195
|
+
@watson_service.configure_http_client(proxy: proxy, timeout: timeout)
|
196
|
+
end
|
182
197
|
# :nocov:
|
183
198
|
#########################
|
184
199
|
# Models
|
@@ -180,6 +180,21 @@ module IBMWatson
|
|
180
180
|
def url
|
181
181
|
@watson_service.url
|
182
182
|
end
|
183
|
+
|
184
|
+
# @!method configure_http_client(proxy: {}, timeout: {})
|
185
|
+
# Sets the http client config, currently works with timeout and proxies
|
186
|
+
# @param proxy [Hash] The hash of proxy configurations
|
187
|
+
# @option proxy address [String] The address of the proxy
|
188
|
+
# @option proxy port [Integer] The port of the proxy
|
189
|
+
# @option proxy username [String] The username of the proxy, if authentication is needed
|
190
|
+
# @option proxy password [String] The password of the proxy, if authentication is needed
|
191
|
+
# @option proxy headers [Hash] The headers to be used with the proxy
|
192
|
+
# @param timeout [Hash] The hash for configuring timeouts. `per_operation` has priority over `global`
|
193
|
+
# @option timeout per_operation [Hash] Timeouts per operation. Requires `read`, `write`, `connect`
|
194
|
+
# @option timeout global [Integer] Upper bound on total request time
|
195
|
+
def configure_http_client(proxy: {}, timeout: {})
|
196
|
+
@watson_service.configure_http_client(proxy: proxy, timeout: timeout)
|
197
|
+
end
|
183
198
|
# :nocov:
|
184
199
|
#########################
|
185
200
|
# Voices
|
@@ -150,6 +150,21 @@ module IBMWatson
|
|
150
150
|
def url
|
151
151
|
@watson_service.url
|
152
152
|
end
|
153
|
+
|
154
|
+
# @!method configure_http_client(proxy: {}, timeout: {})
|
155
|
+
# Sets the http client config, currently works with timeout and proxies
|
156
|
+
# @param proxy [Hash] The hash of proxy configurations
|
157
|
+
# @option proxy address [String] The address of the proxy
|
158
|
+
# @option proxy port [Integer] The port of the proxy
|
159
|
+
# @option proxy username [String] The username of the proxy, if authentication is needed
|
160
|
+
# @option proxy password [String] The password of the proxy, if authentication is needed
|
161
|
+
# @option proxy headers [Hash] The headers to be used with the proxy
|
162
|
+
# @param timeout [Hash] The hash for configuring timeouts. `per_operation` has priority over `global`
|
163
|
+
# @option timeout per_operation [Hash] Timeouts per operation. Requires `read`, `write`, `connect`
|
164
|
+
# @option timeout global [Integer] Upper bound on total request time
|
165
|
+
def configure_http_client(proxy: {}, timeout: {})
|
166
|
+
@watson_service.configure_http_client(proxy: proxy, timeout: timeout)
|
167
|
+
end
|
153
168
|
# :nocov:
|
154
169
|
#########################
|
155
170
|
# Methods
|
data/lib/ibm_watson/version.rb
CHANGED
@@ -131,6 +131,21 @@ module IBMWatson
|
|
131
131
|
def url
|
132
132
|
@watson_service.url
|
133
133
|
end
|
134
|
+
|
135
|
+
# @!method configure_http_client(proxy: {}, timeout: {})
|
136
|
+
# Sets the http client config, currently works with timeout and proxies
|
137
|
+
# @param proxy [Hash] The hash of proxy configurations
|
138
|
+
# @option proxy address [String] The address of the proxy
|
139
|
+
# @option proxy port [Integer] The port of the proxy
|
140
|
+
# @option proxy username [String] The username of the proxy, if authentication is needed
|
141
|
+
# @option proxy password [String] The password of the proxy, if authentication is needed
|
142
|
+
# @option proxy headers [Hash] The headers to be used with the proxy
|
143
|
+
# @param timeout [Hash] The hash for configuring timeouts. `per_operation` has priority over `global`
|
144
|
+
# @option timeout per_operation [Hash] Timeouts per operation. Requires `read`, `write`, `connect`
|
145
|
+
# @option timeout global [Integer] Upper bound on total request time
|
146
|
+
def configure_http_client(proxy: {}, timeout: {})
|
147
|
+
@watson_service.configure_http_client(proxy: proxy, timeout: timeout)
|
148
|
+
end
|
134
149
|
# :nocov:
|
135
150
|
#########################
|
136
151
|
# General
|
@@ -29,7 +29,6 @@ class WatsonService
|
|
29
29
|
password: nil,
|
30
30
|
use_vcap_services: true,
|
31
31
|
api_key: nil,
|
32
|
-
x_watson_learning_opt_out: false,
|
33
32
|
iam_apikey: nil,
|
34
33
|
iam_access_token: nil,
|
35
34
|
iam_url: nil
|
@@ -48,7 +47,6 @@ class WatsonService
|
|
48
47
|
headers = {
|
49
48
|
"User-Agent" => user_agent_string
|
50
49
|
}
|
51
|
-
headers["x-watson-learning-opt-out"] = true if vars[:x_watson_learning_opt_out]
|
52
50
|
if vars[:use_vcap_services]
|
53
51
|
@vcap_service_credentials = load_from_vcap_services(service_name: vars[:vcap_services_name])
|
54
52
|
if !@vcap_service_credentials.nil? && @vcap_service_credentials.instance_of?(Hash)
|
@@ -74,11 +72,6 @@ class WatsonService
|
|
74
72
|
|
75
73
|
@conn = HTTP::Client.new(
|
76
74
|
headers: headers
|
77
|
-
).timeout(
|
78
|
-
:per_operation,
|
79
|
-
read: 60,
|
80
|
-
write: 60,
|
81
|
-
connect: 60
|
82
75
|
)
|
83
76
|
end
|
84
77
|
|
@@ -177,4 +170,52 @@ class WatsonService
|
|
177
170
|
@temp_headers = headers
|
178
171
|
self
|
179
172
|
end
|
173
|
+
|
174
|
+
# @!method configure_http_client(proxy: {}, timeout: {})
|
175
|
+
# Sets the http client config, currently works with timeout and proxies
|
176
|
+
# @param proxy [Hash] The hash of proxy configurations
|
177
|
+
# @option proxy address [String] The address of the proxy
|
178
|
+
# @option proxy port [Integer] The port of the proxy
|
179
|
+
# @option proxy username [String] The username of the proxy, if authentication is needed
|
180
|
+
# @option proxy password [String] The password of the proxy, if authentication is needed
|
181
|
+
# @option proxy headers [Hash] The headers to be used with the proxy
|
182
|
+
# @param timeout [Hash] The hash for configuring timeouts. `per_operation` has priority over `global`
|
183
|
+
# @option timeout per_operation [Hash] Timeouts per operation. Requires `read`, `write`, `connect`
|
184
|
+
# @option timeout global [Integer] Upper bound on total request time
|
185
|
+
def configure_http_client(proxy: {}, timeout: {})
|
186
|
+
raise TypeError("proxy parameter must be a Hash") unless proxy.empty? || proxy.instance_of?(Hash)
|
187
|
+
raise TypeError("timeout parameter must be a Hash") unless timeout.empty? || timeout.instance_of?(Hash)
|
188
|
+
add_proxy(proxy) unless proxy.empty? || !proxy.dig(:address).is_a?(String) || !proxy.dig(:port).is_a?(Integer)
|
189
|
+
add_timeout(timeout) unless timeout.empty? || (!timeout.key?(:per_operation) && !timeout.key?(:global))
|
190
|
+
end
|
191
|
+
|
192
|
+
private
|
193
|
+
|
194
|
+
def add_timeout(timeout)
|
195
|
+
if timeout.key?(:per_operation)
|
196
|
+
raise TypeError("per_operation in timeout must be a Hash") unless timeout[:per_operation].instance_of?(Hash)
|
197
|
+
defaults = {
|
198
|
+
write: 0,
|
199
|
+
connect: 0,
|
200
|
+
read: 0
|
201
|
+
}
|
202
|
+
time = defaults.merge(timeout[:per_operation])
|
203
|
+
@conn = @conn.timeout(:per_operation, write: time[:write], connect: time[:connect], read: time[:read])
|
204
|
+
else
|
205
|
+
raise TypeError("global in timeout must be an Integer") unless timeout[:global].is_a?(Integer)
|
206
|
+
@conn = @conn.timeout(:global, write: timeout[:global], connect: 0, read: 0)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def add_proxy(proxy)
|
211
|
+
if (proxy[:username].nil? || proxy[:password].nil?) && proxy[:headers].nil?
|
212
|
+
@conn = @conn.via(proxy[:address], proxy[:port])
|
213
|
+
elsif !proxy[:username].nil? && !proxy[:password].nil? && proxy[:headers].nil?
|
214
|
+
@conn = @conn.via(proxy[:address], proxy[:port], proxy[:username], proxy[:password])
|
215
|
+
elsif !proxy[:headers].nil? && (proxy[:username].nil? || proxy[:password].nil?)
|
216
|
+
@conn = @conn.via(proxy[:address], proxy[:port], proxy[:headers])
|
217
|
+
else
|
218
|
+
@conn = @conn.via(proxy[:address], proxy[:port], proxy[:username], proxy[:password], proxy[:headers])
|
219
|
+
end
|
220
|
+
end
|
180
221
|
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require("json")
|
4
|
+
require_relative("./../test_helper.rb")
|
5
|
+
require("webmock/minitest")
|
6
|
+
|
7
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
8
|
+
|
9
|
+
# Unit tests for the configure_http_client customizations, such as proxies and timeouts
|
10
|
+
class HTTPConfigTest < Minitest::Test
|
11
|
+
def test_proxy_address_port
|
12
|
+
service = IBMWatson::NaturalLanguageUnderstandingV1.new(
|
13
|
+
version: "2018-03-16",
|
14
|
+
username: "username",
|
15
|
+
password: "password"
|
16
|
+
)
|
17
|
+
def service.conn
|
18
|
+
@watson_service.conn
|
19
|
+
end
|
20
|
+
service.configure_http_client(
|
21
|
+
proxy: {
|
22
|
+
address: "bogus_address.com",
|
23
|
+
port: 9999
|
24
|
+
}
|
25
|
+
)
|
26
|
+
proxy = service.conn.default_options.proxy
|
27
|
+
assert_equal("bogus_address.com", proxy[:proxy_address])
|
28
|
+
assert_equal(9999, proxy[:proxy_port])
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_proxy_username_password
|
32
|
+
service = IBMWatson::NaturalLanguageUnderstandingV1.new(
|
33
|
+
version: "2018-03-16",
|
34
|
+
username: "username",
|
35
|
+
password: "password"
|
36
|
+
)
|
37
|
+
def service.conn
|
38
|
+
@watson_service.conn
|
39
|
+
end
|
40
|
+
service.configure_http_client(
|
41
|
+
proxy: {
|
42
|
+
address: "bogus_address.com",
|
43
|
+
port: 9999,
|
44
|
+
username: "username",
|
45
|
+
password: "password"
|
46
|
+
}
|
47
|
+
)
|
48
|
+
proxy = service.conn.default_options.proxy
|
49
|
+
assert_equal("bogus_address.com", proxy[:proxy_address])
|
50
|
+
assert_equal(9999, proxy[:proxy_port])
|
51
|
+
assert_equal("username", proxy[:proxy_username])
|
52
|
+
assert_equal("password", proxy[:proxy_password])
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_proxy_headers
|
56
|
+
service = IBMWatson::NaturalLanguageUnderstandingV1.new(
|
57
|
+
version: "2018-03-16",
|
58
|
+
username: "username",
|
59
|
+
password: "password"
|
60
|
+
)
|
61
|
+
def service.conn
|
62
|
+
@watson_service.conn
|
63
|
+
end
|
64
|
+
service.configure_http_client(
|
65
|
+
proxy: {
|
66
|
+
address: "bogus_address.com",
|
67
|
+
port: 9999,
|
68
|
+
headers: {
|
69
|
+
bogus_header: true
|
70
|
+
}
|
71
|
+
}
|
72
|
+
)
|
73
|
+
proxy = service.conn.default_options.proxy
|
74
|
+
assert_equal("bogus_address.com", proxy[:proxy_address])
|
75
|
+
assert_equal(9999, proxy[:proxy_port])
|
76
|
+
assert_equal({ bogus_header: true }, proxy[:proxy_headers])
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_proxy_username_password_headers
|
80
|
+
service = IBMWatson::NaturalLanguageUnderstandingV1.new(
|
81
|
+
version: "2018-03-16",
|
82
|
+
username: "username",
|
83
|
+
password: "password"
|
84
|
+
)
|
85
|
+
def service.conn
|
86
|
+
@watson_service.conn
|
87
|
+
end
|
88
|
+
service.configure_http_client(
|
89
|
+
proxy: {
|
90
|
+
address: "bogus_address.com",
|
91
|
+
port: 9999,
|
92
|
+
username: "username",
|
93
|
+
password: "password",
|
94
|
+
headers: {
|
95
|
+
bogus_header: true
|
96
|
+
}
|
97
|
+
}
|
98
|
+
)
|
99
|
+
proxy = service.conn.default_options.proxy
|
100
|
+
assert_equal("bogus_address.com", proxy[:proxy_address])
|
101
|
+
assert_equal(9999, proxy[:proxy_port])
|
102
|
+
assert_equal("username", proxy[:proxy_username])
|
103
|
+
assert_equal("password", proxy[:proxy_password])
|
104
|
+
assert_equal({ bogus_header: true }, proxy[:proxy_headers])
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_timeout_per_operation
|
108
|
+
service = IBMWatson::NaturalLanguageUnderstandingV1.new(
|
109
|
+
version: "2018-03-16",
|
110
|
+
username: "username",
|
111
|
+
password: "password"
|
112
|
+
)
|
113
|
+
def service.conn
|
114
|
+
@watson_service.conn
|
115
|
+
end
|
116
|
+
service.configure_http_client(
|
117
|
+
timeout: {
|
118
|
+
per_operation: {
|
119
|
+
read: 5,
|
120
|
+
write: 7,
|
121
|
+
connect: 10
|
122
|
+
}
|
123
|
+
}
|
124
|
+
)
|
125
|
+
timeout_class = service.conn.default_options.timeout_class
|
126
|
+
assert_equal(HTTP::Timeout::PerOperation, timeout_class)
|
127
|
+
|
128
|
+
expected_timeouts = {
|
129
|
+
read_timeout: 5,
|
130
|
+
write_timeout: 7,
|
131
|
+
connect_timeout: 10
|
132
|
+
}
|
133
|
+
timeout = service.conn.default_options.timeout_options
|
134
|
+
assert_equal(expected_timeouts, timeout)
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_timeout_global
|
138
|
+
service = IBMWatson::NaturalLanguageUnderstandingV1.new(
|
139
|
+
version: "2018-03-16",
|
140
|
+
username: "username",
|
141
|
+
password: "password"
|
142
|
+
)
|
143
|
+
def service.conn
|
144
|
+
@watson_service.conn
|
145
|
+
end
|
146
|
+
service.configure_http_client(
|
147
|
+
timeout: {
|
148
|
+
global: 20
|
149
|
+
}
|
150
|
+
)
|
151
|
+
timeout_class = service.conn.default_options.timeout_class
|
152
|
+
assert_equal(HTTP::Timeout::Global, timeout_class)
|
153
|
+
|
154
|
+
expected_timeouts = {
|
155
|
+
read_timeout: 0,
|
156
|
+
write_timeout: 20,
|
157
|
+
connect_timeout: 0
|
158
|
+
}
|
159
|
+
timeout = service.conn.default_options.timeout_options
|
160
|
+
assert_equal(expected_timeouts, timeout)
|
161
|
+
end
|
162
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ibm_watson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Nussbaum
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -247,6 +247,7 @@ files:
|
|
247
247
|
- test/integration/test_visual_recognition_v3.rb
|
248
248
|
- test/test_helper.rb
|
249
249
|
- test/unit/test_assistant_v1.rb
|
250
|
+
- test/unit/test_configure_http_client.rb
|
250
251
|
- test/unit/test_discovery_v1.rb
|
251
252
|
- test/unit/test_iam_token_manager.rb
|
252
253
|
- test/unit/test_language_translator_v3.rb
|