Skip to content

Commit c2b3e0d

Browse files
Fix Httparty options (#188)
* Take the christianhellsten commit Co-authored-by: Christian Hellsten <[email protected]> * Fix test Co-authored-by: Christian Hellsten <[email protected]>
1 parent 97d1921 commit c2b3e0d

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

lib/meilisearch/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def dump_status(dump_uid)
8888
private
8989

9090
def index_object(uid, primary_key = nil)
91-
Index.new(uid, @base_url, @api_key, primary_key)
91+
Index.new(uid, @base_url, @api_key, primary_key, @options)
9292
end
9393
end
9494
end

lib/meilisearch/http_request.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module MeiliSearch
77
class HTTPRequest
88
include HTTParty
99

10+
attr_reader :options
11+
1012
def initialize(url, api_key = nil, options = {})
1113
@base_url = url
1214
@api_key = api_key

lib/meilisearch/index.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ module MeiliSearch
77
class Index < HTTPRequest
88
attr_reader :uid, :primary_key
99

10-
def initialize(index_uid, url, api_key = nil, primary_key = nil)
10+
def initialize(index_uid, url, api_key = nil, primary_key = nil, options = {})
1111
@uid = index_uid
1212
@primary_key = primary_key
13-
super(url, api_key)
13+
super(url, api_key, options)
1414
end
1515

1616
def fetch_info

spec/meilisearch/index/base_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@
5252
)
5353
end
5454

55+
it 'supports options' do
56+
options = { timeout: 2, max_retries: 1 }
57+
client = MeiliSearch::Client.new($URL, $MASTER_KEY, options)
58+
index_uid = 'options'
59+
index = client.create_index(index_uid)
60+
expect(index.options).to eq({ timeout: 2, max_retries: 1 })
61+
expect(MeiliSearch::Index).to receive(:get).with(
62+
"#{$URL}/indexes/#{index_uid}",
63+
{
64+
headers: { 'Content-Type' => 'application/json', 'X-Meili-API-Key' => $MASTER_KEY },
65+
body: 'null',
66+
query: {},
67+
max_retries: 1,
68+
timeout: 2
69+
}
70+
).and_return(double(success?: true, parsed_response: ''))
71+
index.fetch_info
72+
end
73+
5574
it 'deletes index' do
5675
expect(@index1.delete).to be_nil
5776
expect { @index1.fetch_info }.to raise_index_not_found_meilisearch_api_error

0 commit comments

Comments
 (0)