algolia 2.0.0.pre.beta.1 → 2.0.0.pre.beta.2

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: 70ae2ec824eed001a361d702826ad88956c6b580793bc8bb3aceda020ea8e8ea
4
- data.tar.gz: bbed7b37901bf59cbc1cbf172a4ec9fa06df026988187cd1ea78fd6a3cf9dae4
3
+ metadata.gz: 4645e42bf97d367a91ac73d59c440bc8f07d34c969df2d16ca3d6fac652f14f9
4
+ data.tar.gz: 2188142202397e4e56dbe7b77d635b439794ebf6401472e83907ab078e593a45
5
5
  SHA512:
6
- metadata.gz: 253ebb7ccb0745b17f72526df5656ba58eb800c3ce973eaffe52e6f098758def22d425c77fe6b07f882733551d3d01f081ff80b4be6b900f7ccfcac3a2926edf
7
- data.tar.gz: a5e231f9bd48361cfe12fa5b74234ad899b6ac1dbd2b46dc0b4f69a76532bebb7cc1e0f7eb9abf7930693422a124c7eb5e5f18b5798beb3eb9edd6463779d3b7
6
+ metadata.gz: edb4691eaa9e505a1e014e58232edffb0c6fdb62686f52b90c597b037392e81c1af98c7e339f017ad5b1ecab916d07336cf31c734832838d7648fcab82e2fe82
7
+ data.tar.gz: c9d8da55b0599118d3153ca84e1bf34f909cf128c101b5480ffff64213253e45685daef451ee48e15410737319efd6dea5f75768b3e2c0af0947160b1304473e
@@ -33,7 +33,7 @@ module Algolia
33
33
  @write_timeout = opts[:write_timeout] || Defaults::WRITE_TIMEOUT
34
34
  @connect_timeout = opts[:connect_timeout] || Defaults::CONNECT_TIMEOUT
35
35
  @compression_type = opts[:compression_type] || Defaults::NONE_ENCODING
36
- @symbolize_keys = opts[:symbolize_keys] || true
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
@@ -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,
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Algolia
2
- VERSION = '2.0.0-beta.1'.freeze
2
+ VERSION = '2.0.0-beta.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
@@ -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
 
metadata CHANGED
@@ -1,7 +1,7 @@
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.0.pre.beta.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia