Skip to content
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

Feature/Analytics #292

Merged
merged 1 commit into from
Jan 31, 2022
Merged
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
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