Skip to content

Commit 142cd4a

Browse files
committed
Add stats endpoint
1 parent 5217f8f commit 142cd4a

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

lib/typesense.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ module Typesense
2929
require_relative 'typesense/debug'
3030
require_relative 'typesense/health'
3131
require_relative 'typesense/metrics'
32+
require_relative 'typesense/stats'
3233
require_relative 'typesense/operations'
3334
require_relative 'typesense/error'

lib/typesense/client.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module Typesense
44
class Client
5-
attr_reader :configuration, :collections, :aliases, :keys, :debug, :health, :metrics, :operations,
5+
attr_reader :configuration, :collections, :aliases, :keys, :debug, :health, :metrics, :stats, :operations,
66
:multi_search, :analytics, :presets
77

88
def initialize(options = {})
@@ -15,6 +15,7 @@ def initialize(options = {})
1515
@debug = Debug.new(@api_call)
1616
@health = Health.new(@api_call)
1717
@metrics = Metrics.new(@api_call)
18+
@stats = Stats.new(@api_call)
1819
@operations = Operations.new(@api_call)
1920
@analytics = Analytics.new(@api_call)
2021
@presets = Presets.new(@api_call)

lib/typesense/stats.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
module Typesense
4+
class Stats
5+
RESOURCE_PATH = '/stats.json'
6+
7+
def initialize(api_call)
8+
@api_call = api_call
9+
end
10+
11+
def retrieve
12+
@api_call.get(RESOURCE_PATH)
13+
end
14+
end
15+
end

spec/typesense/stats_spec.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+
require_relative '../spec_helper'
4+
require_relative 'shared_configuration_context'
5+
6+
describe Typesense::Stats do
7+
include_context 'with Typesense configuration'
8+
9+
describe '#retrieve' do
10+
it 'retrieves cluster stats' do
11+
stub_request(:get, Typesense::ApiCall.new(typesense.configuration).send(:uri_for, '/stats.json', typesense.configuration.nodes[0]))
12+
.with(headers: {
13+
'X-Typesense-Api-Key' => typesense.configuration.api_key,
14+
'Content-Type' => 'application/json'
15+
})
16+
.to_return(status: 200, body: '{}', headers: { 'Content-Type': 'application/json' })
17+
18+
result = typesense.stats.retrieve
19+
20+
expect(result).to eq({})
21+
end
22+
end
23+
end

0 commit comments

Comments
 (0)