algolia 2.0.0.pre.alpha.4 → 2.0.0.pre.beta.1

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: 7b7285aa2d0c5d3f32f0c0e2182770d1688f39fb4769a2d897dbe578492aa9a6
4
- data.tar.gz: 3f063a3f2fcb9fecd8a0c28e5dc7f7bf4debef1e3280f1f2253dd20f5547c4ad
3
+ metadata.gz: 70ae2ec824eed001a361d702826ad88956c6b580793bc8bb3aceda020ea8e8ea
4
+ data.tar.gz: bbed7b37901bf59cbc1cbf172a4ec9fa06df026988187cd1ea78fd6a3cf9dae4
5
5
  SHA512:
6
- metadata.gz: 057f6322482a476f9f1a25c4e75de3c2bc31cdfc7cf5fec672095c3fe195e7ace87e1d1476fe3b64c2884bff32df80c6814017768c943a74d2836de9e952d4a9
7
- data.tar.gz: 7d0387f4663c6767ec40f68b229551e8c28da47a44bcd34f369a3cc6ad84fa2ad25f898bc65e0350a44c6f06b5901625a06bdb42f9a29824da8f3b8762c319ef
6
+ metadata.gz: 253ebb7ccb0745b17f72526df5656ba58eb800c3ce973eaffe52e6f098758def22d425c77fe6b07f882733551d3d01f081ff80b4be6b900f7ccfcac3a2926edf
7
+ data.tar.gz: a5e231f9bd48361cfe12fa5b74234ad899b6ac1dbd2b46dc0b4f69a76532bebb7cc1e0f7eb9abf7930693422a124c7eb5e5f18b5798beb3eb9edd6463779d3b7
@@ -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
 
@@ -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
  #
@@ -1,13 +1,12 @@
1
1
  require 'faraday'
2
2
 
3
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,
4
+ class BaseConfig
5
+ attr_accessor :app_id, :api_key, :headers, :batch_size, :read_timeout, :write_timeout, :connect_timeout, :compression_type,
7
6
  :symbolize_keys
8
7
 
9
8
  #
10
- # @option options [String] :app_id
9
+ # @option options [String] :application_id
11
10
  # @option options [String] :api_key
12
11
  # @option options [Integer] :batch_size
13
12
  # @option options [Integer] :read_timeout
@@ -16,13 +15,13 @@ module Algolia
16
15
  # @option options [Boolean] :symbolize_keys
17
16
  #
18
17
  def initialize(opts = {})
19
- raise AlgoliaError, 'No Application ID provided, please set :app_id' unless opts.has_key?(:app_id)
18
+ raise AlgoliaError, 'No Application ID provided, please set :application_id' unless opts.has_key?(:application_id)
20
19
  raise AlgoliaError, 'No API key provided, please set :api_key' unless opts.has_key?(:api_key)
21
20
 
22
- @app_id = opts[:app_id]
21
+ @app_id = opts[:application_id]
23
22
  @api_key = opts[:api_key]
24
23
 
25
- @default_headers = {
24
+ @headers = {
26
25
  Defaults::HEADER_API_KEY => @api_key,
27
26
  Defaults::HEADER_APP_ID => @app_id,
28
27
  'Content-Type' => 'application/json; charset=utf-8',
@@ -36,5 +35,9 @@ module Algolia
36
35
  @compression_type = opts[:compression_type] || Defaults::NONE_ENCODING
37
36
  @symbolize_keys = opts[:symbolize_keys] || true
38
37
  end
38
+
39
+ def set_extra_header(key, value)
40
+ @headers[key] = value
41
+ end
39
42
  end
40
43
  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
@@ -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
 
@@ -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
@@ -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,7 +974,7 @@ 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
979
  deserialize_settings(response)
980
980
  end
@@ -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.4'.freeze
2
+ VERSION = '2.0.0-beta.1'.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::AlgoliaConfig.new(app_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
@@ -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,7 +38,7 @@ 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
  ```
@@ -55,12 +55,8 @@ index.search('query', search_params, request_opts)
55
55
 
56
56
  # After
57
57
  opts = {
58
- :headers => {
59
- 'X-Algolia-UserToken': 'user123'
60
- },
61
- :params => {
62
- hitsPerPage: 50
63
- }
58
+ headers: { 'X-Algolia-UserToken': 'user123' },
59
+ hitsPerPage: 50
64
60
  }
65
61
  index.search('query', opts)
66
62
  ```
@@ -69,6 +65,20 @@ index.search('query', opts)
69
65
 
70
66
  ### `Client`
71
67
 
68
+ #### `set_extra_header`
69
+ The `set_extra_header` method has been moved from the Client to the `Algolia::AlgoliaConfig` class. You have to define your extra headers on Client instantiation.
70
+ ```ruby
71
+ # Before
72
+ client.set_extra_header('admin', 'admin-key')
73
+
74
+ # After
75
+ # `Algolia::Search::Config` inherits from `Algolia::AlgoliaConfig`
76
+ config = Algolia::Search::Config.new(app_id: 'APP_ID', api_key: 'API_KEY')
77
+ config.set_extra_header('admin', 'admin-key')
78
+
79
+ client = Algolia::Search::Client.create_with_config(config)
80
+ ```
81
+
72
82
  #### `multiple_queries`
73
83
  The `strategy` parameter is no longer a string, but a key in the `requestOptions`.
74
84
  ```ruby
@@ -244,12 +254,8 @@ index.search('query', search_params, request_opts)
244
254
 
245
255
  # After
246
256
  opts = {
247
- :headers => {
248
- 'X-Algolia-UserToken': 'user123'
249
- },
250
- :params => {
251
- hitsPerPage: 50
252
- }
257
+ headers: { 'X-Algolia-UserToken': 'user123' },
258
+ hitsPerPage: 50
253
259
  }
254
260
  index.search('query', opts)
255
261
  ```
@@ -265,12 +271,8 @@ index.search_for_facet_values('category', 'phone', search_params, request_opts)
265
271
 
266
272
  # After
267
273
  opts = {
268
- :headers => {
269
- 'X-Algolia-UserToken': 'user123'
270
- },
271
- :params => {
272
- hitsPerPage: 50
273
- }
274
+ headers: { 'X-Algolia-UserToken': 'user123' },
275
+ hitsPerPage: 50
274
276
  }
275
277
  index.search_for_facet_values('category', 'phone', opts)
276
278
  ```
@@ -590,6 +592,6 @@ client = Algolia::Client.new({
590
592
  })
591
593
 
592
594
  # After
593
- search_config = Algolia::Search::Config.new(app_id: 'app_id', api_key: 'api_key', read_timeout: 10, connect_timeout: 2)
595
+ search_config = Algolia::Search::Config.new(application_id: 'app_id', api_key: 'api_key', read_timeout: 10, connect_timeout: 2)
594
596
  client = Algolia::Search::Client.create_with_config(search_config)
595
597
  ```
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.4
4
+ version: 2.0.0.pre.beta.1
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-22 00:00:00.000000000 Z
11
+ date: 2020-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -204,8 +204,8 @@ files:
204
204
  - lib/algolia.rb
205
205
  - lib/algolia/account_client.rb
206
206
  - lib/algolia/analytics_client.rb
207
- - lib/algolia/config/algolia_config.rb
208
207
  - lib/algolia/config/analytics_config.rb
208
+ - lib/algolia/config/base_config.rb
209
209
  - lib/algolia/config/insights_config.rb
210
210
  - lib/algolia/config/recommendation_config.rb
211
211
  - lib/algolia/config/search_config.rb
@@ -265,6 +265,7 @@ files:
265
265
  - test/algolia/integration/recommendation_client_test.rb
266
266
  - test/algolia/integration/search_client_test.rb
267
267
  - test/algolia/integration/search_index_test.rb
268
+ - test/algolia/unit/algolia_config_test.rb
268
269
  - test/algolia/unit/helpers_test.rb
269
270
  - test/algolia/unit/retry_strategy_test.rb
270
271
  - test/algolia/unit/user_agent_test.rb
@@ -277,7 +278,7 @@ metadata:
277
278
  bug_tracker_uri: https://github.com/algolia/algoliasearch-client-ruby/issues
278
279
  documentation_uri: http://www.rubydoc.info/gems/algolia
279
280
  source_code_uri: https://github.com/algolia/algoliasearch-client-ruby/tree/release/v2
280
- post_install_message:
281
+ post_install_message:
281
282
  rdoc_options: []
282
283
  require_paths:
283
284
  - lib
@@ -292,8 +293,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
292
293
  - !ruby/object:Gem::Version
293
294
  version: 1.3.1
294
295
  requirements: []
295
- rubygems_version: 3.0.4
296
- signing_key:
296
+ rubygems_version: 3.0.3
297
+ signing_key:
297
298
  specification_version: 4
298
299
  summary: A simple Ruby client for the algolia.com REST API (alpha release)
299
300
  test_files:
@@ -305,6 +306,7 @@ test_files:
305
306
  - test/algolia/integration/recommendation_client_test.rb
306
307
  - test/algolia/integration/search_client_test.rb
307
308
  - test/algolia/integration/search_index_test.rb
309
+ - test/algolia/unit/algolia_config_test.rb
308
310
  - test/algolia/unit/helpers_test.rb
309
311
  - test/algolia/unit/retry_strategy_test.rb
310
312
  - test/algolia/unit/user_agent_test.rb