diff --git a/lib/typesense.rb b/lib/typesense.rb index bfa51a6..81b163e 100644 --- a/lib/typesense.rb +++ b/lib/typesense.rb @@ -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' diff --git a/lib/typesense/client.rb b/lib/typesense/client.rb index 01d1224..9bb4df2 100644 --- a/lib/typesense/client.rb +++ b/lib/typesense/client.rb @@ -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 = {}) @@ -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) diff --git a/lib/typesense/stats.rb b/lib/typesense/stats.rb new file mode 100644 index 0000000..900d860 --- /dev/null +++ b/lib/typesense/stats.rb @@ -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 diff --git a/spec/typesense/stats_spec.rb b/spec/typesense/stats_spec.rb new file mode 100644 index 0000000..25ce5ce --- /dev/null +++ b/spec/typesense/stats_spec.rb @@ -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