Skip to content

Commit

Permalink
Add stats endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbosco committed Oct 18, 2024
1 parent 5217f8f commit 142cd4a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/typesense.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ module Typesense
require_relative 'typesense/debug'
require_relative 'typesense/health'
require_relative 'typesense/metrics'
require_relative 'typesense/stats'
require_relative 'typesense/operations'
require_relative 'typesense/error'
3 changes: 2 additions & 1 deletion lib/typesense/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Typesense
class Client
attr_reader :configuration, :collections, :aliases, :keys, :debug, :health, :metrics, :operations,
attr_reader :configuration, :collections, :aliases, :keys, :debug, :health, :metrics, :stats, :operations,
:multi_search, :analytics, :presets

def initialize(options = {})
Expand All @@ -15,6 +15,7 @@ def initialize(options = {})
@debug = Debug.new(@api_call)
@health = Health.new(@api_call)
@metrics = Metrics.new(@api_call)
@stats = Stats.new(@api_call)
@operations = Operations.new(@api_call)
@analytics = Analytics.new(@api_call)
@presets = Presets.new(@api_call)
Expand Down
15 changes: 15 additions & 0 deletions lib/typesense/stats.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Typesense
class Stats
RESOURCE_PATH = '/stats.json'

def initialize(api_call)
@api_call = api_call
end

def retrieve
@api_call.get(RESOURCE_PATH)
end
end
end
23 changes: 23 additions & 0 deletions spec/typesense/stats_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require_relative '../spec_helper'
require_relative 'shared_configuration_context'

describe Typesense::Stats do
include_context 'with Typesense configuration'

describe '#retrieve' do
it 'retrieves cluster stats' do
stub_request(:get, Typesense::ApiCall.new(typesense.configuration).send(:uri_for, '/stats.json', typesense.configuration.nodes[0]))
.with(headers: {
'X-Typesense-Api-Key' => typesense.configuration.api_key,
'Content-Type' => 'application/json'
})
.to_return(status: 200, body: '{}', headers: { 'Content-Type': 'application/json' })

result = typesense.stats.retrieve

expect(result).to eq({})
end
end
end

0 comments on commit 142cd4a

Please sign in to comment.