Skip to content

Commit de1aef3

Browse files
committed
feat(curation): add curation set classes
1 parent 9c0e948 commit de1aef3

4 files changed

Lines changed: 108 additions & 0 deletions

File tree

lib/typesense/curation_set.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
module Typesense
4+
class CurationSet
5+
attr_reader :items
6+
7+
def initialize(curation_set_name, api_call)
8+
@curation_set_name = curation_set_name
9+
@api_call = api_call
10+
@items = CurationSetItems.new(@curation_set_name, @api_call)
11+
end
12+
13+
def upsert(curation_set_data)
14+
@api_call.put(endpoint_path, curation_set_data)
15+
end
16+
17+
def retrieve
18+
@api_call.get(endpoint_path)
19+
end
20+
21+
def delete
22+
@api_call.delete(endpoint_path)
23+
end
24+
25+
private
26+
27+
def endpoint_path
28+
"#{CurationSets::RESOURCE_PATH}/#{URI.encode_www_form_component(@curation_set_name)}"
29+
end
30+
end
31+
end

lib/typesense/curation_set_item.rb

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

lib/typesense/curation_sets.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
module Typesense
4+
class CurationSets
5+
RESOURCE_PATH = '/curation_sets'
6+
7+
def initialize(api_call)
8+
@api_call = api_call
9+
end
10+
11+
def upsert(curation_set_name, curation_set_data)
12+
@api_call.put("#{self.class::RESOURCE_PATH}/#{URI.encode_www_form_component(curation_set_name)}", curation_set_data)
13+
end
14+
15+
def retrieve
16+
@api_call.get(self.class::RESOURCE_PATH)
17+
end
18+
19+
def [](curation_set_name)
20+
CurationSet.new(curation_set_name, @api_call)
21+
end
22+
end
23+
end

0 commit comments

Comments
 (0)