algolia 2.0.0.pre.alpha.2 → 2.0.0.pre.beta.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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/Gemfile +1 -1
  4. data/algolia.gemspec +9 -2
  5. data/lib/algolia.rb +1 -1
  6. data/lib/algolia/analytics_client.rb +1 -1
  7. data/lib/algolia/config/analytics_config.rb +2 -2
  8. data/lib/algolia/config/base_config.rb +45 -0
  9. data/lib/algolia/config/insights_config.rb +2 -2
  10. data/lib/algolia/config/recommendation_config.rb +2 -2
  11. data/lib/algolia/config/search_config.rb +2 -2
  12. data/lib/algolia/defaults.rb +2 -2
  13. data/lib/algolia/error.rb +1 -2
  14. data/lib/algolia/helpers.rb +5 -2
  15. data/lib/algolia/insights_client.rb +1 -1
  16. data/lib/algolia/iterators/object_iterator.rb +5 -4
  17. data/lib/algolia/iterators/paginator_iterator.rb +5 -3
  18. data/lib/algolia/recommendation_client.rb +1 -1
  19. data/lib/algolia/search_client.rb +1 -1
  20. data/lib/algolia/search_index.rb +37 -37
  21. data/lib/algolia/transport/transport.rb +4 -4
  22. data/lib/algolia/version.rb +1 -1
  23. data/sig/config/algolia_config.rbs +3 -3
  24. data/sig/config/analytics_config.rbs +1 -1
  25. data/sig/config/insights_config.rbs +1 -1
  26. data/sig/config/recommendation_config.rbs +1 -1
  27. data/sig/config/search_config.rbs +1 -1
  28. data/test/algolia/integration/analytics_client_test.rb +6 -6
  29. data/test/algolia/integration/insights_client_test.rb +11 -11
  30. data/test/algolia/integration/search_client_test.rb +20 -11
  31. data/test/algolia/unit/algolia_config_test.rb +16 -0
  32. data/test/algolia/unit/helpers_test.rb +29 -1
  33. data/test/algolia/unit/retry_strategy_test.rb +3 -3
  34. data/test/test_helper.rb +1 -1
  35. data/upgrade_guide.md +29 -21
  36. metadata +17 -11
  37. data/lib/algolia/config/algolia_config.rb +0 -40
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d60205951ef158935268ca5acdea467072a3e06355b1937a81ae78724da0e909
4
- data.tar.gz: eba4990f0591fb94fbcbc4d7e834f9fdb8ff0092d05a05e658b5a89272999bd5
3
+ metadata.gz: 47d18253040f91e77f82a815e90b4064c88aac2ddbacbe4c26b1dea81304d847
4
+ data.tar.gz: 530b601d76e6de0b4f252dc13bcce01f7446428f839cd22fb4b286a1b5a17f73
5
5
  SHA512:
6
- metadata.gz: e458b5c6be67e8c73338995485cfb01783e83d0e22be7bdce4fa0b23f7bedada8f9630ce274569a30ce7e792ad35324f22d8dbd2761e1ed5f08a6bbcd69984fb
7
- data.tar.gz: 68b2b9af700d930b34ccab5340515935ee56b81eb1bec1703ae9cf4db6f7cb065322dc88705ebc8025e3579a065f6cbbed8b288347d2e15d7e68df4e54b378de
6
+ metadata.gz: 04c63a1fb49fcd66817e0b43f66c16b3cbe8bd044ca513409047f8709ab8cc757deb30cedaeafcddf831f98179efa9c21fdcbf4bb09a1641b9b5b7aa96d6fc8c
7
+ data.tar.gz: e552093cc4ab5827c8ab87e448856bfdbd68f113b8e321e928e66ceb03f8ecf96531aad902d256a6372336c9efeedd166e85165d63a0c83f0795de942a0b4eb7
@@ -184,3 +184,6 @@ Style/HashTransformValues:
184
184
 
185
185
  Style/HashEachMethods:
186
186
  Enabled: true
187
+
188
+ Style/RedundantBegin:
189
+ Enabled: false
data/Gemfile CHANGED
@@ -9,7 +9,7 @@ gem 'minitest-ci'
9
9
 
10
10
  group :development do
11
11
  gem 'git-precommit'
12
- gem 'steep'
12
+ gem 'steep' if RUBY_VERSION >= '2.5'
13
13
  gem 'yard'
14
14
  end
15
15
 
@@ -12,8 +12,15 @@ Gem::Specification.new do |spec|
12
12
 
13
13
  spec.date = Date.today
14
14
  spec.licenses = ['MIT']
15
- spec.summary = 'A simple Ruby client for the algolia.com REST API'
16
- spec.description = 'A simple Ruby client for the algolia.com REST API'
15
+ spec.summary = 'A simple Ruby client for the algolia.com REST API (alpha release)'
16
+ spec.description = 'This is the alpha version of the upcoming v2 release of Algolia Client. Please keep on using the algoliasearch gem in the meantime.'
17
+ spec.homepage = 'https://github.com/algolia/algoliasearch-client-ruby/tree/release/v2'
18
+
19
+ spec.metadata = {
20
+ 'bug_tracker_uri' => 'https://github.com/algolia/algoliasearch-client-ruby/issues',
21
+ 'documentation_uri' => 'http://www.rubydoc.info/gems/algolia',
22
+ 'source_code_uri' => 'https://github.com/algolia/algoliasearch-client-ruby/tree/release/v2'
23
+ }
17
24
 
18
25
  # Specify which files should be added to the gem when it is released.
19
26
  # The `git ls-files -z` loads the files in the RubyGem
@@ -3,7 +3,7 @@ require 'algolia/helpers'
3
3
  require 'algolia/http/http_requester'
4
4
  require 'algolia/defaults'
5
5
  require 'algolia/user_agent'
6
- require 'algolia/config/algolia_config'
6
+ require 'algolia/config/base_config'
7
7
  require 'algolia/config/search_config'
8
8
  require 'algolia/config/analytics_config'
9
9
  require 'algolia/config/insights_config'
@@ -26,7 +26,7 @@ module Algolia
26
26
  # @return self
27
27
  #
28
28
  def self.create(app_id, api_key)
29
- config = Analytics::Config.new(app_id: app_id, api_key: api_key)
29
+ config = Analytics::Config.new(application_id: app_id, api_key: api_key)
30
30
  create_with_config(config)
31
31
  end
32
32
 
@@ -1,11 +1,11 @@
1
1
  module Algolia
2
2
  module Analytics
3
- class Config < AlgoliaConfig
3
+ class Config < BaseConfig
4
4
  attr_accessor :region, :default_hosts
5
5
 
6
6
  # Initialize a config
7
7
  #
8
- # @option options [String] :app_id
8
+ # @option options [String] :application_id
9
9
  # @option options [String] :api_key
10
10
  # @option options [String] :region
11
11
  #
@@ -0,0 +1,45 @@
1
+ require 'faraday'
2
+
3
+ module Algolia
4
+ class BaseConfig
5
+ attr_accessor :app_id, :api_key, :headers, :batch_size, :read_timeout, :write_timeout, :connect_timeout, :compression_type,
6
+ :symbolize_keys, :use_latest_settings
7
+
8
+ #
9
+ # @option options [String] :application_id
10
+ # @option options [String] :api_key
11
+ # @option options [Integer] :batch_size
12
+ # @option options [Integer] :read_timeout
13
+ # @option options [Integer] :write_timeout
14
+ # @option options [Integer] :connect_timeout
15
+ # @option options [Boolean] :symbolize_keys
16
+ #
17
+ def initialize(opts = {})
18
+ raise AlgoliaError, 'No Application ID provided, please set :application_id' unless opts.has_key?(:application_id)
19
+ raise AlgoliaError, 'No API key provided, please set :api_key' unless opts.has_key?(:api_key)
20
+
21
+ @app_id = opts[:application_id]
22
+ @api_key = opts[:api_key]
23
+
24
+ @headers = {
25
+ Defaults::HEADER_API_KEY => @api_key,
26
+ Defaults::HEADER_APP_ID => @app_id,
27
+ 'Content-Type' => 'application/json; charset=utf-8',
28
+ 'User-Agent' => UserAgent.value
29
+ }
30
+
31
+ @batch_size = opts[:batch_size] || Defaults::BATCH_SIZE
32
+ @read_timeout = opts[:read_timeout] || Defaults::READ_TIMEOUT
33
+ @write_timeout = opts[:write_timeout] || Defaults::WRITE_TIMEOUT
34
+ @connect_timeout = opts[:connect_timeout] || Defaults::CONNECT_TIMEOUT
35
+ @compression_type = opts[:compression_type] || Defaults::NONE_ENCODING
36
+ @symbolize_keys = opts.has_key?(:symbolize_keys) ? opts[:symbolize_keys] : true
37
+ # used to avoid BC break on Rails integration, should not be documented
38
+ @use_latest_settings = opts.has_key?(:use_latest_settings) ? opts[:use_latest_settings] : true
39
+ end
40
+
41
+ def set_extra_header(key, value)
42
+ @headers[key] = value
43
+ end
44
+ end
45
+ end
@@ -1,11 +1,11 @@
1
1
  module Algolia
2
2
  module Insights
3
- class Config < AlgoliaConfig
3
+ class Config < BaseConfig
4
4
  attr_accessor :region, :default_hosts
5
5
 
6
6
  # Initialize a config
7
7
  #
8
- # @option options [String] :app_id
8
+ # @option options [String] :application_id
9
9
  # @option options [String] :api_key
10
10
  # @option options [String] :region
11
11
  #
@@ -1,11 +1,11 @@
1
1
  module Algolia
2
2
  module Recommendation
3
- class Config < AlgoliaConfig
3
+ class Config < BaseConfig
4
4
  attr_accessor :region, :default_hosts
5
5
 
6
6
  # Initialize a config
7
7
  #
8
- # @option options [String] :app_id
8
+ # @option options [String] :application_id
9
9
  # @option options [String] :api_key
10
10
  # @option options [String] :region
11
11
  #
@@ -5,13 +5,13 @@ require 'algolia/enums/call_type'
5
5
 
6
6
  module Algolia
7
7
  module Search
8
- class Config < AlgoliaConfig
8
+ class Config < BaseConfig
9
9
  include CallType
10
10
  attr_accessor :default_hosts
11
11
 
12
12
  # Initialize a config
13
13
  #
14
- # @option options [String] :app_id
14
+ # @option options [String] :application_id
15
15
  # @option options [String] :api_key
16
16
  # @option options [Hash] :custom_hosts
17
17
  #
@@ -24,8 +24,8 @@ module Defaults
24
24
 
25
25
  BATCH_SIZE = 1000
26
26
  CONNECT_TIMEOUT = 2
27
- READ_TIMEOUT = 30
28
- WRITE_TIMEOUT = 5
27
+ READ_TIMEOUT = 5
28
+ WRITE_TIMEOUT = 30
29
29
  USER_AGENT = "Algolia for Ruby (#{Algolia::VERSION}), Ruby (#{RUBY_VERSION})"
30
30
 
31
31
  WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY = 100
@@ -17,8 +17,7 @@ module Algolia
17
17
  # which is also included in the response attribute.
18
18
  #
19
19
  class AlgoliaHttpError < AlgoliaError
20
- attr_accessor :code
21
- attr_accessor :message
20
+ attr_accessor :code, :message
22
21
 
23
22
  def initialize(code, message)
24
23
  self.code = code
@@ -52,7 +52,9 @@ module Helpers
52
52
 
53
53
  # Support to convert old settings to their new names
54
54
  #
55
- def deserialize_settings(data)
55
+ def deserialize_settings(data, use_latest_settings, symbolize_keys)
56
+ return data unless use_latest_settings
57
+
56
58
  settings = symbolize_hash(data)
57
59
  keys = {
58
60
  attributesToIndex: 'searchableAttributes',
@@ -62,7 +64,8 @@ module Helpers
62
64
 
63
65
  keys.each do |deprecated_key, current_key|
64
66
  if settings.has_key?(deprecated_key)
65
- settings[current_key.to_sym] = settings.delete(deprecated_key)
67
+ key = symbolize_keys ? current_key.to_sym : current_key.to_s
68
+ settings[key] = settings.delete(deprecated_key)
66
69
  end
67
70
  end
68
71
 
@@ -26,7 +26,7 @@ module Algolia
26
26
  # @return self
27
27
  #
28
28
  def self.create(app_id, api_key)
29
- config = Insights::Config.new(app_id: app_id, api_key: api_key)
29
+ config = Insights::Config.new(application_id: app_id, api_key: api_key)
30
30
  create_with_config(config)
31
31
  end
32
32
 
@@ -7,16 +7,17 @@ module Algolia
7
7
  data = {}
8
8
 
9
9
  if @response
10
- if @response[:hits].length
11
- @response[:hits].each do |hit|
10
+ parsed_response = symbolize_hash(@response)
11
+ if parsed_response[:hits].length
12
+ parsed_response[:hits].each do |hit|
12
13
  yield hit
13
14
  end
14
15
 
15
- if @response[:cursor].nil?
16
+ if parsed_response[:cursor].nil?
16
17
  @response = nil
17
18
  raise StopIteration
18
19
  else
19
- data[:cursor] = @response[:cursor]
20
+ data[:cursor] = parsed_response[:cursor]
20
21
  end
21
22
  end
22
23
  end
@@ -16,13 +16,15 @@ module Algolia
16
16
  def each
17
17
  loop do
18
18
  if @response
19
- if @response[:hits].length
20
- @response[:hits].each do |hit|
19
+ parsed_response = symbolize_hash(@response)
20
+ parsed_data = symbolize_hash(@data)
21
+ if parsed_response[:hits].length
22
+ parsed_response[:hits].each do |hit|
21
23
  hit.delete(:_highlightResult)
22
24
  yield hit
23
25
  end
24
26
 
25
- if @response[:nbHits] < @data[:hitsPerPage]
27
+ if parsed_response[:nbHits] < parsed_data[:hitsPerPage]
26
28
  @response = nil
27
29
  @data = {
28
30
  hitsPerPage: 1000,
@@ -24,7 +24,7 @@ module Algolia
24
24
  # @return self
25
25
  #
26
26
  def self.create(app_id, api_key)
27
- config = Recommendation::Config.new(app_id: app_id, api_key: api_key)
27
+ config = Recommendation::Config.new(application_id: app_id, api_key: api_key)
28
28
  create_with_config(config)
29
29
  end
30
30
 
@@ -32,7 +32,7 @@ module Algolia
32
32
  # @return self
33
33
  #
34
34
  def self.create(app_id, api_key)
35
- config = Search::Config.new(app_id: app_id, api_key: api_key)
35
+ config = Search::Config.new(application_id: app_id, api_key: api_key)
36
36
  create_with_config(config)
37
37
  end
38
38
 
@@ -5,16 +5,16 @@ module Algolia
5
5
  include CallType
6
6
  include Helpers
7
7
 
8
- attr_reader :index_name, :transporter, :config
8
+ attr_reader :name, :transporter, :config
9
9
 
10
10
  # Initialize an index
11
11
  #
12
- # @param index_name [String] name of the index
12
+ # @param name [String] name of the index
13
13
  # @param transporter [Object] transport object used for the connection
14
14
  # @param config [Config] a Config object which contains your APP_ID and API_KEY
15
15
  #
16
- def initialize(index_name, transporter, config)
17
- @index_name = index_name
16
+ def initialize(name, transporter, config)
17
+ @name = name
18
18
  @transporter = transporter
19
19
  @config = config
20
20
  end
@@ -47,7 +47,7 @@ module Algolia
47
47
  # @param opts [Hash] contains extra parameters to send with your query
48
48
  #
49
49
  def get_task_status(task_id, opts = {})
50
- res = @transporter.read(:GET, path_encode('/1/indexes/%s/task/%s', @index_name, task_id), {}, opts)
50
+ res = @transporter.read(:GET, path_encode('/1/indexes/%s/task/%s', @name, task_id), {}, opts)
51
51
  get_option(res, 'status')
52
52
  end
53
53
 
@@ -56,7 +56,7 @@ module Algolia
56
56
  # @param opts [Hash] contains extra parameters to send with your query
57
57
  #
58
58
  def clear_objects(opts = {})
59
- response = @transporter.write(:POST, path_encode('/1/indexes/%s/clear', @index_name), {}, opts)
59
+ response = @transporter.write(:POST, path_encode('/1/indexes/%s/clear', @name), {}, opts)
60
60
 
61
61
  IndexingResponse.new(self, response)
62
62
  end
@@ -75,7 +75,7 @@ module Algolia
75
75
  # @param opts [Hash] contains extra parameters to send with your query
76
76
  #
77
77
  def delete(opts = {})
78
- response = @transporter.write(:DELETE, path_encode('/1/indexes/%s', @index_name), opts)
78
+ response = @transporter.write(:DELETE, path_encode('/1/indexes/%s', @name), opts)
79
79
 
80
80
  IndexingResponse.new(self, response)
81
81
  end
@@ -115,7 +115,7 @@ module Algolia
115
115
  has_next_page = true
116
116
  while has_next_page
117
117
  request_options[:page] = page
118
- res = search(query, request_options)
118
+ res = symbolize_hash(search(query, request_options))
119
119
 
120
120
  res[:hits].each_with_index do |hit, i|
121
121
  if callback.call(hit)
@@ -154,7 +154,7 @@ module Algolia
154
154
  # @return [IndexingResponse]
155
155
  #
156
156
  def copy_to(name, opts = {})
157
- response = @transporter.write(:POST, path_encode('/1/indexes/%s/operation', @index_name), { operation: 'copy', destination: name }, opts)
157
+ response = @transporter.write(:POST, path_encode('/1/indexes/%s/operation', @name), { operation: 'copy', destination: name }, opts)
158
158
 
159
159
  IndexingResponse.new(self, response)
160
160
  end
@@ -167,7 +167,7 @@ module Algolia
167
167
  # @return [IndexingResponse]
168
168
  #
169
169
  def move_to(name, opts = {})
170
- response = @transporter.write(:POST, path_encode('/1/indexes/%s/operation', @index_name), { operation: 'move', destination: name }, opts)
170
+ response = @transporter.write(:POST, path_encode('/1/indexes/%s/operation', @name), { operation: 'move', destination: name }, opts)
171
171
 
172
172
  IndexingResponse.new(self, response)
173
173
  end
@@ -184,7 +184,7 @@ module Algolia
184
184
  # @return [Hash]
185
185
  #
186
186
  def get_object(object_id, opts = {})
187
- @transporter.read(:GET, path_encode('/1/indexes/%s/%s', @index_name, object_id), {}, opts)
187
+ @transporter.read(:GET, path_encode('/1/indexes/%s/%s', @name, object_id), {}, opts)
188
188
  end
189
189
 
190
190
  # Retrieve one or more objects in a single API call
@@ -201,7 +201,7 @@ module Algolia
201
201
 
202
202
  requests = []
203
203
  object_ids.each do |object_id|
204
- request = { indexName: @index_name, objectID: object_id.to_s }
204
+ request = { indexName: @name, objectID: object_id.to_s }
205
205
 
206
206
  if attributes_to_retrieve
207
207
  request[:attributesToRetrieve] = attributes_to_retrieve
@@ -381,7 +381,7 @@ module Algolia
381
381
  # @return [IndexingResponse]
382
382
  #
383
383
  def delete_by(filters, opts = {})
384
- response = @transporter.write(:POST, path_encode('/1/indexes/%s/deleteByQuery', @index_name), filters, opts)
384
+ response = @transporter.write(:POST, path_encode('/1/indexes/%s/deleteByQuery', @name), filters, opts)
385
385
 
386
386
  IndexingResponse.new(self, response)
387
387
  end
@@ -436,7 +436,7 @@ module Algolia
436
436
  # @return [Hash]
437
437
  #
438
438
  def get_rule(object_id, opts = {})
439
- @transporter.read(:GET, path_encode('/1/indexes/%s/rules/%s', @index_name, object_id), {}, opts)
439
+ @transporter.read(:GET, path_encode('/1/indexes/%s/rules/%s', @name, object_id), {}, opts)
440
440
  end
441
441
 
442
442
  # Create or update a rule
@@ -500,7 +500,7 @@ module Algolia
500
500
  get_object_id(rule)
501
501
  end
502
502
 
503
- response = @transporter.write(:POST, path_encode('/1/indexes/%s/rules/batch', @index_name) + handle_params({ forwardToReplicas: forward_to_replicas, clearExistingRules: clear_existing_rules }), rules, request_options)
503
+ response = @transporter.write(:POST, path_encode('/1/indexes/%s/rules/batch', @name) + handle_params({ forwardToReplicas: forward_to_replicas, clearExistingRules: clear_existing_rules }), rules, request_options)
504
504
 
505
505
  IndexingResponse.new(self, response)
506
506
  end
@@ -532,7 +532,7 @@ module Algolia
532
532
  request_options.delete(:forwardToReplicas)
533
533
  end
534
534
 
535
- response = @transporter.write(:POST, path_encode('1/indexes/%s/rules/clear', @index_name) + handle_params({ forwardToReplicas: forward_to_replicas }), '', request_options)
535
+ response = @transporter.write(:POST, path_encode('1/indexes/%s/rules/clear', @name) + handle_params({ forwardToReplicas: forward_to_replicas }), '', request_options)
536
536
 
537
537
  IndexingResponse.new(self, response)
538
538
  end
@@ -566,7 +566,7 @@ module Algolia
566
566
 
567
567
  response = @transporter.write(
568
568
  :DELETE,
569
- path_encode('1/indexes/%s/rules/%s', @index_name, object_id) + handle_params({ forwardToReplicas: forward_to_replicas }),
569
+ path_encode('1/indexes/%s/rules/%s', @name, object_id) + handle_params({ forwardToReplicas: forward_to_replicas }),
570
570
  '',
571
571
  request_options
572
572
  )
@@ -598,7 +598,7 @@ module Algolia
598
598
  # @return [Hash]
599
599
  #
600
600
  def get_synonym(object_id, opts = {})
601
- @transporter.read(:GET, path_encode('/1/indexes/%s/synonyms/%s', @index_name, object_id), {}, opts)
601
+ @transporter.read(:GET, path_encode('/1/indexes/%s/synonyms/%s', @name, object_id), {}, opts)
602
602
  end
603
603
 
604
604
  # Create a new synonym object or update the existing synonym object with the given object ID
@@ -666,7 +666,7 @@ module Algolia
666
666
  end
667
667
  response = @transporter.write(
668
668
  :POST,
669
- path_encode('/1/indexes/%s/synonyms/batch', @index_name) + handle_params({ forwardToReplicas: forward_to_replicas, replaceExistingSynonyms: replace_existing_synonyms }),
669
+ path_encode('/1/indexes/%s/synonyms/batch', @name) + handle_params({ forwardToReplicas: forward_to_replicas, replaceExistingSynonyms: replace_existing_synonyms }),
670
670
  synonyms,
671
671
  request_options
672
672
  )
@@ -703,7 +703,7 @@ module Algolia
703
703
  end
704
704
  response = @transporter.write(
705
705
  :POST,
706
- path_encode('1/indexes/%s/synonyms/clear', @index_name) + handle_params({ forwardToReplicas: forward_to_replicas }),
706
+ path_encode('1/indexes/%s/synonyms/clear', @name) + handle_params({ forwardToReplicas: forward_to_replicas }),
707
707
  '',
708
708
  request_options
709
709
  )
@@ -738,7 +738,7 @@ module Algolia
738
738
  end
739
739
  response = @transporter.write(
740
740
  :DELETE,
741
- path_encode('1/indexes/%s/synonyms/%s', @index_name, object_id) + handle_params({ forwardToReplicas: forward_to_replicas }),
741
+ path_encode('1/indexes/%s/synonyms/%s', @name, object_id) + handle_params({ forwardToReplicas: forward_to_replicas }),
742
742
  '',
743
743
  request_options
744
744
  )
@@ -769,9 +769,9 @@ module Algolia
769
769
  #
770
770
  def browse_objects(opts = {}, &block)
771
771
  if block_given?
772
- ObjectIterator.new(@transporter, @index_name, opts).each(&block)
772
+ ObjectIterator.new(@transporter, @name, opts).each(&block)
773
773
  else
774
- ObjectIterator.new(@transporter, @index_name, opts)
774
+ ObjectIterator.new(@transporter, @name, opts)
775
775
  end
776
776
  end
777
777
 
@@ -783,9 +783,9 @@ module Algolia
783
783
  #
784
784
  def browse_rules(opts = {}, &block)
785
785
  if block_given?
786
- RuleIterator.new(@transporter, @index_name, opts).each(&block)
786
+ RuleIterator.new(@transporter, @name, opts).each(&block)
787
787
  else
788
- RuleIterator.new(@transporter, @index_name, opts)
788
+ RuleIterator.new(@transporter, @name, opts)
789
789
  end
790
790
  end
791
791
 
@@ -797,9 +797,9 @@ module Algolia
797
797
  #
798
798
  def browse_synonyms(opts = {}, &block)
799
799
  if block_given?
800
- SynonymIterator.new(@transporter, @index_name, opts).each(&block)
800
+ SynonymIterator.new(@transporter, @name, opts).each(&block)
801
801
  else
802
- SynonymIterator.new(@transporter, @index_name, opts)
802
+ SynonymIterator.new(@transporter, @name, opts)
803
803
  end
804
804
  end
805
805
 
@@ -822,7 +822,7 @@ module Algolia
822
822
  request_options.delete(:safe)
823
823
  end
824
824
 
825
- tmp_index_name = @index_name + '_tmp_' + rand(10000000).to_s
825
+ tmp_index_name = @name + '_tmp_' + rand(10000000).to_s
826
826
  copy_to_response = copy_to(tmp_index_name, request_options.merge({ scope: %w(settings synonyms rules) }))
827
827
 
828
828
  if safe
@@ -839,7 +839,7 @@ module Algolia
839
839
  save_objects_response.wait
840
840
  end
841
841
 
842
- move_to_response = tmp_index.move_to(@index_name)
842
+ move_to_response = tmp_index.move_to(@name)
843
843
  if safe
844
844
  move_to_response.wait
845
845
  end
@@ -924,7 +924,7 @@ module Algolia
924
924
  # @return [Hash]
925
925
  #
926
926
  def search(query, opts = {})
927
- @transporter.read(:POST, path_encode('/1/indexes/%s/query', @index_name), { 'query': query.to_s }, opts)
927
+ @transporter.read(:POST, path_encode('/1/indexes/%s/query', @name), { 'query': query.to_s }, opts)
928
928
  end
929
929
 
930
930
  # Search for values of a given facet, optionally restricting the returned values to those contained
@@ -937,7 +937,7 @@ module Algolia
937
937
  # @return [Hash]
938
938
  #
939
939
  def search_for_facet_values(facet_name, facet_query, opts = {})
940
- @transporter.read(:POST, path_encode('/1/indexes/%s/facets/%s/query', @index_name, facet_name),
940
+ @transporter.read(:POST, path_encode('/1/indexes/%s/facets/%s/query', @name, facet_name),
941
941
  { 'facetQuery': facet_query }, opts)
942
942
  end
943
943
 
@@ -949,7 +949,7 @@ module Algolia
949
949
  # @return [Hash]
950
950
  #
951
951
  def search_synonyms(query, opts = {})
952
- @transporter.read(:POST, path_encode('/1/indexes/%s/synonyms/search', @index_name), { query: query.to_s }, opts)
952
+ @transporter.read(:POST, path_encode('/1/indexes/%s/synonyms/search', @name), { query: query.to_s }, opts)
953
953
  end
954
954
 
955
955
  # Search or browse all rules, optionally filtering them by type
@@ -960,7 +960,7 @@ module Algolia
960
960
  # @return [Hash]
961
961
  #
962
962
  def search_rules(query, opts = {})
963
- @transporter.read(:POST, path_encode('/1/indexes/%s/rules/search', @index_name), { query: query.to_s }, opts)
963
+ @transporter.read(:POST, path_encode('/1/indexes/%s/rules/search', @name), { query: query.to_s }, opts)
964
964
  end
965
965
 
966
966
  # # # # # # # # # # # # # # # # # # # # #
@@ -974,9 +974,9 @@ module Algolia
974
974
  # @return [Hash]
975
975
  #
976
976
  def get_settings(opts = {})
977
- response = @transporter.read(:GET, path_encode('/1/indexes/%s/settings', @index_name) + handle_params({ getVersion: 2 }), {}, opts)
977
+ response = @transporter.read(:GET, path_encode('/1/indexes/%s/settings', @name) + handle_params({ getVersion: 2 }), {}, opts)
978
978
 
979
- deserialize_settings(response)
979
+ deserialize_settings(response, @config.use_latest_settings, @config.symbolize_keys)
980
980
  end
981
981
 
982
982
  # Update some index settings. Only specified settings are overridden
@@ -987,7 +987,7 @@ module Algolia
987
987
  # @return [IndexingResponse]
988
988
  #
989
989
  def set_settings(settings, opts = {})
990
- response = @transporter.write(:PUT, path_encode('/1/indexes/%s/settings', @index_name), settings, opts)
990
+ response = @transporter.write(:PUT, path_encode('/1/indexes/%s/settings', @name), settings, opts)
991
991
 
992
992
  IndexingResponse.new(self, response)
993
993
  end
@@ -1087,7 +1087,7 @@ module Algolia
1087
1087
  end
1088
1088
 
1089
1089
  def raw_batch(requests, opts)
1090
- @transporter.write(:POST, path_encode('/1/indexes/%s/batch', @index_name), { requests: requests }, opts)
1090
+ @transporter.write(:POST, path_encode('/1/indexes/%s/batch', @name), { requests: requests }, opts)
1091
1091
  end
1092
1092
  end
1093
1093
  end
@@ -132,10 +132,10 @@ module Algolia
132
132
  # @return [Hash] merged headers
133
133
  #
134
134
  def generate_headers(request_options = {})
135
- headers = {}
136
- extra_headers = request_options.headers || {}
137
- @config.default_headers.each { |key, val| headers[key.to_s] = val }
138
- extra_headers.each { |key, val| headers[key.to_s] = val }
135
+ headers = {}
136
+ extra_headers = request_options.headers || {}
137
+ @config.headers.each { |key, val| headers[key.to_s] = val }
138
+ extra_headers.each { |key, val| headers[key.to_s] = val }
139
139
  if request_options.compression_type == Defaults::GZIP_ENCODING
140
140
  headers['Accept-Encoding'] = Defaults::GZIP_ENCODING
141
141
  end
@@ -1,3 +1,3 @@
1
1
  module Algolia
2
- VERSION = '2.0.0-alpha.2'.freeze
2
+ VERSION = '2.0.0-beta.3'.freeze
3
3
  end
@@ -1,11 +1,10 @@
1
1
  module Algolia
2
- # Class AlgoliaConfig
3
- class AlgoliaConfig
2
+ class BaseConfig
4
3
  attr_accessor app_id: String
5
4
 
6
5
  attr_accessor api_key: String
7
6
 
8
- attr_accessor default_headers: Hash[String, String]
7
+ attr_accessor headers: Hash[String, String]
9
8
 
10
9
  attr_accessor batch_size: Integer
11
10
 
@@ -20,5 +19,6 @@ module Algolia
20
19
  attr_accessor symbolize_keys: bool
21
20
 
22
21
  def initialize: (?::Hash[Symbol, String|[String]] opts) -> void
22
+ def set_extra_header: (Symbol|String key, String value) -> void
23
23
  end
24
24
  end
@@ -1,6 +1,6 @@
1
1
  module Algolia
2
2
  module Analytics
3
- class Config < AlgoliaConfig
3
+ class Config < BaseConfig
4
4
  attr_accessor region: String
5
5
 
6
6
  attr_accessor default_hosts: [String]
@@ -1,6 +1,6 @@
1
1
  module Algolia
2
2
  module Insights
3
- class Config < AlgoliaConfig
3
+ class Config < BaseConfig
4
4
  attr_accessor region: String
5
5
 
6
6
  attr_accessor default_hosts: [String]
@@ -1,6 +1,6 @@
1
1
  module Algolia
2
2
  module Recommendation
3
- class Config < AlgoliaConfig
3
+ class Config < BaseConfig
4
4
  attr_accessor region: String
5
5
 
6
6
  attr_accessor default_hosts: [String]
@@ -1,6 +1,6 @@
1
1
  module Algolia
2
2
  module Search
3
- class Config < AlgoliaConfig
3
+ class Config < BaseConfig
4
4
  include CallType
5
5
 
6
6
  attr_accessor default_hosts: Array[untyped]
@@ -11,14 +11,14 @@ class AnalyticsClientTest < BaseTest
11
11
  index1.save_object!({ objectID: 'one' })
12
12
  index2.save_object!({ objectID: 'one' })
13
13
 
14
- ab_test_name = index1.index_name
14
+ ab_test_name = index1.name
15
15
  tomorrow = Time.now + 24*60*60
16
16
 
17
17
  ab_test = {
18
18
  name: ab_test_name,
19
19
  variants: [
20
- { index: index1.index_name, trafficPercentage: 60, description: 'a description' },
21
- { index: index2.index_name, trafficPercentage: 40 }
20
+ { index: index1.name, trafficPercentage: 60, description: 'a description' },
21
+ { index: index2.name, trafficPercentage: 40 }
22
22
  ],
23
23
  endAt: tomorrow.strftime('%Y-%m-%dT%H:%M:%SZ')
24
24
  }
@@ -74,14 +74,14 @@ class AnalyticsClientTest < BaseTest
74
74
 
75
75
  index.save_object!({ objectID: 'one' })
76
76
 
77
- ab_test_name = index.index_name
77
+ ab_test_name = index.name
78
78
  tomorrow = Time.now + 24*60*60
79
79
 
80
80
  ab_test = {
81
81
  name: ab_test_name,
82
82
  variants: [
83
- { index: index.index_name, trafficPercentage: 90 },
84
- { index: index.index_name, trafficPercentage: 10, customSearchParameters: { ignorePlurals: true } }
83
+ { index: index.name, trafficPercentage: 90 },
84
+ { index: index.name, trafficPercentage: 10, customSearchParameters: { ignorePlurals: true } }
85
85
  ],
86
86
  endAt: tomorrow.strftime('%Y-%m-%dT%H:%M:%SZ')
87
87
  }
@@ -17,7 +17,7 @@ class InsightsClientTest < BaseTest
17
17
  client.send_event({
18
18
  eventType: 'click',
19
19
  eventName: 'foo',
20
- index: index.index_name,
20
+ index: index.name,
21
21
  userToken: 'bar',
22
22
  objectIDs: %w(one two),
23
23
  timestamp: (today - 2).strftime('%Q').to_i
@@ -27,14 +27,14 @@ class InsightsClientTest < BaseTest
27
27
  {
28
28
  eventType: 'click',
29
29
  eventName: 'foo',
30
- index: index.index_name,
30
+ index: index.name,
31
31
  userToken: 'bar',
32
32
  objectIDs: %w(one two),
33
33
  timestamp: (today - 2).strftime('%Q').to_i
34
34
  }, {
35
35
  eventType: 'click',
36
36
  eventName: 'foo',
37
- index: index.index_name,
37
+ index: index.name,
38
38
  userToken: 'bar',
39
39
  objectIDs: %w(one two),
40
40
  timestamp: (today - 2).strftime('%Q').to_i
@@ -42,37 +42,37 @@ class InsightsClientTest < BaseTest
42
42
  ])
43
43
 
44
44
  user_client = client.user('bar')
45
- response = user_client.clicked_object_ids('foo', index.index_name, %w(one two))
45
+ response = user_client.clicked_object_ids('foo', index.name, %w(one two))
46
46
  assert_equal 200, response[:status]
47
47
  assert_equal 'OK', response[:message]
48
48
 
49
49
  query_id = index.search('', { clickAnalytics: true })[:queryID]
50
50
 
51
- response = user_client.clicked_object_ids_after_search('foo', index.index_name, %w(one two), [1, 2], query_id)
51
+ response = user_client.clicked_object_ids_after_search('foo', index.name, %w(one two), [1, 2], query_id)
52
52
  assert_equal 200, response[:status]
53
53
  assert_equal 'OK', response[:message]
54
54
 
55
- response = user_client.clicked_filters('foo', index.index_name, %w(filter:foo filter:bar))
55
+ response = user_client.clicked_filters('foo', index.name, %w(filter:foo filter:bar))
56
56
  assert_equal 200, response[:status]
57
57
  assert_equal 'OK', response[:message]
58
58
 
59
- response = user_client.converted_object_ids('foo', index.index_name, %w(one two))
59
+ response = user_client.converted_object_ids('foo', index.name, %w(one two))
60
60
  assert_equal 200, response[:status]
61
61
  assert_equal 'OK', response[:message]
62
62
 
63
- response = user_client.converted_object_ids_after_search('foo', index.index_name, %w(one two), query_id)
63
+ response = user_client.converted_object_ids_after_search('foo', index.name, %w(one two), query_id)
64
64
  assert_equal 200, response[:status]
65
65
  assert_equal 'OK', response[:message]
66
66
 
67
- response = user_client.converted_filters('foo', index.index_name, %w(filter:foo filter:bar))
67
+ response = user_client.converted_filters('foo', index.name, %w(filter:foo filter:bar))
68
68
  assert_equal 200, response[:status]
69
69
  assert_equal 'OK', response[:message]
70
70
 
71
- response = user_client.viewed_object_ids('foo', index.index_name, %w(one two))
71
+ response = user_client.viewed_object_ids('foo', index.name, %w(one two))
72
72
  assert_equal 200, response[:status]
73
73
  assert_equal 'OK', response[:message]
74
74
 
75
- response = user_client.viewed_filters('foo', index.index_name, %w(filter:foo filter:bar))
75
+ response = user_client.viewed_filters('foo', index.name, %w(filter:foo filter:bar))
76
76
  assert_equal 200, response[:status]
77
77
  assert_equal 'OK', response[:message]
78
78
  end
@@ -80,10 +80,10 @@ class SearchClientTest < BaseTest
80
80
  copy_rules_index = @@search_client.init_index(get_test_index_name('copy_index_rules'))
81
81
  copy_synonyms_index = @@search_client.init_index(get_test_index_name('copy_index_synonyms'))
82
82
  copy_full_copy_index = @@search_client.init_index(get_test_index_name('copy_index_full_copy'))
83
- @@search_client.copy_settings!(@index_name, copy_settings_index.index_name)
84
- @@search_client.copy_rules!(@index_name, copy_rules_index.index_name)
85
- @@search_client.copy_synonyms!(@index_name, copy_synonyms_index.index_name)
86
- @@search_client.copy_index!(@index_name, copy_full_copy_index.index_name)
83
+ @@search_client.copy_settings!(@index_name, copy_settings_index.name)
84
+ @@search_client.copy_rules!(@index_name, copy_rules_index.name)
85
+ @@search_client.copy_synonyms!(@index_name, copy_synonyms_index.name)
86
+ @@search_client.copy_index!(@index_name, copy_full_copy_index.name)
87
87
 
88
88
  assert_equal @index.get_settings, copy_settings_index.get_settings
89
89
  assert_equal @index.get_rule(rule[:objectID]), copy_rules_index.get_rule(rule[:objectID])
@@ -93,7 +93,7 @@ class SearchClientTest < BaseTest
93
93
  assert_equal @index.get_synonym(synonym[:objectID]), copy_full_copy_index.get_synonym(synonym[:objectID])
94
94
 
95
95
  moved_index = @@search_client.init_index(get_test_index_name('move_index'))
96
- @@search_client.move_index!(@index_name, moved_index.index_name)
96
+ @@search_client.move_index!(@index_name, moved_index.name)
97
97
 
98
98
  moved_index.get_synonym('google_placeholder')
99
99
  moved_index.get_rule('company_auto_faceting')
@@ -233,7 +233,16 @@ class SearchClientTest < BaseTest
233
233
 
234
234
  assert_equal 'Key does not exist', exception.message
235
235
 
236
- @@search_client.restore_api_key!(@api_key[:value])
236
+ loop do
237
+ begin
238
+ @@search_client.restore_api_key!(@api_key[:value])
239
+ break
240
+ rescue Algolia::AlgoliaHttpError => e
241
+ if e.code != 404
242
+ raise StandardError
243
+ end
244
+ end
245
+ end
237
246
 
238
247
  restored_key = @@search_client.get_api_key(@api_key[:value])
239
248
 
@@ -261,8 +270,8 @@ class SearchClientTest < BaseTest
261
270
  end
262
271
 
263
272
  def test_multiple_operations
264
- index_name1 = @index1.index_name
265
- index_name2 = @index2.index_name
273
+ index_name1 = @index1.name
274
+ index_name2 = @index2.name
266
275
 
267
276
  response = @@search_client.multiple_batch!([
268
277
  { indexName: index_name1, action: 'addObject', body: { firstname: 'Jimmie' } },
@@ -317,12 +326,12 @@ class SearchClientTest < BaseTest
317
326
  now = Time.now.to_i
318
327
  secured_api_key = Algolia::Search::Client.generate_secured_api_key(SEARCH_KEY_1, {
319
328
  validUntil: now + (10 * 60),
320
- restrictIndices: @index1.index_name
329
+ restrictIndices: @index1.name
321
330
  })
322
331
 
323
332
  secured_client = Algolia::Search::Client.create(APPLICATION_ID_1, secured_api_key)
324
- secured_index1 = secured_client.init_index(@index1.index_name)
325
- secured_index2 = secured_client.init_index(@index2.index_name)
333
+ secured_index1 = secured_client.init_index(@index1.name)
334
+ secured_index2 = secured_client.init_index(@index2.name)
326
335
 
327
336
  secured_index1.search('')
328
337
  exception = assert_raises Algolia::AlgoliaHttpError do
@@ -0,0 +1,16 @@
1
+ require 'algolia'
2
+ require 'test_helper'
3
+
4
+ class AlgoliaConfigTest
5
+ describe 'set an extra header' do
6
+ def before_all
7
+ @config = Algolia::BaseConfig.new(application_id: 'app_id', api_key: 'api_key')
8
+ end
9
+
10
+ def test_set_extra_header
11
+ @config.set_extra_header('foo', 'bar')
12
+ assert @config.headers['foo']
13
+ assert_equal @config.headers['foo'], 'bar'
14
+ end
15
+ end
16
+ end
@@ -18,7 +18,35 @@ class HelpersTest
18
18
  replicas: %w(index1 index2)
19
19
  }
20
20
 
21
- deserialized_settings = deserialize_settings(old_settings)
21
+ deserialized_settings = deserialize_settings(old_settings, true, true)
22
+ assert_equal new_settings, deserialized_settings
23
+ end
24
+
25
+ def test_deserialize_settings_with_old_settings
26
+ old_settings = {
27
+ attributesToIndex: %w(attr1 attr2),
28
+ numericAttributesToIndex: %w(attr1 attr2),
29
+ slaves: %w(index1 index2)
30
+ }
31
+
32
+ deserialized_settings = deserialize_settings(old_settings, false, true)
33
+ assert_equal old_settings, deserialized_settings
34
+ end
35
+
36
+ def test_deserialize_settings_with_string
37
+ old_settings = {
38
+ 'attributesToIndex' => %w(attr1 attr2),
39
+ 'numericAttributesToIndex' => %w(attr1 attr2),
40
+ 'slaves' => %w(index1 index2)
41
+ }
42
+
43
+ new_settings = {
44
+ 'searchableAttributes' => %w(attr1 attr2),
45
+ 'numericAttributesForFiltering' => %w(attr1 attr2),
46
+ 'replicas' => %w(index1 index2)
47
+ }
48
+
49
+ deserialized_settings = deserialize_settings(old_settings, true, false)
22
50
  assert_equal new_settings, deserialized_settings
23
51
  end
24
52
  end
@@ -13,7 +13,7 @@ class RetryStrategyTest
13
13
  stateful_hosts << "#{@app_id}-4.algolianet.com"
14
14
  stateful_hosts << "#{@app_id}-5.algolianet.com"
15
15
  stateful_hosts << "#{@app_id}-6.algolianet.com"
16
- @config = Algolia::Search::Config.new(app_id: @app_id, api_key: @api_key, custom_hosts: stateful_hosts)
16
+ @config = Algolia::Search::Config.new(application_id: @app_id, api_key: @api_key, custom_hosts: stateful_hosts)
17
17
  end
18
18
 
19
19
  def test_resets_expired_hosts_according_to_read_type
@@ -74,7 +74,7 @@ class RetryStrategyTest
74
74
  describe 'All hosts are unreachable' do
75
75
  def test_failure_when_all_hosts_are_down
76
76
  stateful_hosts = ['0.0.0.0']
77
- @config = Algolia::Search::Config.new(app_id: 'foo', api_key: 'bar', custom_hosts: stateful_hosts)
77
+ @config = Algolia::Search::Config.new(application_id: 'foo', api_key: 'bar', custom_hosts: stateful_hosts)
78
78
  client = Algolia::Search::Client.create_with_config(@config)
79
79
  index = client.init_index(get_test_index_name('failure'))
80
80
 
@@ -91,7 +91,7 @@ class RetryStrategyTest
91
91
  super
92
92
  @app_id = 'app_id'
93
93
  @api_key = 'api_key'
94
- @config = Algolia::Search::Config.new(app_id: @app_id, api_key: @api_key)
94
+ @config = Algolia::Search::Config.new(application_id: @app_id, api_key: @api_key)
95
95
  @retry_strategy = Algolia::Transport::RetryStrategy.new(@config)
96
96
  @hosts = @retry_strategy.get_tryable_hosts(READ|WRITE)
97
97
  end
@@ -24,7 +24,7 @@ class Minitest::Test
24
24
 
25
25
  include Minitest::Hooks
26
26
  include Helpers
27
- @@search_config = Algolia::Search::Config.new(app_id: APPLICATION_ID_1, api_key: ADMIN_KEY_1, user_agent: USER_AGENT)
27
+ @@search_config = Algolia::Search::Config.new(application_id: APPLICATION_ID_1, api_key: ADMIN_KEY_1, user_agent: USER_AGENT)
28
28
  @@search_client = Algolia::Search::Client.new(@@search_config)
29
29
  end
30
30
 
@@ -5,7 +5,7 @@ First, you'll have to include the new version in your Gemfile. To do so, change
5
5
 
6
6
  ```diff
7
7
  - gem 'algoliasearch'
8
- + gem 'algolia', git: 'https://github.com/algolia/algoliasearch-client-ruby.git', tag: 'v2.0.0-alpha.1'
8
+ + gem 'algolia', git: 'https://github.com/algolia/algoliasearch-client-ruby.git', tag: 'v2.0.0-beta.1'
9
9
  ```
10
10
 
11
11
  Then, you'll need to change your current `require` statements:
@@ -38,11 +38,17 @@ index = client.init_index('index_name')
38
38
  client = Algolia::Search::Client.create('APP_ID', 'API_KEY')
39
39
  index = client.init_index('index_name')
40
40
  # or
41
- search_config = Algolia::Search::Config.new(app_id: app_id, api_key: api_key)
41
+ search_config = Algolia::Search::Config.new(application_id: app_id, api_key: api_key)
42
42
  client = Algolia::Search::Client.create_with_config(search_config)
43
43
  index = client.init_index('index_name')
44
44
  ```
45
45
 
46
+ By default the keys of the response hashes are symbols. If you wish to change that for strings, use the following configuration
47
+ ```ruby
48
+ search_config = Algolia::Search::Config.new(application_id: app_id, api_key: api_key, symbolize_keys: false)
49
+ client = Algolia::Search::Client.create_with_config(search_config)
50
+ ```
51
+
46
52
  ## Search parameters and request options
47
53
  The search parameters and request options are still optional, but they are combined into a single hash instead of two.
48
54
  For example:
@@ -55,12 +61,8 @@ index.search('query', search_params, request_opts)
55
61
 
56
62
  # After
57
63
  opts = {
58
- :headers => {
59
- 'X-Algolia-UserToken': 'user123'
60
- },
61
- :params => {
62
- hitsPerPage: 50
63
- }
64
+ headers: { 'X-Algolia-UserToken': 'user123' },
65
+ hitsPerPage: 50
64
66
  }
65
67
  index.search('query', opts)
66
68
  ```
@@ -69,6 +71,20 @@ index.search('query', opts)
69
71
 
70
72
  ### `Client`
71
73
 
74
+ #### `set_extra_header`
75
+ The `set_extra_header` method has been moved from the Client to the `Algolia::BaseConfig` class. You have to define your extra headers on Client instantiation.
76
+ ```ruby
77
+ # Before
78
+ client.set_extra_header('admin', 'admin-key')
79
+
80
+ # After
81
+ # `Algolia::Search::Config` inherits from `Algolia::BaseConfig`
82
+ config = Algolia::Search::Config.new(app_id: 'APP_ID', api_key: 'API_KEY')
83
+ config.set_extra_header('admin', 'admin-key')
84
+
85
+ client = Algolia::Search::Client.create_with_config(config)
86
+ ```
87
+
72
88
  #### `multiple_queries`
73
89
  The `strategy` parameter is no longer a string, but a key in the `requestOptions`.
74
90
  ```ruby
@@ -244,12 +260,8 @@ index.search('query', search_params, request_opts)
244
260
 
245
261
  # After
246
262
  opts = {
247
- :headers => {
248
- 'X-Algolia-UserToken': 'user123'
249
- },
250
- :params => {
251
- hitsPerPage: 50
252
- }
263
+ headers: { 'X-Algolia-UserToken': 'user123' },
264
+ hitsPerPage: 50
253
265
  }
254
266
  index.search('query', opts)
255
267
  ```
@@ -265,12 +277,8 @@ index.search_for_facet_values('category', 'phone', search_params, request_opts)
265
277
 
266
278
  # After
267
279
  opts = {
268
- :headers => {
269
- 'X-Algolia-UserToken': 'user123'
270
- },
271
- :params => {
272
- hitsPerPage: 50
273
- }
280
+ headers: { 'X-Algolia-UserToken': 'user123' },
281
+ hitsPerPage: 50
274
282
  }
275
283
  index.search_for_facet_values('category', 'phone', opts)
276
284
  ```
@@ -590,6 +598,6 @@ client = Algolia::Client.new({
590
598
  })
591
599
 
592
600
  # After
593
- search_config = Algolia::Search::Config.new(app_id: 'app_id', api_key: 'api_key', read_timeout: 10, connect_timeout: 2)
601
+ search_config = Algolia::Search::Config.new(application_id: 'app_id', api_key: 'api_key', read_timeout: 10, connect_timeout: 2)
594
602
  client = Algolia::Search::Client.create_with_config(search_config)
595
603
  ```
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.0.0.pre.alpha.2
4
+ version: 2.0.0.pre.beta.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-21 00:00:00.000000000 Z
11
+ date: 2020-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -178,7 +178,8 @@ dependencies:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
- description: A simple Ruby client for the algolia.com REST API
181
+ description: This is the alpha version of the upcoming v2 release of Algolia Client.
182
+ Please keep on using the algoliasearch gem in the meantime.
182
183
  email:
183
184
  - support@algolia.com
184
185
  executables: []
@@ -203,8 +204,8 @@ files:
203
204
  - lib/algolia.rb
204
205
  - lib/algolia/account_client.rb
205
206
  - lib/algolia/analytics_client.rb
206
- - lib/algolia/config/algolia_config.rb
207
207
  - lib/algolia/config/analytics_config.rb
208
+ - lib/algolia/config/base_config.rb
208
209
  - lib/algolia/config/insights_config.rb
209
210
  - lib/algolia/config/recommendation_config.rb
210
211
  - lib/algolia/config/search_config.rb
@@ -264,16 +265,20 @@ files:
264
265
  - test/algolia/integration/recommendation_client_test.rb
265
266
  - test/algolia/integration/search_client_test.rb
266
267
  - test/algolia/integration/search_index_test.rb
268
+ - test/algolia/unit/algolia_config_test.rb
267
269
  - test/algolia/unit/helpers_test.rb
268
270
  - test/algolia/unit/retry_strategy_test.rb
269
271
  - test/algolia/unit/user_agent_test.rb
270
272
  - test/test_helper.rb
271
273
  - upgrade_guide.md
272
- homepage:
274
+ homepage: https://github.com/algolia/algoliasearch-client-ruby/tree/release/v2
273
275
  licenses:
274
276
  - MIT
275
- metadata: {}
276
- post_install_message:
277
+ metadata:
278
+ bug_tracker_uri: https://github.com/algolia/algoliasearch-client-ruby/issues
279
+ documentation_uri: http://www.rubydoc.info/gems/algolia
280
+ source_code_uri: https://github.com/algolia/algoliasearch-client-ruby/tree/release/v2
281
+ post_install_message:
277
282
  rdoc_options: []
278
283
  require_paths:
279
284
  - lib
@@ -288,10 +293,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
288
293
  - !ruby/object:Gem::Version
289
294
  version: 1.3.1
290
295
  requirements: []
291
- rubygems_version: 3.0.4
292
- signing_key:
296
+ rubygems_version: 3.0.3
297
+ signing_key:
293
298
  specification_version: 4
294
- summary: A simple Ruby client for the algolia.com REST API
299
+ summary: A simple Ruby client for the algolia.com REST API (alpha release)
295
300
  test_files:
296
301
  - test/algolia/integration/account_client_test.rb
297
302
  - test/algolia/integration/analytics_client_test.rb
@@ -301,6 +306,7 @@ test_files:
301
306
  - test/algolia/integration/recommendation_client_test.rb
302
307
  - test/algolia/integration/search_client_test.rb
303
308
  - test/algolia/integration/search_index_test.rb
309
+ - test/algolia/unit/algolia_config_test.rb
304
310
  - test/algolia/unit/helpers_test.rb
305
311
  - test/algolia/unit/retry_strategy_test.rb
306
312
  - test/algolia/unit/user_agent_test.rb
@@ -1,40 +0,0 @@
1
- require 'faraday'
2
-
3
- module Algolia
4
- # Class AlgoliaConfig
5
- class AlgoliaConfig
6
- attr_accessor :app_id, :api_key, :default_headers, :batch_size, :read_timeout, :write_timeout, :connect_timeout, :compression_type,
7
- :symbolize_keys
8
-
9
- #
10
- # @option options [String] :app_id
11
- # @option options [String] :api_key
12
- # @option options [Integer] :batch_size
13
- # @option options [Integer] :read_timeout
14
- # @option options [Integer] :write_timeout
15
- # @option options [Integer] :connect_timeout
16
- # @option options [Boolean] :symbolize_keys
17
- #
18
- def initialize(opts = {})
19
- raise AlgoliaError, 'No Application ID provided, please set :app_id' unless opts.has_key?(:app_id)
20
- raise AlgoliaError, 'No API key provided, please set :api_key' unless opts.has_key?(:api_key)
21
-
22
- @app_id = opts[:app_id]
23
- @api_key = opts[:api_key]
24
-
25
- @default_headers = {
26
- Defaults::HEADER_API_KEY => @api_key,
27
- Defaults::HEADER_APP_ID => @app_id,
28
- 'Content-Type' => 'application/json; charset=utf-8',
29
- 'User-Agent' => UserAgent.value
30
- }
31
-
32
- @batch_size = opts[:batch_size] || Defaults::BATCH_SIZE
33
- @read_timeout = opts[:read_timeout] || Defaults::READ_TIMEOUT
34
- @write_timeout = opts[:write_timeout] || Defaults::WRITE_TIMEOUT
35
- @connect_timeout = opts[:connect_timeout] || Defaults::CONNECT_TIMEOUT
36
- @compression_type = opts[:compression_type] || Defaults::NONE_ENCODING
37
- @symbolize_keys = opts[:symbolize_keys] || true
38
- end
39
- end
40
- end