Skip to content

Add experimental Network API #600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -721,3 +721,39 @@ multi_search_federated_1: |-
queries: [{ index_uid: 'movies', q: 'batman' }, { index_uid: 'comics', q: 'batman' }],
federation: {}
)
multi_search_remote_federated_1: |-
client.multi_search(
federation: {},
queries: [
{
index_uid: 'movies',
q: 'batman',
federation_options: {
remote: 'ms-00'
}
},
{
index_uid: 'movies',
q: 'batman',
federation_options: {
remote: 'ms-01'
}
}
]
)
get_network_1: |-
client.network
update_network_1: |-
client.update_network(
self: 'ms-00',
remotes: {
'ms-00': {
'url': 'http://INSTANCE_URL',
'searchApiKey': 'INSTANCE_API_KEY'
},
'ms-01': {
'url': 'http://ANOTHER_INSTANCE_URL',
'searchApiKey': 'ANOTHER_INSTANCE_API_KEY'
}
}
)
1 change: 1 addition & 0 deletions lib/meilisearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'meilisearch/models/task'
require 'meilisearch/http_request'
require 'meilisearch/multi_search'
require 'meilisearch/network'
require 'meilisearch/tenant_token'
require 'meilisearch/task'
require 'meilisearch/client'
Expand Down
1 change: 1 addition & 0 deletions lib/meilisearch/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Meilisearch
class Client < HTTPRequest
include Meilisearch::TenantToken
include Meilisearch::MultiSearch
include Meilisearch::Network

### INDEXES

Expand Down
14 changes: 14 additions & 0 deletions lib/meilisearch/network.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Meilisearch
module Network
def network
http_get '/network'
end

def update_network(new_network)
new_network = Utils.transform_attributes(new_network)
http_patch '/network', new_network
end
end
end
1 change: 1 addition & 0 deletions lib/meilisearch/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def warn_on_non_conforming_attribute_names(body)

def parse(body)
body
.transform_values { |val| transform_attributes(val) }
.transform_keys(&:to_s)
.transform_keys do |key|
key.include?('_') ? key.downcase.gsub(SNAKE_CASE, &:upcase).gsub('_', '') : key
Expand Down
44 changes: 44 additions & 0 deletions spec/meilisearch/client/network_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

describe 'Meilisearch::Client - Network' do
before do
client.update_experimental_features(network: true)
end

let(:default_network) do
{
'self' => nil,
'remotes' => {}
}
end

let(:sample_remote) do
{
ms1: {
url: 'http://localhost',
search_api_key: 'masterKey'
}
}
end

describe '#network' do
it 'returns the sharding configuration' do
expect(client.network).to eq default_network
end
end

describe '#update_network' do
it 'updates the sharding configuration' do
new_network = {
self: 'ms0',
remotes: sample_remote
}

client.update_network(new_network)
expect(client.network).to eq(Meilisearch::Utils.transform_attributes(new_network))

client.update_network({ remotes: nil, self: nil })
expect(client.network).to eq default_network
end
end
end