algolia 2.2.0 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 799e36b37cca18189b15d27f6b755904ef5c9707906258cfc3af51691a9af3a6
4
- data.tar.gz: a4235ea4599c928ac96eb9fc1243b8ccb915d2636d30282ff20d792bc7b1b174
3
+ metadata.gz: c113b61e6f68cb0512af5184ec64500c3dfcce89cef1f72fa07c25c9276f5cb1
4
+ data.tar.gz: 6474ee0b14ce28607a2a17bb2353fd7853128d48694f93d608b7faae728044b8
5
5
  SHA512:
6
- metadata.gz: bff81541d4dd4392598eb229ee5e854e352988daa7af4892c07e94cd8574b0dab02e1d0a54aba710370775f521ef0338399a5c7876659b2be75d21e083eb4bfc
7
- data.tar.gz: 6549f6d062a2cecbe6521d7961563917d0a9ea9d660991f644ae00b0ef7772557eae5c416efd633544d81cac3d16a94ed5ba3633297710d553a571c85d746da7
6
+ metadata.gz: efab3e1d53bb186dc091e69e00962223adb1f7c17567e0fbcd97609ed07fc6cb99ae6552e08852f19c3815bd1164fde3475fc74f2445b8c4909f4de5258ee405
7
+ data.tar.gz: 7c961f777ab5616edd3c59c0049ffd5b2b74126cd79697ebcdb4ffee42822866cab8fae0ab7a8922c434479fb032d9d865e83ba7b46543dd7a6b32a013d555ff
data/CHANGELOG.md CHANGED
@@ -1,6 +1,22 @@
1
1
  # ChangeLog
2
2
 
3
- ## [Unreleased](https://github.com/algolia/algoliasearch-client-ruby/compare/2.2.0..master)
3
+ ## [Unreleased](https://github.com/algolia/algoliasearch-client-ruby/compare/2.2.3..master)
4
+
5
+ ## [2.2.3](https://github.com/algolia/algoliasearch-client-ruby/compare/2.2.2...2.2.3) (2022-04-21)
6
+ ### Fixed
7
+ - API polling flood issue due to msec sleep time mishandling ([`#472`](https://github.com/algolia/algoliasearch-client-ruby/pull/472))
8
+ - mailto link in SECURITY.md ([`#463`](https://github.com/algolia/algoliasearch-client-ruby/pull/463))
9
+
10
+ ### Added
11
+ - allow hash in multiple queries ([`#468`](https://github.com/algolia/algoliasearch-client-ruby/pull/468))
12
+
13
+ ## [2.2.2](https://github.com/algolia/algoliasearch-client-ruby/compare/2.2.1...2.2.2) (2021-12-08)
14
+ ### Fixed
15
+ - Added a `status` field to the `MockRequester` ([`#467`](https://github.com/algolia/algoliasearch-client-ruby/pull/467))
16
+
17
+ ## [2.2.1](https://github.com/algolia/algoliasearch-client-ruby/compare/2.2.0...2.2.1) (2021-11-12)
18
+ ### Chore
19
+ - Deprecated `RecommendationClient` in favor of `PersonalizationClient` ([`#461`](https://github.com/algolia/algoliasearch-client-ruby/pull/461))
4
20
 
5
21
  ## [2.2.0](https://github.com/algolia/algoliasearch-client-ruby/compare/2.1.1...2.2.0) (2021-11-08)
6
22
  ### Added
data/SECURITY.md CHANGED
@@ -1,3 +1,3 @@
1
1
  ## Reporting a Vulnerability
2
2
 
3
- To report a security vulnerability, please use the [Algolia security email](security@algolia.com). Algolia will coordinate the fix and disclosure.
3
+ To report a security vulnerability, please use the [Algolia security email](mailto:security@algolia.com). Algolia will coordinate the fix and disclosure.
@@ -0,0 +1,20 @@
1
+ module Algolia
2
+ module Personalization
3
+ class Config < BaseConfig
4
+ attr_accessor :region, :default_hosts
5
+
6
+ # Initialize a config
7
+ #
8
+ # @option options [String] :application_id
9
+ # @option options [String] :api_key
10
+ # @option options [String] :region
11
+ #
12
+ def initialize(opts = {})
13
+ super(opts)
14
+
15
+ @region = opts[:region] || 'us'
16
+ @default_hosts = [Transport::StatefulHost.new("personalization.#{region}.algolia.com")]
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,20 +1,7 @@
1
1
  module Algolia
2
2
  module Recommendation
3
- class Config < BaseConfig
4
- attr_accessor :region, :default_hosts
5
-
6
- # Initialize a config
7
- #
8
- # @option options [String] :application_id
9
- # @option options [String] :api_key
10
- # @option options [String] :region
11
- #
12
- def initialize(opts = {})
13
- super(opts)
14
-
15
- @region = opts[:region] || 'us'
16
- @default_hosts = [Transport::StatefulHost.new("recommendation.#{region}.algolia.com")]
17
- end
3
+ # <b>DEPRECATED:</b> Please use <tt>Algolia::Personalization::Config</tt> instead.
4
+ class Config < Algolia::Personalization::Config
18
5
  end
19
6
  end
20
7
  end
@@ -0,0 +1,60 @@
1
+ module Algolia
2
+ module Personalization
3
+ class Client
4
+ # Initializes the Personalization client
5
+ #
6
+ # @param personalization_config [Personalization::Config] a Personalization::Config object which contains your APP_ID and API_KEY
7
+ # @option adapter [Object] adapter object used for the connection
8
+ # @option logger [Object]
9
+ # @option http_requester [Object] http_requester object used for the connection
10
+ #
11
+ def initialize(personalization_config, opts = {})
12
+ @config = personalization_config
13
+ adapter = opts[:adapter] || Defaults::ADAPTER
14
+ logger = opts[:logger] || LoggerHelper.create('debug.log')
15
+ requester = opts[:http_requester] || Defaults::REQUESTER_CLASS.new(adapter, logger)
16
+ @transporter = Transport::Transport.new(@config, requester)
17
+ end
18
+
19
+ # Create a new client providing only app ID and API key
20
+ #
21
+ # @param app_id [String] Algolia application ID
22
+ # @param api_key [String] Algolia API key
23
+ #
24
+ # @return self
25
+ #
26
+ def self.create(app_id, api_key)
27
+ config = Personalization::Config.new(application_id: app_id, api_key: api_key)
28
+ create_with_config(config)
29
+ end
30
+
31
+ # Create a new client providing only an Personalization::Config object
32
+ #
33
+ # @param config [Personalization::Config]
34
+ #
35
+ # @return self
36
+ #
37
+ def self.create_with_config(config)
38
+ new(config)
39
+ end
40
+
41
+ # Set the personalization strategy.
42
+ #
43
+ # @param personalization_strategy [Hash] A strategy object.
44
+ #
45
+ # @return [Hash]
46
+ #
47
+ def set_personalization_strategy(personalization_strategy, opts = {})
48
+ @transporter.write(:POST, '1/strategies/personalization', personalization_strategy, opts)
49
+ end
50
+
51
+ # Get the personalization strategy.
52
+ #
53
+ # @return [Hash]
54
+ #
55
+ def get_personalization_strategy(opts = {})
56
+ @transporter.read(:GET, '1/strategies/personalization', {}, opts)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,60 +1,7 @@
1
1
  module Algolia
2
2
  module Recommendation
3
- class Client
4
- # Initializes the Recommendation client
5
- #
6
- # @param recommendation_config [Recommendation::Config] a Recommendation::Config object which contains your APP_ID and API_KEY
7
- # @option adapter [Object] adapter object used for the connection
8
- # @option logger [Object]
9
- # @option http_requester [Object] http_requester object used for the connection
10
- #
11
- def initialize(recommendation_config, opts = {})
12
- @config = recommendation_config
13
- adapter = opts[:adapter] || Defaults::ADAPTER
14
- logger = opts[:logger] || LoggerHelper.create('debug.log')
15
- requester = opts[:http_requester] || Defaults::REQUESTER_CLASS.new(adapter, logger)
16
- @transporter = Transport::Transport.new(@config, requester)
17
- end
18
-
19
- # Create a new client providing only app ID and API key
20
- #
21
- # @param app_id [String] Algolia application ID
22
- # @param api_key [String] Algolia API key
23
- #
24
- # @return self
25
- #
26
- def self.create(app_id, api_key)
27
- config = Recommendation::Config.new(application_id: app_id, api_key: api_key)
28
- create_with_config(config)
29
- end
30
-
31
- # Create a new client providing only an Recommendation::Config object
32
- #
33
- # @param config [Recommendation::Config]
34
- #
35
- # @return self
36
- #
37
- def self.create_with_config(config)
38
- new(config)
39
- end
40
-
41
- # Set the personalization strategy.
42
- #
43
- # @param personalization_strategy [Hash] A strategy object.
44
- #
45
- # @return [Hash]
46
- #
47
- def set_personalization_strategy(personalization_strategy, opts = {})
48
- @transporter.write(:POST, '1/strategies/personalization', personalization_strategy, opts)
49
- end
50
-
51
- # Get the personalization strategy.
52
- #
53
- # @return [Hash]
54
- #
55
- def get_personalization_strategy(opts = {})
56
- @transporter.read(:GET, '1/strategies/personalization', {}, opts)
57
- end
3
+ # <b>DEPRECATED:</b> Please use <tt>Algolia::Personalization::Client</tt> instead.
4
+ class Client < Algolia::Personalization::Client
58
5
  end
59
6
  end
60
7
  end
@@ -28,7 +28,7 @@ module Algolia
28
28
  end
29
29
  retries_count += 1
30
30
  time_before_retry = retries_count * Defaults::WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY
31
- sleep(time_before_retry / 1000)
31
+ sleep(time_before_retry.to_f / 1000)
32
32
  end
33
33
  end
34
34
 
@@ -29,7 +29,7 @@ module Algolia
29
29
  unless @done
30
30
  retries_count += 1
31
31
  time_before_retry = retries_count * Defaults::WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY
32
- sleep(time_before_retry / 1000)
32
+ sleep(time_before_retry.to_f / 1000)
33
33
  end
34
34
  end
35
35
  end
@@ -26,7 +26,7 @@ module Algolia
26
26
  end
27
27
  retries_count += 1
28
28
  time_before_retry = retries_count * Defaults::WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY
29
- sleep(time_before_retry / 1000)
29
+ sleep(time_before_retry.to_f / 1000)
30
30
  end
31
31
  end
32
32
 
@@ -29,7 +29,7 @@ module Algolia
29
29
  raise e unless e.code == 404
30
30
  retries_count += 1
31
31
  time_before_retry = retries_count * Defaults::WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY
32
- sleep(time_before_retry / 1000)
32
+ sleep(time_before_retry.to_f / 1000)
33
33
  end
34
34
  end
35
35
 
@@ -478,6 +478,9 @@ module Algolia
478
478
  # @return [Hash]
479
479
  #
480
480
  def multiple_queries(queries, opts = {})
481
+ queries.each do |q|
482
+ q[:params] = to_query_string(q[:params]) unless q[:params].is_a?(String)
483
+ end
481
484
  @transporter.read(:POST, '/1/indexes/*/queries', { requests: queries }, opts)
482
485
  end
483
486
  alias_method :search, :multiple_queries
@@ -36,7 +36,7 @@ module Algolia
36
36
  if status == 'published'
37
37
  return
38
38
  end
39
- sleep(time_before_retry / 1000)
39
+ sleep(time_before_retry.to_f / 1000)
40
40
  end
41
41
  end
42
42
 
@@ -1,3 +1,3 @@
1
1
  module Algolia
2
- VERSION = '2.2.0'.freeze
2
+ VERSION = '2.2.3'.freeze
3
3
  end
data/lib/algolia.rb CHANGED
@@ -8,6 +8,7 @@ require 'algolia/config/search_config'
8
8
  require 'algolia/config/analytics_config'
9
9
  require 'algolia/config/insights_config'
10
10
  require 'algolia/config/recommend_config'
11
+ require 'algolia/config/personalization_config'
11
12
  require 'algolia/config/recommendation_config'
12
13
  require 'algolia/enums/call_type'
13
14
  require 'algolia/enums/retry_outcome_type'
@@ -35,6 +36,7 @@ require 'algolia/search_client'
35
36
  require 'algolia/analytics_client'
36
37
  require 'algolia/insights_client'
37
38
  require 'algolia/recommend_client'
39
+ require 'algolia/personalization_client'
38
40
  require 'algolia/recommendation_client'
39
41
  require 'algolia/error'
40
42
  require 'algolia/search_index'
@@ -14,7 +14,7 @@ class AccountClientTest < BaseTest
14
14
 
15
15
  search_client2 = Algolia::Search::Client.create(APPLICATION_ID_2, ADMIN_KEY_2)
16
16
  index2 = search_client2.init_index(get_test_index_name('copy_index2'))
17
- index1.save_object!({ objectID: 'one' })
17
+ index1.save_object!({ objectID: 'one', title: 'Test title' })
18
18
  index1.save_rule!({
19
19
  objectID: 'one',
20
20
  condition: { anchoring: 'is', pattern: 'pattern' },
@@ -29,7 +29,7 @@ class AccountClientTest < BaseTest
29
29
  }
30
30
  })
31
31
  index1.save_synonym!({ objectID: 'one', type: 'synonym', synonyms: %w(one two) })
32
- index1.set_settings!({ searchableAttributes: ['objectID'] })
32
+ index1.set_settings!({ searchableAttributes: ['title'] })
33
33
 
34
34
  Algolia::Account::Client.copy_index!(index1, index2)
35
35
  assert_equal 'one', index2.get_object('one')[:objectID]
@@ -20,7 +20,7 @@ class MockRequester
20
20
 
21
21
  Algolia::Http::Response.new(
22
22
  status: 200,
23
- body: '{"hits": []}',
23
+ body: '{"hits": [], "status": "published"}',
24
24
  headers: {}
25
25
  )
26
26
  end
@@ -0,0 +1,30 @@
1
+ require_relative 'base_test'
2
+ require 'date'
3
+
4
+ class PersonalizationClientTest < BaseTest
5
+ describe 'Personalization client' do
6
+ def test_personalization_client
7
+ client = Algolia::Personalization::Client.create(APPLICATION_ID_1, ADMIN_KEY_1)
8
+ personalization_strategy = {
9
+ eventsScoring: [
10
+ { eventName: 'Add to cart', eventType: 'conversion', score: 50 },
11
+ { eventName: 'Purchase', eventType: 'conversion', score: 100 }
12
+ ],
13
+ facetsScoring: [
14
+ { facetName: 'brand', score: 100 },
15
+ { facetName: 'categories', score: 10 }
16
+ ],
17
+ personalizationImpact: 0
18
+ }
19
+
20
+ begin
21
+ client.set_personalization_strategy(personalization_strategy)
22
+ rescue Algolia::AlgoliaHttpError => e
23
+ raise e unless e.code == 429
24
+ end
25
+ response = client.get_personalization_strategy
26
+
27
+ assert_equal response, personalization_strategy
28
+ end
29
+ end
30
+ end
@@ -294,7 +294,7 @@ class SearchClientTest < BaseTest
294
294
 
295
295
  results = @@search_client.multiple_queries([
296
296
  { indexName: index_name1, params: to_query_string({ query: '', hitsPerPage: 2 }) },
297
- { indexName: index_name2, params: to_query_string({ query: '', hitsPerPage: 2 }) }
297
+ { indexName: index_name2, params: { query: '', hitsPerPage: 2 } }
298
298
  ], { strategy: 'none' })[:results]
299
299
 
300
300
  assert_equal 2, results.length
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algolia
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-08 00:00:00.000000000 Z
11
+ date: 2022-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -218,6 +218,7 @@ files:
218
218
  - lib/algolia/config/analytics_config.rb
219
219
  - lib/algolia/config/base_config.rb
220
220
  - lib/algolia/config/insights_config.rb
221
+ - lib/algolia/config/personalization_config.rb
221
222
  - lib/algolia/config/recommend_config.rb
222
223
  - lib/algolia/config/recommendation_config.rb
223
224
  - lib/algolia/config/search_config.rb
@@ -235,6 +236,7 @@ files:
235
236
  - lib/algolia/iterators/rule_iterator.rb
236
237
  - lib/algolia/iterators/synonym_iterator.rb
237
238
  - lib/algolia/logger_helper.rb
239
+ - lib/algolia/personalization_client.rb
238
240
  - lib/algolia/recommend_client.rb
239
241
  - lib/algolia/recommendation_client.rb
240
242
  - lib/algolia/responses/add_api_key_response.rb
@@ -276,6 +278,7 @@ files:
276
278
  - test/algolia/integration/base_test.rb
277
279
  - test/algolia/integration/insights_client_test.rb
278
280
  - test/algolia/integration/mocks/mock_requester.rb
281
+ - test/algolia/integration/personalization_client_test.rb
279
282
  - test/algolia/integration/recommend_client_test.rb
280
283
  - test/algolia/integration/recommendation_client_test.rb
281
284
  - test/algolia/integration/search_client_test.rb
@@ -318,6 +321,7 @@ test_files:
318
321
  - test/algolia/integration/base_test.rb
319
322
  - test/algolia/integration/insights_client_test.rb
320
323
  - test/algolia/integration/mocks/mock_requester.rb
324
+ - test/algolia/integration/personalization_client_test.rb
321
325
  - test/algolia/integration/recommend_client_test.rb
322
326
  - test/algolia/integration/recommendation_client_test.rb
323
327
  - test/algolia/integration/search_client_test.rb