Skip to content

Commit b728531

Browse files
committed
feat(analytics): add new analytics API
1 parent 2f4bf69 commit b728531

File tree

5 files changed

+33
-12
lines changed

5 files changed

+33
-12
lines changed

lib/typesense.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module Typesense
2424
require_relative 'typesense/key'
2525
require_relative 'typesense/multi_search'
2626
require_relative 'typesense/analytics'
27+
require_relative 'typesense/analytics_events'
2728
require_relative 'typesense/analytics_rules'
2829
require_relative 'typesense/analytics_rule'
2930
require_relative 'typesense/analytics_v1'

lib/typesense/analytics.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,9 @@ def initialize(api_call)
1111
def rules
1212
@rules ||= AnalyticsRules.new(@api_call)
1313
end
14+
15+
def events
16+
@events ||= AnalyticsEvents.new(@api_call)
17+
end
1418
end
1519
end

lib/typesense/analytics_events.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
module Typesense
4+
class AnalyticsEvents
5+
RESOURCE_PATH = '/analytics/events'
6+
7+
def initialize(api_call)
8+
@api_call = api_call
9+
end
10+
11+
def create(params)
12+
@api_call.post(self.class::RESOURCE_PATH, params)
13+
end
14+
15+
def retrieve(params = {})
16+
@api_call.get(self.class::RESOURCE_PATH, params)
17+
end
18+
end
19+
end

lib/typesense/analytics_rule.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ def delete
1515
@api_call.delete(endpoint_path)
1616
end
1717

18+
def update(params)
19+
@api_call.put(endpoint_path, params)
20+
end
21+
1822
private
1923

2024
def endpoint_path

lib/typesense/analytics_rules.rb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,19 @@ class AnalyticsRules
55
RESOURCE_PATH = '/analytics/rules'
66

77
def initialize(api_call)
8-
@api_call = api_call
9-
@analytics_rules = {}
8+
@api_call = api_call
109
end
1110

12-
def upsert(rule_name, params)
13-
@api_call.put(endpoint_path(rule_name), params)
11+
def create(rules)
12+
@api_call.post(self.class::RESOURCE_PATH, rules)
1413
end
1514

1615
def retrieve
17-
@api_call.get(endpoint_path)
16+
@api_call.get(self.class::RESOURCE_PATH)
1817
end
1918

2019
def [](rule_name)
21-
@analytics_rules[rule_name] ||= AnalyticsRule.new(rule_name, @api_call)
22-
end
23-
24-
private
25-
26-
def endpoint_path(operation = nil)
27-
"#{AnalyticsRules::RESOURCE_PATH}#{"/#{URI.encode_www_form_component(operation)}" unless operation.nil?}"
20+
AnalyticsRule.new(rule_name, @api_call)
2821
end
2922
end
3023
end

0 commit comments

Comments
 (0)