Skip to content

Commit 0697657

Browse files
committed
Support for operations endpoint
1 parent 5b58461 commit 0697657

4 files changed

Lines changed: 46 additions & 1 deletion

File tree

lib/typesense.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ module Typesense
2222
require_relative 'typesense/debug'
2323
require_relative 'typesense/health'
2424
require_relative 'typesense/metrics'
25+
require_relative 'typesense/operations'
2526
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
5+
attr_reader :configuration, :collections, :aliases, :keys, :debug, :health, :metrics, :operations
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+
@operations = Operations.new(@api_call)
1617
end
1718
end
1819
end

lib/typesense/operations.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 Operations
5+
RESOURCE_PATH = '/operations'
6+
7+
def initialize(api_call)
8+
@api_call = api_call
9+
end
10+
11+
def perform(operation_name, query_params = {})
12+
@api_call.post("#{RESOURCE_PATH}/#{operation_name}", {}, query_params)
13+
end
14+
end
15+
end

spec/typesense/operations_spec.rb

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

0 commit comments

Comments
 (0)