diff --git a/README.md b/README.md index 6efefc47..bb4b2a29 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ You can check out [the API documentation](https://docs.meilisearch.com/reference # Create an index client.create_index('books') # Create an index and give the primary-key -client.create_index(uid: 'books', primaryKey: 'book_id') +client.create_index('books', primaryKey: 'book_id') ``` #### List all indexes diff --git a/lib/meilisearch/client.rb b/lib/meilisearch/client.rb index ce977e6a..32ef9930 100644 --- a/lib/meilisearch/client.rb +++ b/lib/meilisearch/client.rb @@ -15,15 +15,10 @@ def show_index(index_uid) end # Usage: - # create_index('indexUID') - # create_index(uid: 'indexUID') - # create_index(uid: 'indexUID', primaryKey: 'id') - def create_index(attributes) - body = if attributes.is_a?(Hash) - attributes - else - { uid: attributes } - end + # client.create_index('indexUID') + # client.create_index('indexUID', primaryKey: 'id') + def create_index(index_uid, options = {}) + body = { uid: index_uid }.merge(options) res = http_post '/indexes', body index_object(res['uid']) end @@ -33,13 +28,11 @@ def delete_index(index_uid) end # Usage: - # index('indexUID') - # index(uid: 'indexUID') - def index(attribute) - uid = attribute.is_a?(Hash) ? attribute[:uid] : attribute - raise IndexUidError if uid.nil? + # client.index('indexUID') + def index(index_uid) + raise IndexUidError if index_uid.nil? - index_object(uid) + index_object(index_uid) end alias get_index index diff --git a/spec/meilisearch/client/indexes_spec.rb b/spec/meilisearch/client/indexes_spec.rb index c97696cf..38f11fd3 100644 --- a/spec/meilisearch/client/indexes_spec.rb +++ b/spec/meilisearch/client/indexes_spec.rb @@ -6,7 +6,6 @@ clear_all_indexes(@client) @uid1 = 'uid1' @uid2 = 'uid2' - @uid3 = 'uid3' @primary_key = 'objectId' end @@ -17,17 +16,10 @@ expect(index.primary_key).to be_nil end - it 'creates an index without primary-key as an Hash' do - index = @client.create_index(uid: @uid2) - expect(index).to be_a(MeiliSearch::Index) - expect(index.uid).to eq(@uid2) - expect(index.primary_key).to be_nil - end - it 'creates an index with primary-key' do - index = @client.create_index(uid: @uid3, primaryKey: @primary_key) + index = @client.create_index(@uid2, primaryKey: @primary_key) expect(index).to be_a(MeiliSearch::Index) - expect(index.uid).to eq(@uid3) + expect(index.uid).to eq(@uid2) expect(index.primary_key).to eq(@primary_key) end @@ -46,22 +38,22 @@ it 'gets list of indexes' do response = @client.indexes expect(response).to be_a(Array) - expect(response.count).to eq(3) + expect(response.count).to eq(2) uids = response.map { |elem| elem['uid'] } - expect(uids).to contain_exactly(@uid1, @uid2, @uid3) + expect(uids).to contain_exactly(@uid1, @uid2) end it 'shows a specific index' do - response = @client.show_index(@uid3) + response = @client.show_index(@uid2) expect(response).to be_a(Hash) - expect(response['uid']).to eq(@uid3) + expect(response['uid']).to eq(@uid2) expect(response['primaryKey']).to eq(@primary_key) end it 'returns an index object based on uid' do - index = @client.index(@uid3) + index = @client.index(@uid2) expect(index).to be_a(MeiliSearch::Index) - expect(index.uid).to eq(@uid3) + expect(index.uid).to eq(@uid2) expect(index.primary_key).to eq(@primary_key) end @@ -70,8 +62,6 @@ expect { @client.show_index(@uid1) }.to raise_meilisearch_http_error_with(404) expect(@client.delete_index(@uid2)).to be_nil expect { @client.show_index(@uid2) }.to raise_meilisearch_http_error_with(404) - expect(@client.delete_index(@uid3)).to be_nil - expect { @client.show_index(@uid3) }.to raise_meilisearch_http_error_with(404) expect(@client.indexes.count).to eq(0) end diff --git a/spec/meilisearch/index/base_spec.rb b/spec/meilisearch/index/base_spec.rb index c2784f5a..7cf9946a 100644 --- a/spec/meilisearch/index/base_spec.rb +++ b/spec/meilisearch/index/base_spec.rb @@ -8,7 +8,7 @@ client = MeiliSearch::Client.new($URL, $MASTER_KEY) clear_all_indexes(client) @index1 = client.create_index(@uid1) - @index2 = client.create_index(uid: @uid2, primaryKey: @primary_key) + @index2 = client.create_index(@uid2, primaryKey: @primary_key) end it 'shows the index' do diff --git a/spec/meilisearch/index/settings_spec.rb b/spec/meilisearch/index/settings_spec.rb index 80477c4e..3ee688b6 100644 --- a/spec/meilisearch/index/settings_spec.rb +++ b/spec/meilisearch/index/settings_spec.rb @@ -432,7 +432,7 @@ context 'Index with primary-key' do before(:all) do @uid = SecureRandom.hex(4) - @client.create_index(uid: @uid, primaryKey: 'id') + @client.create_index(@uid, primaryKey: 'id') end after(:all) { clear_all_indexes(@client) } diff --git a/spec/meilisearch/index/updates_spec.rb b/spec/meilisearch/index/updates_spec.rb index f26838c4..75c61edb 100644 --- a/spec/meilisearch/index/updates_spec.rb +++ b/spec/meilisearch/index/updates_spec.rb @@ -12,7 +12,7 @@ ] client = MeiliSearch::Client.new($URL, $MASTER_KEY) clear_all_indexes(client) - @index = client.create_index(uid: 'books', primaryKey: 'objectId') + @index = client.create_index('books', primaryKey: 'objectId') end after(:all) do