algoliasearch 1.22.0 → 1.23.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 431002a3ec233966b7b7a0507662292938fd09cdbb62d1279d538d2da761ee6f
4
- data.tar.gz: 6988bad4c248073ceee35d8ff9c447aeeb97c873e73b1ac41b4ab9b65099fd8c
3
+ metadata.gz: 7aec9582dfb81fdce4070cf4c30819075b2bc14e92ca1fa8574877533491904e
4
+ data.tar.gz: bf648a4405d74d8d9ef94cd2f52566d1ad77ce65ef2012c766649c60de94cafa
5
5
  SHA512:
6
- metadata.gz: 6bdc28f6b84c96088f0cddf1f071c68994291d5365a612b771426052b327bad8ff11b47682bc9fe150f6128c2144e699632c6c606fd08d836a7da889824a61b7
7
- data.tar.gz: 1af3a1305da6856ccd56caaeeee126170205d244ba3a0026c50308d250f31e899609f1aab36b33a4970e6eec41f25b5014e9aea9c079e622576fb83b644997a6
6
+ metadata.gz: c286583acd9d232476d6017c883dc93a193e327bceca68672718b224604fbb436ca832c4a9094def62a65e2a610d40ced96b165b383676707cde61d69b315cc7
7
+ data.tar.gz: 96f3ad4b2f8eadd48b5c080d18e39427b4782c583fdc6c027132ee6352ab521ae3fad83acb562ac22f2c05a31a205199579308651465e5ed582f0f73c573f799
data/.travis.yml CHANGED
@@ -7,12 +7,12 @@ branches:
7
7
  rvm:
8
8
  - 1.8.7
9
9
  - 1.9.3
10
- - 2.0.0
11
- - 2.1.10
12
- - 2.2.5
13
- - 2.3.4
14
- - 2.4.1
15
- - 2.5.0
10
+ - 2.0
11
+ - 2.1
12
+ - 2.2
13
+ - 2.3
14
+ - 2.4
15
+ - 2.5
16
16
  - jruby
17
17
  - rbx-3
18
18
 
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.23.0](https://github.com/algolia/algoliasearch-client-ruby/releases/tag/1.23.0) (2018-06-19)
2
+
3
+ * Feat(analytics): introduce new analytics class
4
+ * Chore(rake): use unshift to keep compat with older ruby versions
5
+ * Ruby version must be after client version in ua
6
+ * Fix ua tests with new format
7
+ * Rewrite ua
8
+ * Feat(ua): add ruby version
9
+ * Fix(syntax): this isn't php
10
+ * Tests(mcm): use unique userid everytime
11
+ * Tests(mcm): introduce auto_retry for more stable tests
12
+ * Feat(client): expose waittask in the client (#302)
13
+ * Fix(travis): always test on the latest patches (#295)
14
+
1
15
  ## [1.22.0](https://github.com/algolia/algoliasearch-client-ruby/releases/tag/1.22.0) (2018-05-30)
2
16
 
3
17
  * Rename license file (#297)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- algoliasearch (1.22.0)
4
+ algoliasearch (1.23.0)
5
5
  httpclient (~> 2.8, >= 2.8.3)
6
6
  json (>= 1.5.1)
7
7
 
data/README.md CHANGED
@@ -90,7 +90,7 @@ index.add_objects(batch)
90
90
  Settings can be customized to fine tune the search behavior. For example, you can add a custom sort by number of followers to further enhance the built-in relevance:
91
91
 
92
92
  ```ruby
93
- index.set_settings customRanking: ['desc(followers)']
93
+ index.set_settings(customRanking: ['desc(followers)'])
94
94
  ```
95
95
 
96
96
  You can also configure the list of attributes you want to index by order of importance (most important first).
@@ -287,6 +287,17 @@ search.start();
287
287
 
288
288
 
289
289
 
290
+ ### A/B Test
291
+
292
+ - [Add an A/B test](https://algolia.com/doc/api-reference/api-methods/add-ab-test/?language=ruby)
293
+ - [Get an A/B test](https://algolia.com/doc/api-reference/api-methods/get-ab-test/?language=ruby)
294
+ - [List A/B tests](https://algolia.com/doc/api-reference/api-methods/get-ab-tests/?language=ruby)
295
+ - [Stop an A/B test](https://algolia.com/doc/api-reference/api-methods/stop-ab-test/?language=ruby)
296
+ - [Delete an A/B test](https://algolia.com/doc/api-reference/api-methods/delete-ab-test/?language=ruby)
297
+
298
+
299
+
300
+
290
301
  ### MultiClusters
291
302
 
292
303
  - [Assign or Move userID](https://algolia.com/doc/api-reference/api-methods/assign-user-id/?language=ruby)
data/Rakefile CHANGED
@@ -57,7 +57,7 @@ namespace :algolia do
57
57
  title = "## [%s](%s%s) (%s)\n\n" % [args[:version], GIT_TAG_URL, args[:version], last_commit_date]
58
58
  changes = changelog.each_line
59
59
  .map { |line| (exceptions_regexp === line) ? nil : "* #{line.capitalize}" }
60
- .prepend(title)
60
+ .unshift(title)
61
61
  .append("\n\n")
62
62
  .join
63
63
 
@@ -21,6 +21,7 @@ module Algolia
21
21
  DEFAULT_SEND_TIMEOUT = 30
22
22
  DEFAULT_BATCH_TIMEOUT = 120
23
23
  DEFAULT_SEARCH_TIMEOUT = 5
24
+ DEFAULT_USER_AGENT = ["Algolia for Ruby (#{::Algolia::VERSION})", "Ruby (#{RUBY_VERSION})"]
24
25
 
25
26
  def initialize(data = {})
26
27
  raise ArgumentError.new('No APPLICATION_ID provided, please set :application_id') if data[:application_id].nil?
@@ -41,7 +42,7 @@ module Algolia
41
42
  Protocol::HEADER_API_KEY => api_key,
42
43
  Protocol::HEADER_APP_ID => application_id,
43
44
  'Content-Type' => 'application/json; charset=utf-8',
44
- 'User-Agent' => (data[:user_agent] || "Algolia for Ruby #{::Algolia::VERSION}")
45
+ 'User-Agent' => DEFAULT_USER_AGENT.push(data[:user_agent]).compact.join('; ')
45
46
  }
46
47
  end
47
48
 
@@ -59,6 +60,13 @@ module Algolia
59
60
  Index.new(name, self)
60
61
  end
61
62
 
63
+ #
64
+ # Initialize analytics helper
65
+ #
66
+ def init_analytics()
67
+ Analytics.new(self, { :headers => @headers })
68
+ end
69
+
62
70
  #
63
71
  # Allow to set custom headers
64
72
  #
@@ -155,7 +163,7 @@ module Algolia
155
163
  # @param request_options contains extra parameters to send with your query
156
164
  #
157
165
  def move_index(src_index, dst_index, request_options = {})
158
- request = { 'operation' => 'move', 'destination' => dst_index };
166
+ request = { 'operation' => 'move', 'destination' => dst_index }
159
167
  post(Protocol.index_operation_uri(src_index), request.to_json, :write, request_options)
160
168
  end
161
169
 
@@ -168,7 +176,7 @@ module Algolia
168
176
  #
169
177
  def move_index!(src_index, dst_index, request_options = {})
170
178
  res = move_index(src_index, dst_index, request_options)
171
- init_index(dst_index).wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
179
+ wait_task(dst_index, res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
172
180
  res
173
181
  end
174
182
 
@@ -181,7 +189,7 @@ module Algolia
181
189
  # @param request_options contains extra parameters to send with your query
182
190
  #
183
191
  def copy_index(src_index, dst_index, scope = nil, request_options = {})
184
- request = { 'operation' => 'copy', 'destination' => dst_index };
192
+ request = { 'operation' => 'copy', 'destination' => dst_index }
185
193
  request['scope'] = scope unless scope.nil?
186
194
  post(Protocol.index_operation_uri(src_index), request.to_json, :write, request_options)
187
195
  end
@@ -196,7 +204,7 @@ module Algolia
196
204
  #
197
205
  def copy_index!(src_index, dst_index, scope = nil, request_options = {})
198
206
  res = copy_index(src_index, dst_index, scope, request_options)
199
- init_index(dst_index).wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
207
+ wait_task(dst_index, res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
200
208
  res
201
209
  end
202
210
 
@@ -376,7 +384,38 @@ module Algolia
376
384
  def batch!(operations, request_options = {})
377
385
  res = batch(operations, request_options)
378
386
  res['taskID'].each do |index, taskID|
379
- init_index(index).wait_task(taskID, WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
387
+ wait_task(index, taskID, WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
388
+ end
389
+ end
390
+
391
+ #
392
+ # Check the status of a task on the server.
393
+ # All server task are asynchronous and you can check the status of a task with this method.
394
+ #
395
+ # @param index_name the index name owning the taskID
396
+ # @param taskID the id of the task returned by server
397
+ # @param request_options contains extra parameters to send with your query
398
+ #
399
+ def get_task_status(index_name, taskID, request_options = {})
400
+ get(Protocol.task_uri(index_name, taskID), :read, request_options)['status']
401
+ end
402
+
403
+ #
404
+ # Wait the publication of a task on the server.
405
+ # All server task are asynchronous and you can check with this method that the task is published.
406
+ #
407
+ # @param index_name the index name owning the taskID
408
+ # @param taskID the id of the task returned by server
409
+ # @param time_before_retry the time in milliseconds before retry (default = 100ms)
410
+ # @param request_options contains extra parameters to send with your query
411
+ #
412
+ def wait_task(index_name, taskID, time_before_retry = WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options = {})
413
+ loop do
414
+ status = get_task_status(index_name, taskID, request_options)
415
+ if status == 'published'
416
+ return
417
+ end
418
+ sleep(time_before_retry.to_f / 1000)
380
419
  end
381
420
  end
382
421
 
@@ -861,6 +900,16 @@ module Algolia
861
900
  Algolia.client.batch!(requests, request_options)
862
901
  end
863
902
 
903
+ #
904
+ # Wait until task is completed by the engine
905
+ #
906
+ def Algolia.wait_task(index_name, taskID, time_before_retry = WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options = {})
907
+ Algolia.client.wait_task(index_name, taskID, time_before_retry, request_options)
908
+ end
909
+
910
+ def Algolia.get_task_status(index_name, taskID, request_options = {})
911
+ Algolia.client.get_task_status(index_name, taskID, request_options = {})
912
+ end
864
913
  #
865
914
  # Used mostly for testing. Lets you delete the api key global vars.
866
915
  #
data/lib/algolia/index.rb CHANGED
@@ -272,7 +272,7 @@ module Algolia
272
272
  # @param request_options contains extra parameters to send with your query
273
273
  #
274
274
  def get_task_status(taskID, request_options = {})
275
- client.get(Protocol.task_uri(name, taskID), :read, request_options)['status']
275
+ client.get_task_status(name, taskID, request_options)
276
276
  end
277
277
 
278
278
  #
@@ -284,13 +284,7 @@ module Algolia
284
284
  # @param request_options contains extra parameters to send with your query
285
285
  #
286
286
  def wait_task(taskID, time_before_retry = WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options = {})
287
- loop do
288
- status = get_task_status(taskID, request_options)
289
- if status == 'published'
290
- return
291
- end
292
- sleep(time_before_retry.to_f / 1000)
293
- end
287
+ client.wait_task(name, taskID, time_before_retry, request_options)
294
288
  end
295
289
 
296
290
  #
@@ -189,5 +189,15 @@ module Algolia
189
189
  "/#{VERSION}/clusters/mapping/search"
190
190
  end
191
191
 
192
+ def Protocol.ab_tests_uri(ab_test = nil)
193
+ ab_test = "/#{ab_test}" if ab_test
194
+
195
+ "/2/abtests" + ab_test.to_s
196
+ end
197
+
198
+ def Protocol.ab_tests_stop_uri(ab_test)
199
+ "/2/abtests/#{ab_test}/stop"
200
+ end
201
+
192
202
  end
193
203
  end
@@ -1,3 +1,3 @@
1
1
  module Algolia
2
- VERSION = "1.22.0"
2
+ VERSION = "1.23.0"
3
3
  end
data/lib/algoliasearch.rb CHANGED
@@ -21,3 +21,4 @@ cwd = Pathname(__FILE__).dirname
21
21
  $:.unshift(cwd.to_s) unless $:.include?(cwd.to_s) || $:.include?(cwd.expand_path.to_s)
22
22
 
23
23
  require 'algolia/index'
24
+ require 'algolia/analytics'
data/spec/client_spec.rb CHANGED
@@ -2,13 +2,6 @@
2
2
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
3
3
  require 'base64'
4
4
 
5
- # avoid concurrent access to the same index
6
- def safe_index_name(name)
7
- return name if ENV['TRAVIS'].to_s != "true"
8
- id = ENV['TRAVIS_JOB_NUMBER']
9
- "TRAVIS_RUBY_#{name}-#{id}"
10
- end
11
-
12
5
  def is_include(array, attr, value)
13
6
  array.each do |elt|
14
7
  if elt[attr] == value
@@ -311,7 +304,7 @@ describe 'Client' do
311
304
  res = Algolia.list_indexes
312
305
  is_include(res['items'], 'name', safe_index_name('àlgol?a')).should eq(false)
313
306
  index.add_object!({ :name => "Robert" })
314
- resAfter = Algolia.list_indexes;
307
+ resAfter = Algolia.list_indexes
315
308
  is_include(resAfter['items'], 'name', safe_index_name('àlgol?a')).should eq(true)
316
309
  end
317
310
 
@@ -1160,8 +1153,11 @@ describe 'Client' do
1160
1153
  end
1161
1154
 
1162
1155
  before(:each) do
1163
- @client = Algolia::Client.new :application_id => ENV['ALGOLIA_APPLICATION_ID'], :api_key => ENV['ALGOLIA_API_KEY'],
1156
+ @client = Algolia::Client.new(
1157
+ :application_id => ENV['ALGOLIA_APPLICATION_ID'],
1158
+ :api_key => ENV['ALGOLIA_API_KEY'],
1164
1159
  :user_agent => 'test agent'
1160
+ )
1165
1161
  @client.destroy # make sure the thread-local vars are reseted
1166
1162
  end
1167
1163
 
@@ -1170,7 +1166,7 @@ describe 'Client' do
1170
1166
  to_return(:status => 200, :body => '{}')
1171
1167
  @client.list_indexes
1172
1168
  expect(WebMock).to have_requested(:get, /https:\/\/.+-dsn.algolia(net\.com|\.net)\/1\/indexes/).
1173
- with(:headers => {'User-Agent' => 'test agent'})
1169
+ with(:headers => { 'User-Agent' => "Algolia for Ruby (#{::Algolia::VERSION}); Ruby (#{RUBY_VERSION}); test agent" })
1174
1170
  end
1175
1171
 
1176
1172
  after(:all) do
data/spec/spec_helper.rb CHANGED
@@ -20,6 +20,7 @@ require 'algoliasearch'
20
20
  require 'rspec'
21
21
  require 'webmock/rspec'
22
22
  require 'algolia/webmock'
23
+ require 'time'
23
24
 
24
25
  raise 'missing ALGOLIA_APPLICATION_ID or ALGOLIA_API_KEY environment variables' if ENV['ALGOLIA_APPLICATION_ID'].nil? || ENV['ALGOLIA_API_KEY'].nil?
25
26
  Algolia.init :application_id => ENV['ALGOLIA_APPLICATION_ID'], :api_key => ENV['ALGOLIA_API_KEY']
@@ -35,3 +36,30 @@ RSpec.configure do |config|
35
36
  WebMock.disable!
36
37
  end
37
38
  end
39
+
40
+ # avoid concurrent access to the same index
41
+ def safe_index_name(name)
42
+ return name if ENV['TRAVIS'].to_s != "true"
43
+ id = ENV['TRAVIS_JOB_NUMBER']
44
+ "TRAVIS_RUBY_#{name}-#{id}"
45
+ end
46
+
47
+ def auto_retry(options = {})
48
+ return if !block_given?
49
+
50
+ max_retry = options[:max_retry] || 10
51
+ retry_count = 0
52
+
53
+ loop do
54
+ begin
55
+ return yield
56
+ rescue => e
57
+ retry_count += 1
58
+ if retry_count >= max_retry
59
+ raise e
60
+ else
61
+ sleep retry_count
62
+ end
63
+ end
64
+ end
65
+ end
data/spec/stub_spec.rb CHANGED
@@ -16,7 +16,7 @@ describe 'With a rate limited client' do
16
16
 
17
17
  it "should pass the right headers" do
18
18
  WebMock.stub_request(:post, %r{https://.*\.algolia\.(io|net)/1/indexes/friends/query}).
19
- with(:headers => {'Content-Type'=>'application/json; charset=utf-8', 'User-Agent'=>"Algolia for Ruby #{Algolia::VERSION}", 'X-Algolia-Api-Key'=>ENV['ALGOLIA_API_KEY'], 'X-Algolia-Application-Id'=>ENV['ALGOLIA_APPLICATION_ID'], 'X-Forwarded-Api-Key'=>'ratelimitapikey', 'X-Forwarded-For'=>'1.2.3.4'}).
19
+ with(:headers => {'Content-Type'=>'application/json; charset=utf-8', 'User-Agent'=>"Algolia for Ruby (#{Algolia::VERSION}); Ruby (#{RUBY_VERSION})", 'X-Algolia-Api-Key'=>ENV['ALGOLIA_API_KEY'], 'X-Algolia-Application-Id'=>ENV['ALGOLIA_APPLICATION_ID'], 'X-Forwarded-Api-Key'=>'ratelimitapikey', 'X-Forwarded-For'=>'1.2.3.4'}).
20
20
  to_return(:status => 200, :body => "{ \"hits\": [], \"fakeAttribute\": 1 }", :headers => {})
21
21
  Algolia.enable_rate_limit_forward ENV['ALGOLIA_API_KEY'], "1.2.3.4", "ratelimitapikey"
22
22
  index = Algolia::Index.new("friends")
@@ -26,8 +26,8 @@ describe 'With a rate limited client' do
26
26
 
27
27
  it "should use original headers" do
28
28
  WebMock.stub_request(:post, %r{https://.*\.algolia\.(io|net)/1/indexes/friends/query}).
29
- with(:headers => {'Content-Type'=>'application/json; charset=utf-8', 'User-Agent'=>"Algolia for Ruby #{Algolia::VERSION}", 'X-Algolia-Api-Key'=>ENV['ALGOLIA_API_KEY'], 'X-Algolia-Application-Id'=>ENV['ALGOLIA_APPLICATION_ID'] }).
30
- to_return(:status => 200, :body => "{ \"hits\": [], \"fakeAttribute\": 2 }", :headers => {})
29
+ with(:headers => {'Content-Type'=>'application/json; charset=utf-8', 'User-Agent'=>"Algolia for Ruby (#{Algolia::VERSION}); Ruby (#{RUBY_VERSION})", 'X-Algolia-Api-Key'=>ENV['ALGOLIA_API_KEY'], 'X-Algolia-Application-Id'=>ENV['ALGOLIA_APPLICATION_ID'] }).
30
+ to_return(:status => 200, :body => "{ \"hits\": [], \"fakeAttribute\": 2 }", :headers => {})
31
31
  Algolia.disable_rate_limit_forward
32
32
  index = Algolia::Index.new("friends")
33
33
  index.search('bar')['fakeAttribute'].should == 2
@@ -35,7 +35,7 @@ describe 'With a rate limited client' do
35
35
 
36
36
  it "should pass the right headers in the scope" do
37
37
  WebMock.stub_request(:post, %r{https://.*\.algolia\.(io|net)/1/indexes/friends/query}).
38
- with(:headers => {'Content-Type'=>'application/json; charset=utf-8', 'User-Agent'=>"Algolia for Ruby #{Algolia::VERSION}", 'X-Algolia-Api-Key'=>ENV['ALGOLIA_API_KEY'], 'X-Algolia-Application-Id'=>ENV['ALGOLIA_APPLICATION_ID'], 'X-Forwarded-Api-Key'=>'ratelimitapikey', 'X-Forwarded-For'=>'1.2.3.4'}).
38
+ with(:headers => {'Content-Type'=>'application/json; charset=utf-8', 'User-Agent'=>"Algolia for Ruby (#{Algolia::VERSION}); Ruby (#{RUBY_VERSION})", 'X-Algolia-Api-Key'=>ENV['ALGOLIA_API_KEY'], 'X-Algolia-Application-Id'=>ENV['ALGOLIA_APPLICATION_ID'], 'X-Forwarded-Api-Key'=>'ratelimitapikey', 'X-Forwarded-For'=>'1.2.3.4'}).
39
39
  to_return(:status => 200, :body => "{ \"hits\": [], \"fakeAttribute\": 1 }", :headers => {})
40
40
  Algolia.with_rate_limits "1.2.3.4", "ratelimitapikey" do
41
41
  index = Algolia::Index.new("friends")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algoliasearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.22.0
4
+ version: 1.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-30 00:00:00.000000000 Z
11
+ date: 2018-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient