Skip to content

Commit 9290118

Browse files
meili-bors[bot]meili-botcurquiza
authored
Merge #273
273: Changes related to the next MeiliSearch release (v0.25.0) r=brunoocasali a=meili-bot Related to this issue: meilisearch/integration-guides#157 This PR: - gathers the changes related to the next MeiliSearch release (v0.25.0) so that this package is ready when the official release is out. - should pass the tests against the [latest pre-release of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases). - might eventually contain test failures until the MeiliSearch v0.25.0 is out. ⚠️ This PR should NOT be merged until the next release of MeiliSearch (v0.25.0) is out. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/master/guides/pre-release-week.md) purpose._ Co-authored-by: meili-bot <[email protected]> Co-authored-by: Clémentine Urquizar - curqui <[email protected]> Co-authored-by: Clémentine Urquizar <[email protected]>
2 parents cb54dcb + 175d2bf commit 9290118

24 files changed

+1070
-731
lines changed

.code-samples.meilisearch.yaml

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ delete_documents_1: |-
4343
client.index('movies').delete_documents([23488, 153738, 437035, 363869])
4444
search_post_1: |-
4545
client.index('movies').search('american ninja')
46-
get_update_1: |-
47-
client.index('movies').get_update_status(1)
48-
get_all_updates_1: |-
49-
client.index('movies').get_all_update_status
46+
get_task_by_index_1: |-
47+
client.index('movies').task(1)
48+
get_all_tasks_by_index_1: |-
49+
client.index('movies').tasks
50+
get_task_1: |-
51+
client.task(1)
52+
get_all_tasks_1: |-
53+
client.tasks
5054
get_keys_1: |-
5155
client.keys
5256
get_settings_1: |-
@@ -400,3 +404,55 @@ geosearch_guide_sort_usage_1: |-
400404
client.index('restaurants').search('', { sort: ['_geoPoint(48.8583701,2.2922926):asc'] })
401405
geosearch_guide_sort_usage_2: |-
402406
client.index('restaurants').search('', { sort: ['_geoPoint(48.8583701,2.2922926):asc', 'rating:desc'] })
407+
authorization_header_1: |-
408+
client = MeiliSearch::Client.new('http://127.0.0.1:7700', 'masterKey')
409+
client.keys
410+
get_one_key_1: |-
411+
client.key('d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4')
412+
get_all_keys_1: |-
413+
client.keys
414+
create_a_key_1: |-
415+
client.create_key(
416+
description: 'Add documents: Products API key',
417+
actions: ['documents.add'],
418+
indexes: ['products'],
419+
expires_at: '2042-04-02T00:42:42Z'
420+
)
421+
update_a_key_1: |-
422+
client.update_key(
423+
'd0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4',
424+
{
425+
description: 'Manage documents: Products/Reviews API key',
426+
actions: [
427+
'documents.add',
428+
'documents.delete'
429+
],
430+
indexes: [
431+
'products',
432+
'reviews'
433+
],
434+
expires_at: '2042-04-02T00:42:42Z'
435+
}
436+
)
437+
delete_a_key_1: |-
438+
client.delete_key('d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4')
439+
security_guide_search_key_1: |-
440+
client = MeiliSearch::Client.new('http://127.0.0.1:7700', 'apiKey')
441+
client.index('patient_medical_records').search
442+
security_guide_update_key_1: |-
443+
client = MeiliSearch::Client.new('http://127.0.0.1:7700', 'masterKey')
444+
client.update_key('d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4', indexes: ['doctors'])
445+
security_guide_create_key_1: |-
446+
client = MeiliSearch::Client.new('http://127.0.0.1:7700', 'masterKey')
447+
client.create_key(
448+
description: 'Search patient records key',
449+
actions: ['search'],
450+
indexes: ['patient_medical_records'],
451+
expires_at: '2023-01-01T00:00:00Z'
452+
)
453+
security_guide_list_keys_1: |-
454+
client = MeiliSearch::Client.new('http://127.0.0.1:7700', 'masterKey')
455+
client.keys
456+
security_guide_delete_key_1: |-
457+
client = MeiliSearch::Client.new('http://127.0.0.1:7700', 'masterKey')
458+
client.delete_key('d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4')

.rubocop_todo.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2021-11-21 21:31:55 UTC using RuboCop version 1.23.0.
3+
# on 2021-12-13 22:26:31 UTC using RuboCop version 1.23.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -20,23 +20,23 @@ Layout/HeredocIndentation:
2020
Exclude:
2121
- 'spec/meilisearch/index/documents_spec.rb'
2222

23-
# Offense count: 32
23+
# Offense count: 33
2424
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
2525
# IgnoredMethods: refine
2626
Metrics/BlockLength:
27-
Max: 512
27+
Max: 557
2828

2929
# Offense count: 1
3030
# Configuration parameters: CountComments, CountAsOne.
3131
Metrics/ClassLength:
32-
Max: 289
32+
Max: 278
3333

3434
# Offense count: 1
3535
# Configuration parameters: Max, CountKeywordArgs.
3636
Metrics/ParameterLists:
3737
MaxOptionalParameters: 4
3838

39-
# Offense count: 2
39+
# Offense count: 1
4040
Naming/AccessorMethodName:
4141
Exclude:
4242
- 'lib/meilisearch/index.rb'

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ documents = [
9292
{ id: 6, title: 'Philadelphia', genres: ['Drama'] },
9393
]
9494
# If the index 'movies' does not exist, MeiliSearch creates it when you first add the documents.
95-
index.add_documents(documents) # => { "updateId": 0 }
95+
index.add_documents(documents) # => { "uid": 0 }
9696
```
9797

98-
With the `updateId`, you can check the status (`enqueued`, `processing`, `processed` or `failed`) of your documents addition using the [update endpoint](https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status).
98+
With the `uid`, you can check the status (`enqueued`, `processing`, `succeeded` or `failed`) of your documents addition using the [task](https://docs.meilisearch.com/reference/api/tasks.html#get-task).
9999

100100
💡 To customize the `Client`, for example, increasing the default timeout, please check out [this section](https://github.com/meilisearch/meilisearch-ruby/wiki/Client-Options) of the Wiki.
101101

@@ -165,7 +165,7 @@ index.update_filterable_attributes([
165165

166166
You only need to perform this operation once.
167167

168-
Note that MeiliSearch will rebuild your index whenever you update `filterableAttributes`. Depending on the size of your dataset, this might take time. You can track the process using the [update status](https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status).
168+
Note that MeiliSearch will rebuild your index whenever you update `filterableAttributes`. Depending on the size of your dataset, this might take time. You can track the process using the [tasks](https://docs.meilisearch.com/reference/api/tasks.html#get-task)).
169169

170170
Then, you can perform the search:
171171

@@ -198,7 +198,7 @@ JSON output:
198198

199199
## 🤖 Compatibility with MeiliSearch
200200

201-
This package only guarantees the compatibility with the [version v0.24.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.24.0).
201+
This package only guarantees the compatibility with the [version v0.25.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.25.0).
202202

203203
## 💡 Learn More
204204

lib/meilisearch.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require 'meilisearch/version'
44
require 'meilisearch/utils'
5+
require 'meilisearch/task'
56
require 'meilisearch/client'
67
require 'meilisearch/index'
78

lib/meilisearch/client.rb

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,20 @@ def indexes
2222
def create_index(index_uid, options = {})
2323
body = Utils.transform_attributes(options.merge(uid: index_uid))
2424

25-
index_hash = http_post '/indexes', body
26-
index_object(index_hash['uid'], index_hash['primaryKey'])
25+
http_post '/indexes', body
2726
end
2827

29-
def get_or_create_index(index_uid, options = {})
30-
begin
31-
index_instance = fetch_index(index_uid)
32-
rescue ApiError => e
33-
raise e unless e.code == 'index_not_found'
34-
35-
index_instance = create_index(index_uid, options)
36-
end
37-
index_instance
28+
# Synchronous version of create_index.
29+
# Waits for the task to be achieved, be careful when using it.
30+
def create_index!(index_uid, options = {})
31+
task = create_index(index_uid, options)
32+
wait_for_task(task['uid'])
3833
end
3934

4035
def delete_index(index_uid)
4136
index_object(index_uid).delete
4237
end
4338

44-
# Usage:
45-
# client.delete_index_if_exists('indexUID')
46-
def delete_index_if_exists(index_uid)
47-
index_object(index_uid).delete
48-
true
49-
rescue ApiError => e
50-
raise e if e.code != 'index_not_found'
51-
52-
false
53-
end
54-
5539
# Usage:
5640
# client.index('indexUID')
5741
def index(index_uid)
@@ -71,7 +55,26 @@ def fetch_raw_index(index_uid)
7155
def keys
7256
http_get '/keys'
7357
end
74-
alias get_keys keys
58+
59+
def key(key_uid)
60+
http_get "/keys/#{key_uid}"
61+
end
62+
63+
def create_key(key_options)
64+
body = Utils.transform_attributes(key_options)
65+
66+
http_post '/keys', body
67+
end
68+
69+
def update_key(key_uid, key_options)
70+
body = Utils.transform_attributes(key_options)
71+
72+
http_patch "/keys/#{key_uid}", body
73+
end
74+
75+
def delete_key(key_uid)
76+
http_delete "/keys/#{key_uid}"
77+
end
7578

7679
### HEALTH
7780

@@ -107,10 +110,28 @@ def dump_status(dump_uid)
107110
end
108111
alias get_dump_status dump_status
109112

113+
### TASKS
114+
115+
def tasks
116+
task_endpoint.task_list
117+
end
118+
119+
def task(task_uid)
120+
task_endpoint.task(task_uid)
121+
end
122+
123+
def wait_for_task(task_uid, timeout_in_ms = 5000, interval_in_ms = 50)
124+
task_endpoint.wait_for_task(task_uid, timeout_in_ms, interval_in_ms)
125+
end
126+
110127
private
111128

112129
def index_object(uid, primary_key = nil)
113130
Index.new(uid, @base_url, @api_key, primary_key, @options)
114131
end
132+
133+
def task_endpoint
134+
@task_endpoint ||= Task.new(@base_url, @api_key, @options)
135+
end
115136
end
116137
end

lib/meilisearch/http_request.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ def http_put(relative_path = '', body = nil, query_params = nil)
4949
)
5050
end
5151

52+
def http_patch(relative_path = '', body = nil, query_params = nil)
53+
send_request(
54+
proc { |path, config| self.class.patch(path, config) },
55+
relative_path,
56+
query_params: query_params,
57+
body: body,
58+
options: @options
59+
)
60+
end
61+
5262
def http_delete(relative_path = '')
5363
send_request(
5464
proc { |path, config| self.class.delete(path, config) },
@@ -60,10 +70,11 @@ def http_delete(relative_path = '')
6070
private
6171

6272
def build_default_options_headers(api_key = nil)
63-
{
64-
'Content-Type' => 'application/json',
65-
'X-Meili-API-Key' => api_key
66-
}.compact
73+
header = {
74+
'Content-Type' => 'application/json'
75+
}
76+
header = header.merge('Authorization' => "Bearer #{api_key}") unless api_key.nil?
77+
header
6778
end
6879

6980
def merge_options(default_options, added_options = {})

0 commit comments

Comments
 (0)