Skip to content

Commit e643362

Browse files
committed
Added stats endpoint
1 parent dc4f09c commit e643362

6 files changed

Lines changed: 45 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Tests are also a good place to know how the the library works internally: [spec]
3333

3434
| Typesense Server | typesense-ruby |
3535
|------------------|----------------|
36+
| \>= v0.18.2 | \>= v0.11.0 |
3637
| \>= v0.18.0 | \>= v0.10.0 |
3738
| \>= v0.17.0 | \>= v0.9.0 |
3839
| \>= v0.16.0 | \>= v0.8.0 |

lib/typesense.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ module Typesense
2222
require_relative 'typesense/debug'
2323
require_relative 'typesense/health'
2424
require_relative 'typesense/metrics'
25+
require_relative 'typesense/stats'
2526
require_relative 'typesense/operations'
2627
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, :operations, :stats
66

77
def initialize(options = {})
88
@configuration = Configuration.new(options)
@@ -13,6 +13,7 @@ def initialize(options = {})
1313
@debug = Debug.new(@api_call)
1414
@health = Health.new(@api_call)
1515
@metrics = Metrics.new(@api_call)
16+
@stats = Stats.new(@api_call)
1617
@operations = Operations.new(@api_call)
1718
end
1819
end

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

lib/typesense/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Typesense
4-
VERSION = '0.10.0'
4+
VERSION = '0.11.0'
55
end

spec/typesense/stats_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../spec_helper'
4+
require_relative 'shared_configuration_context'
5+
6+
describe Typesense::Stats do
7+
subject(:stats) { typesense.stats }
8+
9+
include_context 'with Typesense configuration'
10+
11+
describe '#retrieve' do
12+
it 'retrieves endpoint stats' do
13+
stub_request(:get, Typesense::ApiCall.new(typesense.configuration).send(:uri_for, '/stats.json', typesense.configuration.nodes[0]))
14+
.with(headers: {
15+
'X-Typesense-Api-Key' => typesense.configuration.api_key,
16+
'Content-Type' => 'application/json'
17+
})
18+
.to_return(status: 200, body: '{}', headers: { 'Content-Type': 'application/json' })
19+
20+
result = stats.retrieve
21+
22+
expect(result).to eq({})
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)