Skip to content

Commit f2b801d

Browse files
committed
refactor: pass array query params as comma separated strings
1 parent 9f01578 commit f2b801d

File tree

6 files changed

+35
-21
lines changed

6 files changed

+35
-21
lines changed

lib/ibm_watson/discovery_v1.rb

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,11 @@ def list_fields(environment_id:, collection_ids:)
260260
}
261261
sdk_headers = Common.new.get_sdk_headers("discovery", "V1", "list_fields")
262262
headers.merge!(sdk_headers)
263+
collection_ids *= "," unless collection_ids.nil?
263264

264265
params = {
265266
"version" => @version,
266-
"collection_ids" => collection_ids.to_a
267+
"collection_ids" => collection_ids
267268
}
268269

269270
method_url = "/v1/environments/%s/fields" % [ERB::Util.url_encode(environment_id)]
@@ -1485,6 +1486,11 @@ def query_notices(environment_id:, collection_id:, filter: nil, query: nil, natu
14851486
}
14861487
sdk_headers = Common.new.get_sdk_headers("discovery", "V1", "query_notices")
14871488
headers.merge!(sdk_headers)
1489+
_return *= "," unless _return.nil?
1490+
sort *= "," unless sort.nil?
1491+
passages_fields *= "," unless passages_fields.nil?
1492+
similar_document_ids *= "," unless similar_document_ids.nil?
1493+
similar_fields *= "," unless similar_fields.nil?
14881494

14891495
params = {
14901496
"version" => @version,
@@ -1494,17 +1500,17 @@ def query_notices(environment_id:, collection_id:, filter: nil, query: nil, natu
14941500
"passages" => passages,
14951501
"aggregation" => aggregation,
14961502
"count" => count,
1497-
"return" => _return.to_a,
1503+
"return" => _return,
14981504
"offset" => offset,
1499-
"sort" => sort.to_a,
1505+
"sort" => sort,
15001506
"highlight" => highlight,
1501-
"passages.fields" => passages_fields.to_a,
1507+
"passages.fields" => passages_fields,
15021508
"passages.count" => passages_count,
15031509
"passages.characters" => passages_characters,
15041510
"deduplicate.field" => deduplicate_field,
15051511
"similar" => similar,
1506-
"similar.document_ids" => similar_document_ids.to_a,
1507-
"similar.fields" => similar_fields.to_a
1512+
"similar.document_ids" => similar_document_ids,
1513+
"similar.fields" => similar_fields
15081514
}
15091515

15101516
method_url = "/v1/environments/%s/collections/%s/notices" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)]
@@ -1686,23 +1692,28 @@ def federated_query_notices(environment_id:, collection_ids:, filter: nil, query
16861692
}
16871693
sdk_headers = Common.new.get_sdk_headers("discovery", "V1", "federated_query_notices")
16881694
headers.merge!(sdk_headers)
1695+
collection_ids *= "," unless collection_ids.nil?
1696+
_return *= "," unless _return.nil?
1697+
sort *= "," unless sort.nil?
1698+
similar_document_ids *= "," unless similar_document_ids.nil?
1699+
similar_fields *= "," unless similar_fields.nil?
16891700

16901701
params = {
16911702
"version" => @version,
1692-
"collection_ids" => collection_ids.to_a,
1703+
"collection_ids" => collection_ids,
16931704
"filter" => filter,
16941705
"query" => query,
16951706
"natural_language_query" => natural_language_query,
16961707
"aggregation" => aggregation,
16971708
"count" => count,
1698-
"return" => _return.to_a,
1709+
"return" => _return,
16991710
"offset" => offset,
1700-
"sort" => sort.to_a,
1711+
"sort" => sort,
17011712
"highlight" => highlight,
17021713
"deduplicate.field" => deduplicate_field,
17031714
"similar" => similar,
1704-
"similar.document_ids" => similar_document_ids.to_a,
1705-
"similar.fields" => similar_fields.to_a
1715+
"similar.document_ids" => similar_document_ids,
1716+
"similar.fields" => similar_fields
17061717
}
17071718

17081719
method_url = "/v1/environments/%s/notices" % [ERB::Util.url_encode(environment_id)]
@@ -2265,14 +2276,15 @@ def query_log(filter: nil, query: nil, count: nil, offset: nil, sort: nil)
22652276
}
22662277
sdk_headers = Common.new.get_sdk_headers("discovery", "V1", "query_log")
22672278
headers.merge!(sdk_headers)
2279+
sort *= "," unless sort.nil?
22682280

22692281
params = {
22702282
"version" => @version,
22712283
"filter" => filter,
22722284
"query" => query,
22732285
"count" => count,
22742286
"offset" => offset,
2275-
"sort" => sort.to_a
2287+
"sort" => sort
22762288
}
22772289

22782290
method_url = "/v1/logs"

lib/ibm_watson/speech_to_text_v1.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,9 @@ def recognize(audio:, content_type: nil, model: nil, language_customization_id:
365365
headers = {
366366
"Content-Type" => content_type
367367
}
368-
keywords *= "," unless keywords.nil?
369368
sdk_headers = Common.new.get_sdk_headers("speech_to_text", "V1", "recognize")
370369
headers.merge!(sdk_headers)
370+
keywords *= "," unless keywords.nil?
371371

372372
params = {
373373
"model" => model,
@@ -942,6 +942,7 @@ def create_job(audio:, content_type: nil, model: nil, callback_url: nil, events:
942942
}
943943
sdk_headers = Common.new.get_sdk_headers("speech_to_text", "V1", "create_job")
944944
headers.merge!(sdk_headers)
945+
keywords *= "," unless keywords.nil?
945946

946947
params = {
947948
"model" => model,
@@ -954,7 +955,7 @@ def create_job(audio:, content_type: nil, model: nil, callback_url: nil, events:
954955
"base_model_version" => base_model_version,
955956
"customization_weight" => customization_weight,
956957
"inactivity_timeout" => inactivity_timeout,
957-
"keywords" => keywords.to_a,
958+
"keywords" => keywords,
958959
"keywords_threshold" => keywords_threshold,
959960
"max_alternatives" => max_alternatives,
960961
"word_alternatives_threshold" => word_alternatives_threshold,

lib/ibm_watson/tone_analyzer_v3.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,12 @@ def tone(tone_input:, content_type: nil, sentences: nil, tones: nil, content_lan
134134
}
135135
sdk_headers = Common.new.get_sdk_headers("tone_analyzer", "V3", "tone")
136136
headers.merge!(sdk_headers)
137+
tones *= "," unless tones.nil?
137138

138139
params = {
139140
"version" => @version,
140141
"sentences" => sentences,
141-
"tones" => tones.to_a
142+
"tones" => tones
142143
}
143144

144145
if content_type.start_with?("application/json") && tone_input.instance_of?(Hash)

test/integration/test_discovery_v1.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def test_collections_fields_query_and_expansions
104104

105105
fields = @service.list_fields(
106106
environment_id: @environment_id,
107-
collection_ids: [new_collection_id]
107+
collection_ids: [new_collection_id, @collection_id]
108108
)
109109
refute(fields.nil?)
110110

test/integration/test_speech_to_text_v1.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_recognize_with_keywords
8080
content_type: "audio/l16; rate=44100",
8181
timestamps: true,
8282
word_alternatives_threshold: 0.9,
83-
keywords: %w"[colorado tornado]",
83+
keywords: %w[colorado tornado],
8484
keywords_threshold: 0.5
8585
)
8686
refute_nil(output.result["results"][0]["alternatives"][0]["transcript"])

test/integration/test_tone_analyzer_v3.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ def before_all
2626
end
2727

2828
def test_tone
29-
tone_text = File.read(Dir.getwd + "/resources/personality.txt")
29+
tone_text = File.read(Dir.getwd + "/resources/tone-example.json")
3030
service_response = service.tone(
3131
tone_input: tone_text,
32-
content_type: "text/plain"
32+
content_type: "application/json"
3333
)
3434
assert((200..299).cover?(service_response.status))
3535
end
3636

3737
def test_tone_with_args
38-
tone_text = File.read(Dir.getwd + "/resources/personality.txt")
38+
tone_text = File.read(Dir.getwd + "/resources/tone-example.json")
3939
service_response = service.tone(
4040
tone_input: tone_text,
41-
content_type: "text/plain",
41+
content_type: "application/json",
4242
sentences: false
4343
)
4444
assert((200..299).cover?(service_response.status))

0 commit comments

Comments
 (0)