Skip to content

Commit bcb457f

Browse files
committed
feat(synonyms): add synonym set classes
1 parent 0a0b1ba commit bcb457f

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

lib/typesense/synonym_set.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
module Typesense
4+
class SynonymSet
5+
def initialize(synonym_set_name, api_call)
6+
@synonym_set_name = synonym_set_name
7+
@api_call = api_call
8+
end
9+
10+
def retrieve
11+
@api_call.get(endpoint_path)
12+
end
13+
14+
def delete
15+
@api_call.delete(endpoint_path)
16+
end
17+
18+
private
19+
20+
def endpoint_path
21+
"#{SynonymSets::RESOURCE_PATH}/#{URI.encode_www_form_component(@synonym_set_name)}"
22+
end
23+
end
24+
end

lib/typesense/synonym_sets.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# frozen_string_literal: true
2+
3+
module Typesense
4+
class SynonymSets
5+
RESOURCE_PATH = '/synonym_sets'
6+
7+
def initialize(api_call)
8+
@api_call = api_call
9+
@synonym_sets = {}
10+
end
11+
12+
def upsert(synonym_set_name, params)
13+
@api_call.put(endpoint_path(synonym_set_name), params)
14+
end
15+
16+
def retrieve
17+
@api_call.get(endpoint_path)
18+
end
19+
20+
def [](synonym_set_name)
21+
@synonym_sets[synonym_set_name] ||= SynonymSet.new(synonym_set_name, @api_call)
22+
end
23+
24+
private
25+
26+
def endpoint_path(operation = nil)
27+
"#{RESOURCE_PATH}#{"/#{URI.encode_www_form_component(operation)}" unless operation.nil?}"
28+
end
29+
end
30+
end

0 commit comments

Comments
 (0)