algolia 2.0.0.pre.beta.1 → 2.0.2

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: 70ae2ec824eed001a361d702826ad88956c6b580793bc8bb3aceda020ea8e8ea
4
- data.tar.gz: bbed7b37901bf59cbc1cbf172a4ec9fa06df026988187cd1ea78fd6a3cf9dae4
3
+ metadata.gz: b0246ce68c04f74cbc9e5556fc6ce0732168ae80854fad5bb3c16cc136c5313f
4
+ data.tar.gz: b8d46fda53509732a442547eda0b1b8087127380bf4b628461aee491e85736bc
5
5
  SHA512:
6
- metadata.gz: 253ebb7ccb0745b17f72526df5656ba58eb800c3ce973eaffe52e6f098758def22d425c77fe6b07f882733551d3d01f081ff80b4be6b900f7ccfcac3a2926edf
7
- data.tar.gz: a5e231f9bd48361cfe12fa5b74234ad899b6ac1dbd2b46dc0b4f69a76532bebb7cc1e0f7eb9abf7930693422a124c7eb5e5f18b5798beb3eb9edd6463779d3b7
6
+ metadata.gz: dc78357744b82ccea9963df689b6bfce71125cde45c7605b348cb38210ca028a681c57ad9e422add37c33a1a0394681bec958e3a50a1690128b727a2d5406099
7
+ data.tar.gz: f56ffd3e67ca4072024f99e24447ecac30a34d252893cc585e467a6589f5ce7331f9e80cc98fe4188ea0a01d325c9f0b6cfac7a689565cbda785c5a077510692
data/.gitignore CHANGED
@@ -35,4 +35,5 @@ pkg
35
35
  Gemfile.lock
36
36
  spec/integration_spec_conf.rb
37
37
  data.sqlite3
38
+
38
39
  debug.log
@@ -0,0 +1,16 @@
1
+ # ChangeLog
2
+
3
+ ## Unreleased
4
+
5
+ ## [2.0.2](https://github.com/algolia/algoliasearch-client-ruby/releases/tag/2.0.2) (2020-11-09)
6
+
7
+ * Fix: don't mutate index name on stripping
8
+
9
+ ## [2.0.1](https://github.com/algolia/algoliasearch-client-ruby/releases/tag/2.0.1) (2020-11-02)
10
+
11
+ * Fix: simplify merge of headers in `Transport` class
12
+ * Fix: `deserialize_settings` function to take into account `symbolize_keys` parameter
13
+
14
+ ## [2.0.0](https://github.com/algolia/algoliasearch-client-ruby/releases/tag/2.0.0) (2020-10-27)
15
+
16
+ * Initial release of v2
data/README.md CHANGED
@@ -6,9 +6,9 @@
6
6
  <h4 align="center">The perfect starting point to integrate <a href="https://algolia.com" target="_blank">Algolia</a> within your Ruby project</h4>
7
7
 
8
8
  <p align="center">
9
- <a href="https://circleci.com/gh/algolia/algoliasearch-client-ruby/tree/release%2Fv2"><img src="https://circleci.com/gh/algolia/algoliasearch-client-ruby/tree/release%2Fv2.svg?style=shield" alt="CircleCI" /></a>
10
- <a href="https://rubygems.org/gems/algoliasearch"><img src="https://badge.fury.io/rb/algoliasearch.svg" alt="Gem Version"></a>
11
- <a href="https://rubygems.org/gems/algoliasearch"><img src="https://img.shields.io/badge/licence-MIT-blue.svg" alt="License"></a>
9
+ <a href="https://circleci.com/gh/algolia/algoliasearch-client-ruby"><img src="https://circleci.com/gh/algolia/algoliasearch-client-ruby.svg?style=shield" alt="CircleCI" /></a>
10
+ <a href="https://rubygems.org/gems/algolia"><img src="https://badge.fury.io/rb/algolia.svg" alt="Gem Version"></a>
11
+ <a href="https://rubygems.org/gems/algolia"><img src="https://img.shields.io/badge/licence-MIT-blue.svg" alt="License"></a>
12
12
  </p>
13
13
  </p>
14
14
 
@@ -18,39 +18,47 @@
18
18
  <a href="https://discourse.algolia.com" target="_blank">Community Forum</a> •
19
19
  <a href="http://stackoverflow.com/questions/tagged/algolia" target="_blank">Stack Overflow</a> •
20
20
  <a href="https://github.com/algolia/algoliasearch-client-ruby/issues" target="_blank">Report a bug</a> •
21
+ <a href="https://www.algolia.com/doc/api-client/troubleshooting/faq/ruby/" target="_blank">FAQ</a> •
21
22
  <a href="https://www.algolia.com/support" target="_blank">Support</a>
22
23
  </p>
23
24
 
24
25
  ## ✨ Features
25
26
 
26
27
  - Thin & minimal low-level HTTP client to interact with Algolia's API
27
- - Supports Ruby `^1.8.7`.
28
+ - Supports Ruby `^2.2`.
28
29
 
29
30
  ## 💡 Getting Started
30
31
 
31
32
  First, install Algolia Ruby API Client via the [RubyGems](https://rubygems.org/) package manager:
32
33
  ```bash
33
- gem install algoliasearch
34
+ gem install algolia
34
35
  ```
35
36
 
36
37
  Then, create objects on your index:
37
38
 
38
39
 
39
40
  ```ruby
40
- Algolia.init(application_id: 'YourApplicationID',
41
- api_key: 'YourAPIKey')
42
- index = Algolia::Index.new('your_index_name')
41
+ client = Algolia::Search::Client.create('YourApplicationID', 'YourAPIKey')
42
+ index = client.init_index('your_index_name')
43
43
 
44
- index.save_objects([objectID: 1, name: 'Foo'])
44
+ index.save_objects([objectID: 1, name: 'Foo'])
45
45
  ```
46
46
 
47
47
  Finally, you may begin searching a object using the `search` method:
48
48
  ```ruby
49
- objects = index.search('Fo')
49
+ objects = index.search('Foo')
50
50
  ```
51
51
 
52
52
  For full documentation, visit the **[Algolia Ruby API Client](https://www.algolia.com/doc/api-client/getting-started/install/ruby/)**.
53
53
 
54
+ ## ❓ Troubleshooting
55
+
56
+ Encountering an issue? Before reaching out to support, we recommend heading to our [FAQ](https://www.algolia.com/doc/api-client/troubleshooting/faq/ruby/) where you will find answers for the most common issues and gotchas with the client.
57
+
58
+ ## Upgrade from V1 to V2
59
+
60
+ If you were using the v1 and wish to update to v2, please follow our [Upgrade Guide](upgrade_guide.md)
61
+
54
62
  ## 📄 License
55
63
 
56
64
  Algolia Ruby API Client is an open-sourced software licensed under the [MIT license](LICENSE.md).
@@ -0,0 +1,3 @@
1
+ ## Reporting a Vulnerability
2
+
3
+ To report a security vulnerability, please use the [Algolia security email](security@algolia.com). Algolia will coordinate the fix and disclosure.
@@ -12,14 +12,14 @@ 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 (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'
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'
17
+ spec.homepage = 'https://github.com/algolia/algoliasearch-client-ruby'
18
18
 
19
19
  spec.metadata = {
20
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'
21
+ 'documentation_uri' => 'https://www.algolia.com/doc/api-client/getting-started/install/ruby',
22
+ 'source_code_uri' => 'https://github.com/algolia/algoliasearch-client-ruby'
23
23
  }
24
24
 
25
25
  # Specify which files should be added to the gem when it is released.
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency 'rake'
36
36
  spec.add_development_dependency 'rubocop', '<= 0.82.0'
37
37
 
38
- spec.add_dependency 'faraday', '~> 0.15'
38
+ spec.add_dependency 'faraday', ['>= 0.15', '< 2.0']
39
39
  spec.add_dependency 'multi_json', '~> 1.0'
40
40
  spec.add_dependency 'net-http-persistent'
41
41
 
@@ -3,7 +3,7 @@ require 'faraday'
3
3
  module Algolia
4
4
  class BaseConfig
5
5
  attr_accessor :app_id, :api_key, :headers, :batch_size, :read_timeout, :write_timeout, :connect_timeout, :compression_type,
6
- :symbolize_keys
6
+ :symbolize_keys, :use_latest_settings
7
7
 
8
8
  #
9
9
  # @option options [String] :application_id
@@ -28,12 +28,12 @@ module Algolia
28
28
  'User-Agent' => UserAgent.value
29
29
  }
30
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[:symbolize_keys] || true
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
37
  end
38
38
 
39
39
  def set_extra_header(key, value)
@@ -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,8 +52,8 @@ module Helpers
52
52
 
53
53
  # Support to convert old settings to their new names
54
54
  #
55
- def deserialize_settings(data)
56
- settings = symbolize_hash(data)
55
+ def deserialize_settings(data, symbolize_keys)
56
+ settings = data
57
57
  keys = {
58
58
  attributesToIndex: 'searchableAttributes',
59
59
  numericAttributesToIndex: 'numericAttributesForFiltering',
@@ -61,8 +61,10 @@ module Helpers
61
61
  }
62
62
 
63
63
  keys.each do |deprecated_key, current_key|
64
+ deprecated_key = symbolize_keys ? deprecated_key : deprecated_key.to_s
64
65
  if settings.has_key?(deprecated_key)
65
- settings[current_key.to_sym] = settings.delete(deprecated_key)
66
+ key = symbolize_keys ? current_key.to_sym : current_key.to_s
67
+ settings[key] = settings.delete(deprecated_key)
66
68
  end
67
69
  end
68
70
 
@@ -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,
@@ -90,11 +90,11 @@ module Algolia
90
90
  # @return [Index] new Index instance
91
91
  #
92
92
  def init_index(index_name)
93
- index_name.strip!
94
- if index_name.empty?
93
+ stripped_index_name = index_name.strip
94
+ if stripped_index_name.empty?
95
95
  raise AlgoliaError, 'Please provide a valid index name'
96
96
  end
97
- Index.new(index_name, @transporter, @config)
97
+ Index.new(stripped_index_name, @transporter, @config)
98
98
  end
99
99
 
100
100
  # List all indexes of the client
@@ -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)
@@ -976,7 +976,7 @@ module Algolia
976
976
  def get_settings(opts = {})
977
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.symbolize_keys)
980
980
  end
981
981
 
982
982
  # Update some index settings. Only specified settings are overridden
@@ -34,7 +34,7 @@ module Algolia
34
34
  def add_headers(opts = {})
35
35
  unless opts[:headers].nil?
36
36
  opts[:headers].each do |opt, value|
37
- @headers[opt.to_sym] = value
37
+ @headers[opt.to_s] = value
38
38
  end
39
39
  opts.delete(:headers)
40
40
  end
@@ -127,15 +127,12 @@ module Algolia
127
127
 
128
128
  # Generates headers from config headers and optional parameters
129
129
  #
130
- # @option options [String] :headers
130
+ # @param request_options [RequestOptions]
131
131
  #
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.headers.each { |key, val| headers[key.to_s] = val }
138
- extra_headers.each { |key, val| headers[key.to_s] = val }
135
+ headers = @config.headers.merge(request_options.headers)
139
136
  if request_options.compression_type == Defaults::GZIP_ENCODING
140
137
  headers['Accept-Encoding'] = Defaults::GZIP_ENCODING
141
138
  end
@@ -1,3 +1,3 @@
1
1
  module Algolia
2
- VERSION = '2.0.0-beta.1'.freeze
2
+ VERSION = '2.0.2'.freeze
3
3
  end
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
  class AlgoliaConfigTest
5
5
  describe 'set an extra header' do
6
6
  def before_all
7
- @config = Algolia::AlgoliaConfig.new(app_id: 'app_id', api_key: 'api_key')
7
+ @config = Algolia::BaseConfig.new(application_id: 'app_id', api_key: 'api_key')
8
8
  end
9
9
 
10
10
  def test_set_extra_header
@@ -18,7 +18,26 @@ 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)
22
+ assert_equal new_settings, deserialized_settings
23
+ end
24
+
25
+ def test_deserialize_settings_with_string
26
+ old_settings = {
27
+ 'attributesToIndex' => %w(attr1 attr2),
28
+ 'numericAttributesToIndex' => %w(attr1 attr2),
29
+ 'slaves' => %w(index1 index2),
30
+ 'minWordSizefor1Typo' => 1
31
+ }
32
+
33
+ new_settings = {
34
+ 'searchableAttributes' => %w(attr1 attr2),
35
+ 'numericAttributesForFiltering' => %w(attr1 attr2),
36
+ 'replicas' => %w(index1 index2),
37
+ 'minWordSizefor1Typo' => 1
38
+ }
39
+
40
+ deserialized_settings = deserialize_settings(old_settings, false)
22
41
  assert_equal new_settings, deserialized_settings
23
42
  end
24
43
  end
@@ -43,6 +43,12 @@ 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:
@@ -66,13 +72,13 @@ index.search('query', opts)
66
72
  ### `Client`
67
73
 
68
74
  #### `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.
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.
70
76
  ```ruby
71
77
  # Before
72
78
  client.set_extra_header('admin', 'admin-key')
73
79
 
74
80
  # After
75
- # `Algolia::Search::Config` inherits from `Algolia::AlgoliaConfig`
81
+ # `Algolia::Search::Config` inherits from `Algolia::BaseConfig`
76
82
  config = Algolia::Search::Config.new(app_id: 'APP_ID', api_key: 'API_KEY')
77
83
  config.set_extra_header('admin', 'admin-key')
78
84
 
@@ -223,7 +229,7 @@ client.search_user_ids('query', {clusterName: 'my-cluster', hitPerPage: 12, page
223
229
  #### `pending_mappings`
224
230
  New method to check the status of your clusters' migration or user creation.
225
231
  ```ruby
226
- client.pending_mapping?({ retrieveMappings: true })
232
+ client.pending_mappings?({ retrieveMappings: true })
227
233
  ```
228
234
 
229
235
  #### `get_logs`
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.beta.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-19 00:00:00.000000000 Z
11
+ date: 2020-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,16 +56,22 @@ dependencies:
56
56
  name: faraday
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0.15'
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '2.0'
62
65
  type: :runtime
63
66
  prerelease: false
64
67
  version_requirements: !ruby/object:Gem::Requirement
65
68
  requirements:
66
- - - "~>"
69
+ - - ">="
67
70
  - !ruby/object:Gem::Version
68
71
  version: '0.15'
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '2.0'
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: multi_json
71
77
  requirement: !ruby/object:Gem::Requirement
@@ -178,8 +184,7 @@ dependencies:
178
184
  - - ">="
179
185
  - !ruby/object:Gem::Version
180
186
  version: '0'
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.
187
+ description: A simple Ruby client for the algolia.com REST API
183
188
  email:
184
189
  - support@algolia.com
185
190
  executables: []
@@ -192,11 +197,13 @@ files:
192
197
  - ".gitignore"
193
198
  - ".rubocop.yml"
194
199
  - ".rubocop_todo.yml"
200
+ - CHANGELOG.md
195
201
  - CODE_OF_CONDUCT.md
196
202
  - Gemfile
197
203
  - LICENSE
198
204
  - README.md
199
205
  - Rakefile
206
+ - SECURITY.md
200
207
  - Steepfile
201
208
  - algolia.gemspec
202
209
  - bin/console
@@ -271,13 +278,13 @@ files:
271
278
  - test/algolia/unit/user_agent_test.rb
272
279
  - test/test_helper.rb
273
280
  - upgrade_guide.md
274
- homepage: https://github.com/algolia/algoliasearch-client-ruby/tree/release/v2
281
+ homepage: https://github.com/algolia/algoliasearch-client-ruby
275
282
  licenses:
276
283
  - MIT
277
284
  metadata:
278
285
  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
286
+ documentation_uri: https://www.algolia.com/doc/api-client/getting-started/install/ruby
287
+ source_code_uri: https://github.com/algolia/algoliasearch-client-ruby
281
288
  post_install_message:
282
289
  rdoc_options: []
283
290
  require_paths:
@@ -289,14 +296,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
289
296
  version: '0'
290
297
  required_rubygems_version: !ruby/object:Gem::Requirement
291
298
  requirements:
292
- - - ">"
299
+ - - ">="
293
300
  - !ruby/object:Gem::Version
294
- version: 1.3.1
301
+ version: '0'
295
302
  requirements: []
296
303
  rubygems_version: 3.0.3
297
304
  signing_key:
298
305
  specification_version: 4
299
- summary: A simple Ruby client for the algolia.com REST API (alpha release)
306
+ summary: A simple Ruby client for the algolia.com REST API
300
307
  test_files:
301
308
  - test/algolia/integration/account_client_test.rb
302
309
  - test/algolia/integration/analytics_client_test.rb