ibm_watson 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -79,7 +79,7 @@ require_relative "./watson_service"
79
79
  module IBMWatson
80
80
  ##
81
81
  # The Text to Speech V1 service.
82
- class TextToSpeechV1
82
+ class TextToSpeechV1 < WatsonService
83
83
  include Concurrent::Async
84
84
  ##
85
85
  # @!method initialize(args)
@@ -110,7 +110,6 @@ module IBMWatson
110
110
  # 'https://iam.ng.bluemix.net/identity/token'.
111
111
  def initialize(args = {})
112
112
  @__async_initialized__ = false
113
- super()
114
113
  defaults = {}
115
114
  defaults[:url] = "https://stream.watsonplatform.net/text-to-speech/api"
116
115
  defaults[:username] = nil
@@ -119,83 +118,10 @@ module IBMWatson
119
118
  defaults[:iam_access_token] = nil
120
119
  defaults[:iam_url] = nil
121
120
  args = defaults.merge(args)
122
- @watson_service = WatsonService.new(
123
- vcap_services_name: "text_to_speech",
124
- url: args[:url],
125
- username: args[:username],
126
- password: args[:password],
127
- iam_apikey: args[:iam_apikey],
128
- iam_access_token: args[:iam_access_token],
129
- iam_url: args[:iam_url],
130
- use_vcap_services: true
131
- )
132
- end
133
-
134
- # :nocov:
135
- def add_default_headers(headers: {})
136
- @watson_service.add_default_headers(headers: headers)
137
- end
138
-
139
- def _iam_access_token(iam_access_token:)
140
- @watson_service._iam_access_token(iam_access_token: iam_access_token)
141
- end
142
-
143
- def _iam_apikey(iam_apikey:)
144
- @watson_service._iam_apikey(iam_apikey: iam_apikey)
145
- end
146
-
147
- # @return [DetailedResponse]
148
- def request(args)
149
- @watson_service.request(args)
150
- end
151
-
152
- # @note Chainable
153
- # @param headers [Hash] Custom headers to be sent with the request
154
- # @return [self]
155
- def headers(headers)
156
- @watson_service.headers(headers)
157
- self
158
- end
159
-
160
- def password=(password)
161
- @watson_service.password = password
162
- end
163
-
164
- def password
165
- @watson_service.password
166
- end
167
-
168
- def username=(username)
169
- @watson_service.username = username
170
- end
171
-
172
- def username
173
- @watson_service.username
174
- end
175
-
176
- def url=(url)
177
- @watson_service.url = url
121
+ args[:vcap_services_name] = "text_to_speech"
122
+ super
178
123
  end
179
124
 
180
- def url
181
- @watson_service.url
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
198
- # :nocov:
199
125
  #########################
200
126
  # Voices
201
127
  #########################
@@ -235,6 +161,7 @@ module IBMWatson
235
161
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
236
162
  def get_voice(voice:, customization_id: nil)
237
163
  raise ArgumentError("voice must be provided") if voice.nil?
164
+
238
165
  headers = {
239
166
  }
240
167
  params = {
@@ -289,6 +216,7 @@ module IBMWatson
289
216
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
290
217
  def synthesize(text:, accept: nil, voice: nil, customization_id: nil)
291
218
  raise ArgumentError("text must be provided") if text.nil?
219
+
292
220
  headers = {
293
221
  "Accept" => accept
294
222
  }
@@ -339,6 +267,7 @@ module IBMWatson
339
267
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
340
268
  def get_pronunciation(text:, voice: nil, format: nil, customization_id: nil)
341
269
  raise ArgumentError("text must be provided") if text.nil?
270
+
342
271
  headers = {
343
272
  }
344
273
  params = {
@@ -378,6 +307,7 @@ module IBMWatson
378
307
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
379
308
  def create_voice_model(name:, language: nil, description: nil)
380
309
  raise ArgumentError("name must be provided") if name.nil?
310
+
381
311
  headers = {
382
312
  }
383
313
  data = {
@@ -450,6 +380,7 @@ module IBMWatson
450
380
  # @return [nil]
451
381
  def update_voice_model(customization_id:, name: nil, description: nil, words: nil)
452
382
  raise ArgumentError("customization_id must be provided") if customization_id.nil?
383
+
453
384
  headers = {
454
385
  }
455
386
  data = {
@@ -483,6 +414,7 @@ module IBMWatson
483
414
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
484
415
  def get_voice_model(customization_id:)
485
416
  raise ArgumentError("customization_id must be provided") if customization_id.nil?
417
+
486
418
  headers = {
487
419
  }
488
420
  method_url = "/v1/customizations/%s" % [ERB::Util.url_encode(customization_id)]
@@ -508,6 +440,7 @@ module IBMWatson
508
440
  # @return [nil]
509
441
  def delete_voice_model(customization_id:)
510
442
  raise ArgumentError("customization_id must be provided") if customization_id.nil?
443
+
511
444
  headers = {
512
445
  }
513
446
  method_url = "/v1/customizations/%s" % [ERB::Util.url_encode(customization_id)]
@@ -547,7 +480,9 @@ module IBMWatson
547
480
  # @return [nil]
548
481
  def add_words(customization_id:, words:)
549
482
  raise ArgumentError("customization_id must be provided") if customization_id.nil?
483
+
550
484
  raise ArgumentError("words must be provided") if words.nil?
485
+
551
486
  headers = {
552
487
  }
553
488
  data = {
@@ -579,6 +514,7 @@ module IBMWatson
579
514
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
580
515
  def list_words(customization_id:)
581
516
  raise ArgumentError("customization_id must be provided") if customization_id.nil?
517
+
582
518
  headers = {
583
519
  }
584
520
  method_url = "/v1/customizations/%s/words" % [ERB::Util.url_encode(customization_id)]
@@ -618,8 +554,11 @@ module IBMWatson
618
554
  # @return [nil]
619
555
  def add_word(customization_id:, word:, translation:, part_of_speech: nil)
620
556
  raise ArgumentError("customization_id must be provided") if customization_id.nil?
557
+
621
558
  raise ArgumentError("word must be provided") if word.nil?
559
+
622
560
  raise ArgumentError("translation must be provided") if translation.nil?
561
+
623
562
  headers = {
624
563
  }
625
564
  data = {
@@ -652,7 +591,9 @@ module IBMWatson
652
591
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
653
592
  def get_word(customization_id:, word:)
654
593
  raise ArgumentError("customization_id must be provided") if customization_id.nil?
594
+
655
595
  raise ArgumentError("word must be provided") if word.nil?
596
+
656
597
  headers = {
657
598
  }
658
599
  method_url = "/v1/customizations/%s/words/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(word)]
@@ -680,7 +621,9 @@ module IBMWatson
680
621
  # @return [nil]
681
622
  def delete_word(customization_id:, word:)
682
623
  raise ArgumentError("customization_id must be provided") if customization_id.nil?
624
+
683
625
  raise ArgumentError("word must be provided") if word.nil?
626
+
684
627
  headers = {
685
628
  }
686
629
  method_url = "/v1/customizations/%s/words/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(word)]
@@ -713,6 +656,7 @@ module IBMWatson
713
656
  # @return [nil]
714
657
  def delete_user_data(customer_id:)
715
658
  raise ArgumentError("customer_id must be provided") if customer_id.nil?
659
+
716
660
  headers = {
717
661
  }
718
662
  params = {
@@ -37,7 +37,7 @@ require_relative "./watson_service"
37
37
  module IBMWatson
38
38
  ##
39
39
  # The Tone Analyzer V3 service.
40
- class ToneAnalyzerV3
40
+ class ToneAnalyzerV3 < WatsonService
41
41
  include Concurrent::Async
42
42
  ##
43
43
  # @!method initialize(args)
@@ -78,7 +78,6 @@ module IBMWatson
78
78
  # 'https://iam.ng.bluemix.net/identity/token'.
79
79
  def initialize(args = {})
80
80
  @__async_initialized__ = false
81
- super()
82
81
  defaults = {}
83
82
  defaults[:version] = nil
84
83
  defaults[:url] = "https://gateway.watsonplatform.net/tone-analyzer/api"
@@ -88,84 +87,11 @@ module IBMWatson
88
87
  defaults[:iam_access_token] = nil
89
88
  defaults[:iam_url] = nil
90
89
  args = defaults.merge(args)
91
- @watson_service = WatsonService.new(
92
- vcap_services_name: "tone_analyzer",
93
- url: args[:url],
94
- username: args[:username],
95
- password: args[:password],
96
- iam_apikey: args[:iam_apikey],
97
- iam_access_token: args[:iam_access_token],
98
- iam_url: args[:iam_url],
99
- use_vcap_services: true
100
- )
90
+ args[:vcap_services_name] = "tone_analyzer"
91
+ super
101
92
  @version = args[:version]
102
93
  end
103
94
 
104
- # :nocov:
105
- def add_default_headers(headers: {})
106
- @watson_service.add_default_headers(headers: headers)
107
- end
108
-
109
- def _iam_access_token(iam_access_token:)
110
- @watson_service._iam_access_token(iam_access_token: iam_access_token)
111
- end
112
-
113
- def _iam_apikey(iam_apikey:)
114
- @watson_service._iam_apikey(iam_apikey: iam_apikey)
115
- end
116
-
117
- # @return [DetailedResponse]
118
- def request(args)
119
- @watson_service.request(args)
120
- end
121
-
122
- # @note Chainable
123
- # @param headers [Hash] Custom headers to be sent with the request
124
- # @return [self]
125
- def headers(headers)
126
- @watson_service.headers(headers)
127
- self
128
- end
129
-
130
- def password=(password)
131
- @watson_service.password = password
132
- end
133
-
134
- def password
135
- @watson_service.password
136
- end
137
-
138
- def username=(username)
139
- @watson_service.username = username
140
- end
141
-
142
- def username
143
- @watson_service.username
144
- end
145
-
146
- def url=(url)
147
- @watson_service.url = url
148
- end
149
-
150
- def url
151
- @watson_service.url
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
168
- # :nocov:
169
95
  #########################
170
96
  # Methods
171
97
  #########################
@@ -218,7 +144,9 @@ module IBMWatson
218
144
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
219
145
  def tone(tone_input:, content_type:, sentences: nil, tones: nil, content_language: nil, accept_language: nil)
220
146
  raise ArgumentError("tone_input must be provided") if tone_input.nil?
147
+
221
148
  raise ArgumentError("content_type must be provided") if content_type.nil?
149
+
222
150
  headers = {
223
151
  "Content-Type" => content_type,
224
152
  "Content-Language" => content_language,
@@ -278,6 +206,7 @@ module IBMWatson
278
206
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
279
207
  def tone_chat(utterances:, content_language: nil, accept_language: nil)
280
208
  raise ArgumentError("utterances must be provided") if utterances.nil?
209
+
281
210
  headers = {
282
211
  "Content-Language" => content_language,
283
212
  "Accept-Language" => accept_language
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IBMWatson
4
- VERSION = "0.5.1"
4
+ VERSION = "0.6.0"
5
5
  end
@@ -29,7 +29,7 @@ require_relative "./watson_service"
29
29
  module IBMWatson
30
30
  ##
31
31
  # The Visual Recognition V3 service.
32
- class VisualRecognitionV3
32
+ class VisualRecognitionV3 < WatsonService
33
33
  include Concurrent::Async
34
34
  ##
35
35
  # @!method initialize(args)
@@ -61,7 +61,6 @@ module IBMWatson
61
61
  # 'https://iam.ng.bluemix.net/identity/token'.
62
62
  def initialize(args = {})
63
63
  @__async_initialized__ = false
64
- super()
65
64
  defaults = {}
66
65
  defaults[:version] = nil
67
66
  defaults[:url] = "https://gateway.watsonplatform.net/visual-recognition/api"
@@ -70,83 +69,11 @@ module IBMWatson
70
69
  defaults[:iam_access_token] = nil
71
70
  defaults[:iam_url] = nil
72
71
  args = defaults.merge(args)
73
- @watson_service = WatsonService.new(
74
- vcap_services_name: "watson_vision_combined",
75
- url: args[:url],
76
- api_key: args[:api_key],
77
- iam_apikey: args[:iam_apikey],
78
- iam_access_token: args[:iam_access_token],
79
- iam_url: args[:iam_url],
80
- use_vcap_services: true
81
- )
72
+ args[:vcap_services_name] = "watson_vision_combined"
73
+ super
82
74
  @version = args[:version]
83
75
  end
84
76
 
85
- # :nocov:
86
- def add_default_headers(headers: {})
87
- @watson_service.add_default_headers(headers: headers)
88
- end
89
-
90
- def _iam_access_token(iam_access_token:)
91
- @watson_service._iam_access_token(iam_access_token: iam_access_token)
92
- end
93
-
94
- def _iam_apikey(iam_apikey:)
95
- @watson_service._iam_apikey(iam_apikey: iam_apikey)
96
- end
97
-
98
- # @return [DetailedResponse]
99
- def request(args)
100
- @watson_service.request(args)
101
- end
102
-
103
- # @note Chainable
104
- # @param headers [Hash] Custom headers to be sent with the request
105
- # @return [self]
106
- def headers(headers)
107
- @watson_service.headers(headers)
108
- self
109
- end
110
-
111
- def password=(password)
112
- @watson_service.password = password
113
- end
114
-
115
- def password
116
- @watson_service.password
117
- end
118
-
119
- def username=(username)
120
- @watson_service.username = username
121
- end
122
-
123
- def username
124
- @watson_service.username
125
- end
126
-
127
- def url=(url)
128
- @watson_service.url = url
129
- end
130
-
131
- def url
132
- @watson_service.url
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
149
- # :nocov:
150
77
  #########################
151
78
  # General
152
79
  #########################
@@ -337,7 +264,9 @@ module IBMWatson
337
264
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
338
265
  def create_classifier(name:, **args)
339
266
  raise ArgumentError("name must be provided") if name.nil?
267
+
340
268
  raise ArgumentError("<classname>_positive_examples must be provided") unless args.keys.any? { |key| key.to_s.end_with?("_positive_examples") }
269
+
341
270
  positive_keys = args.keys
342
271
  positive_keys.keep_if { |key| key.to_s.end_with?("_positive_examples") }
343
272
  headers = {
@@ -414,6 +343,7 @@ module IBMWatson
414
343
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
415
344
  def get_classifier(classifier_id:)
416
345
  raise ArgumentError("classifier_id must be provided") if classifier_id.nil?
346
+
417
347
  headers = {
418
348
  }
419
349
  params = {
@@ -469,6 +399,7 @@ module IBMWatson
469
399
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
470
400
  def update_classifier(classifier_id:, **args)
471
401
  raise ArgumentError("classifier_id must be provided") if classifier_id.nil?
402
+
472
403
  headers = {
473
404
  }
474
405
  params = {
@@ -520,6 +451,7 @@ module IBMWatson
520
451
  # @return [nil]
521
452
  def delete_classifier(classifier_id:)
522
453
  raise ArgumentError("classifier_id must be provided") if classifier_id.nil?
454
+
523
455
  headers = {
524
456
  }
525
457
  params = {
@@ -548,6 +480,7 @@ module IBMWatson
548
480
  # @return [DetailedResponse] A `DetailedResponse` object representing the response.
549
481
  def get_core_ml_model(classifier_id:)
550
482
  raise ArgumentError("classifier_id must be provided") if classifier_id.nil?
483
+
551
484
  headers = {
552
485
  }
553
486
  params = {
@@ -581,6 +514,7 @@ module IBMWatson
581
514
  # @return [nil]
582
515
  def delete_user_data(customer_id:)
583
516
  raise ArgumentError("customer_id must be provided") if customer_id.nil?
517
+
584
518
  headers = {
585
519
  }
586
520
  params = {