From b59957005a1d2ea5955e2bd849821f0a63fcff03 Mon Sep 17 00:00:00 2001 From: Andrew Myers Date: Tue, 14 May 2024 11:28:51 -0400 Subject: [PATCH] Back to faceted search for finding by name, searching curent workspace by default, and looking for a match in the first 10 search results. --- lib/sony_ci_api/client.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/sony_ci_api/client.rb b/lib/sony_ci_api/client.rb index 5457c7c..b0b9424 100644 --- a/lib/sony_ci_api/client.rb +++ b/lib/sony_ci_api/client.rb @@ -151,13 +151,16 @@ def workspace_search(workspace_id = self.workspace_id, **params) end def faceted_search(**params) + # Set workspaceIds to the current workspace as a default. + params['workspaceIds'] ||= [workspace_id] get_items('/faceted-search', params: params, post: true) end # Returns an item whose name matches the `name` parameter. def find_by_name(name, **params) - params.merge!(query: name, limit: MAX_ITEMS) - items = workspace_search(**params).select { |item| item['name'] == name } + raise ArgumentError, "Expected first argument to be a string, but got #{name.class}" unless name.is_a? String + params.merge!(query: name, limit: 10) + items = faceted_search(**params).select { |item| item['name'] == name } raise "#{items.count} items found with name '#{name}'" if items.count > 1 items.first end