Skip to content

Commit

Permalink
Merge #354
Browse files Browse the repository at this point in the history
354: Support custom agents r=brunoocasali a=brunoocasali

Related to meilisearch/integration-guides#150 take #2

We will use this door to send information from the Rails gem.

Co-authored-by: Bruno Casali <brunoocasali@gmail.com>
  • Loading branch information
meili-bors[bot] and brunoocasali authored Aug 1, 2022
2 parents 606f684 + e19ccc5 commit 6860f67
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/meilisearch/http_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ def build_default_options_headers
{
'Content-Type' => 'application/json',
'Authorization' => ("Bearer #{@api_key}" unless @api_key.nil?),
'User-Agent' => MeiliSearch.qualified_version
'User-Agent' => [
@options.fetch(:client_agents, []),
MeiliSearch.qualified_version
].flatten.join(';')
}.compact
end

Expand Down
28 changes: 28 additions & 0 deletions spec/meilisearch/index/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,34 @@
index.fetch_info
end

it 'supports client_agents' do
custom_agent = 'Meilisearch Rails (v0.0.1)'
options = { timeout: 2, max_retries: 1, client_agents: [custom_agent] }
expected_headers = {
'Authorization' => "Bearer #{MASTER_KEY}",
'User-Agent' => "#{custom_agent};#{MeiliSearch.qualified_version}"
}

new_client = MeiliSearch::Client.new(URL, MASTER_KEY, options)
new_client.create_index!('options')
index = new_client.fetch_index('options')
expect(index.options).to eq(options.merge({ convert_body?: true }))

expect(MeiliSearch::Index).to receive(:get).with(
"#{URL}/indexes/options",
{
headers: expected_headers,
body: 'null',
query: {},
max_retries: 1,
timeout: 2
}
).and_return(double(success?: true,
parsed_response: { 'createdAt' => '2021-10-16T14:57:35Z',
'updatedAt' => '2021-10-16T14:57:35Z' }))
index.fetch_info
end

it 'deletes index' do
client.create_index!('uid')

Expand Down

0 comments on commit 6860f67

Please sign in to comment.