ibm_watson 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,6 +30,7 @@ require "concurrent"
30
30
  require "erb"
31
31
  require "json"
32
32
  require_relative "./detailed_response"
33
+ require_relative "./common.rb"
33
34
 
34
35
  require_relative "./watson_service"
35
36
 
@@ -154,7 +155,7 @@ module IBMWatson
154
155
  "Content-Language" => content_language,
155
156
  "Accept-Language" => accept_language
156
157
  }
157
- headers["X-IBMCloud-SDK-Analytics"] = "service_name=tone_analyzer;service_version=V3;operation_id=tone"
158
+ headers = Common.new.get_default_headers(headers: headers, service_name: "tone_analyzer", service_version: "V3", operation_id: "tone")
158
159
 
159
160
  params = {
160
161
  "version" => @version,
@@ -219,7 +220,7 @@ module IBMWatson
219
220
  "Content-Language" => content_language,
220
221
  "Accept-Language" => accept_language
221
222
  }
222
- headers["X-IBMCloud-SDK-Analytics"] = "service_name=tone_analyzer;service_version=V3;operation_id=tone_chat"
223
+ headers = Common.new.get_default_headers(headers: headers, service_name: "tone_analyzer", service_version: "V3", operation_id: "tone_chat")
223
224
 
224
225
  params = {
225
226
  "version" => @version
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IBMWatson
4
- VERSION = "0.12.0"
4
+ VERSION = "0.13.0"
5
5
  end
@@ -22,6 +22,7 @@ require "concurrent"
22
22
  require "erb"
23
23
  require "json"
24
24
  require_relative "./detailed_response"
25
+ require_relative "./common.rb"
25
26
 
26
27
  require_relative "./watson_service"
27
28
 
@@ -120,7 +121,7 @@ module IBMWatson
120
121
  headers = {
121
122
  "Accept-Language" => accept_language
122
123
  }
123
- headers["X-IBMCloud-SDK-Analytics"] = "service_name=watson_vision_combined;service_version=V3;operation_id=classify"
124
+ headers = Common.new.get_default_headers(headers: headers, service_name: "watson_vision_combined", service_version: "V3", operation_id: "classify")
124
125
 
125
126
  params = {
126
127
  "version" => @version
@@ -199,7 +200,7 @@ module IBMWatson
199
200
  headers = {
200
201
  "Accept-Language" => accept_language
201
202
  }
202
- headers["X-IBMCloud-SDK-Analytics"] = "service_name=watson_vision_combined;service_version=V3;operation_id=detect_faces"
203
+ headers = Common.new.get_default_headers(headers: headers, service_name: "watson_vision_combined", service_version: "V3", operation_id: "detect_faces")
203
204
 
204
205
  params = {
205
206
  "version" => @version
@@ -274,7 +275,7 @@ module IBMWatson
274
275
 
275
276
  headers = {
276
277
  }
277
- headers["X-IBMCloud-SDK-Analytics"] = "service_name=watson_vision_combined;service_version=V3;operation_id=create_classifier"
278
+ headers = Common.new.get_default_headers(headers: headers, service_name: "watson_vision_combined", service_version: "V3", operation_id: "create_classifier")
278
279
 
279
280
  params = {
280
281
  "version" => @version
@@ -324,7 +325,7 @@ module IBMWatson
324
325
  def list_classifiers(verbose: nil)
325
326
  headers = {
326
327
  }
327
- headers["X-IBMCloud-SDK-Analytics"] = "service_name=watson_vision_combined;service_version=V3;operation_id=list_classifiers"
328
+ headers = Common.new.get_default_headers(headers: headers, service_name: "watson_vision_combined", service_version: "V3", operation_id: "list_classifiers")
328
329
 
329
330
  params = {
330
331
  "version" => @version,
@@ -354,7 +355,7 @@ module IBMWatson
354
355
 
355
356
  headers = {
356
357
  }
357
- headers["X-IBMCloud-SDK-Analytics"] = "service_name=watson_vision_combined;service_version=V3;operation_id=get_classifier"
358
+ headers = Common.new.get_default_headers(headers: headers, service_name: "watson_vision_combined", service_version: "V3", operation_id: "get_classifier")
358
359
 
359
360
  params = {
360
361
  "version" => @version
@@ -418,7 +419,7 @@ module IBMWatson
418
419
 
419
420
  headers = {
420
421
  }
421
- headers["X-IBMCloud-SDK-Analytics"] = "service_name=watson_vision_combined;service_version=V3;operation_id=update_classifier"
422
+ headers = Common.new.get_default_headers(headers: headers, service_name: "watson_vision_combined", service_version: "V3", operation_id: "update_classifier")
422
423
 
423
424
  params = {
424
425
  "version" => @version
@@ -467,7 +468,7 @@ module IBMWatson
467
468
 
468
469
  headers = {
469
470
  }
470
- headers["X-IBMCloud-SDK-Analytics"] = "service_name=watson_vision_combined;service_version=V3;operation_id=delete_classifier"
471
+ headers = Common.new.get_default_headers(headers: headers, service_name: "watson_vision_combined", service_version: "V3", operation_id: "delete_classifier")
471
472
 
472
473
  params = {
473
474
  "version" => @version
@@ -500,7 +501,7 @@ module IBMWatson
500
501
 
501
502
  headers = {
502
503
  }
503
- headers["X-IBMCloud-SDK-Analytics"] = "service_name=watson_vision_combined;service_version=V3;operation_id=get_core_ml_model"
504
+ headers = Common.new.get_default_headers(headers: headers, service_name: "watson_vision_combined", service_version: "V3", operation_id: "get_core_ml_model")
504
505
 
505
506
  params = {
506
507
  "version" => @version
@@ -538,7 +539,7 @@ module IBMWatson
538
539
 
539
540
  headers = {
540
541
  }
541
- headers["X-IBMCloud-SDK-Analytics"] = "service_name=watson_vision_combined;service_version=V3;operation_id=delete_user_data"
542
+ headers = Common.new.get_default_headers(headers: headers, service_name: "watson_vision_combined", service_version: "V3", operation_id: "delete_user_data")
542
543
 
543
544
  params = {
544
545
  "version" => @version,
@@ -8,6 +8,7 @@ require_relative("./detailed_response.rb")
8
8
  require_relative("./watson_api_exception.rb")
9
9
  require_relative("./iam_token_manager.rb")
10
10
  require_relative("./version.rb")
11
+ require_relative("./common.rb")
11
12
  # require("httplog")
12
13
  # HttpLog.configure do |config|
13
14
  # config.log_connect = true
@@ -19,6 +20,9 @@ require_relative("./version.rb")
19
20
  # end
20
21
 
21
22
  DEFAULT_CREDENTIALS_FILE_NAME = "ibm-credentials.env"
23
+ NORMALIZER = lambda do |uri| # Custom URI normalizer when using HTTP Client
24
+ HTTP::URI.parse uri
25
+ end
22
26
 
23
27
  # Class for interacting with the Watson API
24
28
  class WatsonService
@@ -46,14 +50,6 @@ class WatsonService
46
50
  @disable_ssl = false
47
51
  @display_name = vars[:display_name]
48
52
 
49
- user_agent_string = "watson-apis-ruby-sdk-" + IBMWatson::VERSION
50
- user_agent_string += " #{RbConfig::CONFIG["host"]}"
51
- user_agent_string += " #{RbConfig::CONFIG["RUBY_BASE_NAME"]}-#{RbConfig::CONFIG["RUBY_PROGRAM_VERSION"]}"
52
-
53
- headers = {
54
- "User-Agent" => user_agent_string
55
- }
56
-
57
53
  if !vars[:iam_access_token].nil? || !vars[:iam_apikey].nil?
58
54
  set_token_manager(iam_apikey: vars[:iam_apikey], iam_access_token: vars[:iam_access_token], iam_url: vars[:iam_url])
59
55
  elsif !vars[:username].nil? && !vars[:password].nil?
@@ -88,8 +84,8 @@ class WatsonService
88
84
  raise ArgumentError.new('The apikey shouldn\'t start or end with curly brackets or quotes. Be sure to remove any {} and \" characters surrounding your apikey') if check_bad_first_or_last_char(@iam_apikey)
89
85
 
90
86
  @conn = HTTP::Client.new(
91
- headers: headers
92
- )
87
+ headers: {}
88
+ ).use normalize_uri: { normalizer: NORMALIZER }
93
89
  end
94
90
 
95
91
  # Initiates the credentials based on the credential file
@@ -267,11 +263,11 @@ class WatsonService
267
263
  read: 0
268
264
  }
269
265
  time = defaults.merge(timeout[:per_operation])
270
- @conn = @conn.timeout(:per_operation, write: time[:write], connect: time[:connect], read: time[:read])
266
+ @conn = @conn.timeout(write: time[:write], connect: time[:connect], read: time[:read])
271
267
  else
272
268
  raise TypeError("global in timeout must be an Integer") unless timeout[:global].is_a?(Integer)
273
269
 
274
- @conn = @conn.timeout(:global, write: timeout[:global], connect: 0, read: 0)
270
+ @conn = @conn.timeout(timeout[:global])
275
271
  end
276
272
  end
277
273
 
data/lib/ibm_watson.rb CHANGED
@@ -15,4 +15,5 @@ module IBMWatson
15
15
  require_relative("./ibm_watson/language_translator_v3.rb")
16
16
  require_relative("./ibm_watson/compare_comply_v1.rb")
17
17
  require_relative("./ibm_watson/websocket/recognize_callback.rb")
18
+ require_relative("./ibm_watson/common.rb")
18
19
  end
@@ -281,6 +281,27 @@ if !ENV["SPEECH_TO_TEXT_USERNAME"].nil? && !ENV["SPEECH_TO_TEXT_PASSWORD"].nil?
281
281
  customization_id: customization_id
282
282
  )
283
283
  end
284
+
285
+ def test_add_word_double
286
+ model = @service.create_language_model(
287
+ name: "integration_test_model",
288
+ base_model_name: "en-US_BroadbandModel"
289
+ ).result
290
+ customization_id = model["customization_id"]
291
+ service_response = @service.add_word(
292
+ customization_id: customization_id,
293
+ word_name: "ABC"
294
+ )
295
+ assert_nil(service_response)
296
+ service_response = @service.get_word(
297
+ customization_id: customization_id,
298
+ word_name: "ABC"
299
+ )
300
+ refute_nil(service_response)
301
+ @service.delete_language_model(
302
+ customization_id: customization_id
303
+ )
304
+ end
284
305
  end
285
306
  else
286
307
  class SpeechToTextV1Test < Minitest::Test
@@ -134,9 +134,7 @@ class HTTPConfigTest < Minitest::Test
134
134
  assert_equal(HTTP::Timeout::Global, timeout_class)
135
135
 
136
136
  expected_timeouts = {
137
- read_timeout: 0,
138
- write_timeout: 20,
139
- connect_timeout: 0
137
+ global_timeout: 20
140
138
  }
141
139
  timeout = service.conn.default_options.timeout_options
142
140
  assert_equal(expected_timeouts, timeout)
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.12.0
4
+ version: 0.13.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: 2019-02-05 00:00:00.000000000 Z
11
+ date: 2019-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.3'
61
+ version: 4.1.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.3'
68
+ version: 4.1.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -246,6 +246,7 @@ files:
246
246
  - lib/ibm_watson.rb
247
247
  - lib/ibm_watson/assistant_v1.rb
248
248
  - lib/ibm_watson/assistant_v2.rb
249
+ - lib/ibm_watson/common.rb
249
250
  - lib/ibm_watson/compare_comply_v1.rb
250
251
  - lib/ibm_watson/detailed_response.rb
251
252
  - lib/ibm_watson/discovery_v1.rb
@@ -317,7 +318,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
317
318
  - !ruby/object:Gem::Version
318
319
  version: '0'
319
320
  requirements: []
320
- rubygems_version: 3.0.2
321
+ rubygems_version: 3.0.3
321
322
  signing_key:
322
323
  specification_version: 4
323
324
  summary: Official client library to use the IBM Watson Services