Skip to content

Commit 2f4bf69

Browse files
committed
feat(analytics): rename old API to analytics_v1
1 parent 89ea6b0 commit 2f4bf69

5 files changed

Lines changed: 79 additions & 1 deletion

File tree

lib/typesense.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ module Typesense
2626
require_relative 'typesense/analytics'
2727
require_relative 'typesense/analytics_rules'
2828
require_relative 'typesense/analytics_rule'
29+
require_relative 'typesense/analytics_v1'
30+
require_relative 'typesense/analytics_events_v1'
31+
require_relative 'typesense/analytics_rules_v1'
32+
require_relative 'typesense/analytics_rule_v1'
2933
require_relative 'typesense/presets'
3034
require_relative 'typesense/preset'
3135
require_relative 'typesense/debug'

lib/typesense/analytics_rule_v1.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 AnalyticsRuleV1
5+
def initialize(rule_name, api_call)
6+
@rule_name = rule_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+
"#{AnalyticsRulesV1::RESOURCE_PATH}/#{URI.encode_www_form_component(@rule_name)}"
22+
end
23+
end
24+
end
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 AnalyticsRulesV1
5+
RESOURCE_PATH = '/analytics/rules'
6+
7+
def initialize(api_call)
8+
@api_call = api_call
9+
@analytics_rules = {}
10+
end
11+
12+
def upsert(rule_name, params)
13+
@api_call.put(endpoint_path(rule_name), params)
14+
end
15+
16+
def retrieve
17+
@api_call.get(endpoint_path)
18+
end
19+
20+
def [](rule_name)
21+
@analytics_rules[rule_name] ||= AnalyticsRuleV1.new(rule_name, @api_call)
22+
end
23+
24+
private
25+
26+
def endpoint_path(operation = nil)
27+
"#{AnalyticsRulesV1::RESOURCE_PATH}#{"/#{URI.encode_www_form_component(operation)}" unless operation.nil?}"
28+
end
29+
end
30+
end

lib/typesense/analytics_v1.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 AnalyticsV1
5+
RESOURCE_PATH = '/analytics'
6+
7+
def initialize(api_call)
8+
@api_call = api_call
9+
end
10+
11+
def rules
12+
@rules ||= AnalyticsRulesV1.new(@api_call)
13+
end
14+
15+
def events
16+
@events ||= AnalyticsEventsV1.new(@api_call)
17+
end
18+
end
19+
end

lib/typesense/client.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Typesense
44
class Client
55
attr_reader :configuration, :collections, :aliases, :keys, :debug, :health, :metrics, :stats, :operations,
6-
:multi_search, :analytics, :presets, :stemming, :nl_search_models, :synonym_sets, :curation_sets
6+
:multi_search, :analytics, :analytics_v1, :presets, :stemming, :nl_search_models, :synonym_sets, :curation_sets
77

88
def initialize(options = {})
99
@configuration = Configuration.new(options)
@@ -18,6 +18,7 @@ def initialize(options = {})
1818
@stats = Stats.new(@api_call)
1919
@operations = Operations.new(@api_call)
2020
@analytics = Analytics.new(@api_call)
21+
@analytics_v1 = AnalyticsV1.new(@api_call)
2122
@stemming = Stemming.new(@api_call)
2223
@presets = Presets.new(@api_call)
2324
@nl_search_models = NlSearchModels.new(@api_call)

0 commit comments

Comments
 (0)