Skip to content

Commit

Permalink
Try #292:
Browse files Browse the repository at this point in the history
  • Loading branch information
meili-bors[bot] authored Jan 31, 2022
2 parents 719901d + 8154e1f commit ec37f67
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/meilisearch/http_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def http_delete(relative_path = '')
def build_default_options_headers
{
'Content-Type' => 'application/json',
'Authorization' => ("Bearer #{@api_key}" unless @api_key.nil?)
'Authorization' => ("Bearer #{@api_key}" unless @api_key.nil?),
'User-Agent' => MeiliSearch.qualified_version
}.compact
end

Expand Down
4 changes: 4 additions & 0 deletions lib/meilisearch/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

module MeiliSearch
VERSION = '0.18.0'

def self.qualified_version
"Meilisearch Ruby (v#{VERSION})"
end
end
3 changes: 2 additions & 1 deletion spec/meilisearch/index/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
it 'supports options' do
options = { timeout: 2, max_retries: 1 }
expected_headers = {
'Authorization' => "Bearer #{MASTER_KEY}"
'Authorization' => "Bearer #{MASTER_KEY}",
'User-Agent' => MeiliSearch.qualified_version
}

new_client = MeiliSearch::Client.new(URL, MASTER_KEY, options)
Expand Down
11 changes: 11 additions & 0 deletions spec/meilisearch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
expect(MeiliSearch::VERSION).not_to be nil
end

it 'has a qualified version number' do
expect(MeiliSearch.qualified_version).to eq("Meilisearch Ruby (v#{MeiliSearch::VERSION})")
end

it 'raises an exception when it is impossible to connect' do
new_client = MeiliSearch::Client.new('http://127.0.0.1:8800', 'masterKey')
expect do
Expand All @@ -24,4 +28,11 @@
new_client.indexes
end.to raise_error(Timeout::Error)
end

it 'has a pre-defined header with current version' do
new_client = MeiliSearch::Client.new(URL, MASTER_KEY)

expect(new_client.headers).to have_key('User-Agent')
expect(new_client.headers['User-Agent']).to eq(MeiliSearch.qualified_version)
end
end

0 comments on commit ec37f67

Please sign in to comment.