algoliasearch 1.26.0 → 1.27.3

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: 7419f8c2f96d1a08461a1d069948004752c155d45b02be413b064558a61f7f37
4
- data.tar.gz: a3d5a45956d86bcc984f512f9e39d2efeda5a1f938120092cd77ccc919926580
3
+ metadata.gz: 1b8f0b51a88b74caae749998520d35ea8a006089c580e7a7dbb9e3438651c463
4
+ data.tar.gz: a16f2830aa1af13d4731da6b2eb23ac731812d6d4751f7b9da9aff8feba5de99
5
5
  SHA512:
6
- metadata.gz: bfdca3abc62f36662e90a3a06157beeb9de33516b91c70a3541c59e4fc132b966b55725f45f21852cd673ac6a826a9a7c83cfe4a25188d29f4f850eff9a8b53b
7
- data.tar.gz: 4d7ece80fecb91f403345d14a7534d36621c109407dd65f5fa5b1b4e4746506faad0b5fe7a3ed301ab86218063a1cb660b61b8fd30d1d758f5f3ded9270668de
6
+ metadata.gz: 4a310ba42e3b4ad001d16debd277177d28dce746453793777e09509e0c9e7ffcef03d22119e0d1b50f5597e3d616f1a28f76d7b886c006c9c177cd6014726031
7
+ data.tar.gz: 346211f63a67f947468b1cc4e687ce732463808a3efeb88d0249922f05dd156bf36633d551ff1480a7d6ffc8070391cee45815de622e395d05fa63ebc3fe031d
@@ -5,7 +5,6 @@ branches:
5
5
  - master
6
6
 
7
7
  rvm:
8
- - 1.8.7
9
8
  - 1.9.3
10
9
  - 2.0
11
10
  - 2.1
@@ -20,6 +19,10 @@ matrix:
20
19
  allow_failures:
21
20
  - rvm: rbx-3
22
21
  - rvm: jruby
22
+ include:
23
+ - rvm: 1.8.7
24
+ dist: precise
25
+
23
26
 
24
27
  cache: bundler
25
28
 
@@ -1,3 +1,53 @@
1
+ # ChangeLog
2
+
3
+ ## Unreleased
4
+
5
+ ## [1.27.3](https://github.com/algolia/algoliasearch-client-ruby/compare/1.27.2...1.27.3) (2020-06-03)
6
+
7
+ **Fixed**
8
+
9
+ * Replace expired certificate within embedded certificate chain ([9087dd1](https://github.com/algolia/algoliasearch-client-ruby/commit/9087dd14a97bf77c9391a3360c4803edf686086d))
10
+
11
+ ## [1.27.2](https://github.com/algolia/algoliasearch-client-ruby/compare/1.27.1...1.27.2) (2020-04-28)
12
+
13
+ **Fixed**
14
+
15
+ * In `search_user_id`, retrieve param `cluster` instead of `clusterName`. [368](https://github.com/algolia/algoliasearch-client-ruby/issues/368)
16
+
17
+ ## [1.27.1](https://github.com/algolia/algoliasearch-client-ruby/compare/1.27.0...1.27.1) (2019-09-26)
18
+
19
+ **Fixed**
20
+
21
+ * Update `Algolia::Index.exists` method to `Algolia::Index.exists?`. [364](https://github.com/algolia/algoliasearch-client-ruby/issues/364)
22
+
23
+ ## [1.27.0](https://github.com/algolia/algoliasearch-client-ruby/releases/tag/1.27.0) (2019-09-16)
24
+
25
+ **Added**
26
+
27
+ * Introduce `Algolia::Index.exists` method. [358](https://github.com/algolia/algoliasearch-client-ruby/issues/358)
28
+
29
+ Check whether an index exists or not.
30
+
31
+ * Introduce `Algolia::Index.find_object` method. [359](https://github.com/algolia/algoliasearch-client-ruby/issues/359)
32
+
33
+ Find object by the given condition.
34
+
35
+ * Introduce `Algolia::Index.get_object_position` method. [359](https://github.com/algolia/algoliasearch-client-ruby/issues/359)
36
+
37
+ Retrieve the given object position in a set of results.
38
+
39
+ * Introduce `Algolia.get_secured_api_key_remaining_validity` method. [361](https://github.com/algolia/algoliasearch-client-ruby/issues/361)
40
+
41
+ Returns the remaining validity time for the given API key in seconds.
42
+
43
+
44
+ ## [1.26.1](https://github.com/algolia/algoliasearch-client-ruby/compare/1.26.0...1.26.1) (2019-07-31)
45
+
46
+ ### Chore
47
+
48
+ - stop using coveralls because of a GPL-licensed transitive dep ([d2fbe8c](https://github.com/algolia/algoliasearch-client-ruby/commit/d2fbe8c))
49
+
50
+
1
51
  [1.26.0](https://github.com/algolia/algoliasearch-client-ruby/releases/tag/1.26.0) (2019-02-12)
2
52
 
3
53
  **Added**
data/Gemfile CHANGED
@@ -16,7 +16,6 @@ else
16
16
  end
17
17
 
18
18
  group :development do
19
- gem 'coveralls'
20
19
  gem 'rake'
21
20
  gem 'rdoc'
22
21
  gem 'travis'
@@ -1,68 +1,73 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- algoliasearch (1.25.2)
4
+ algoliasearch (1.27.3)
5
5
  httpclient (~> 2.8, >= 2.8.3)
6
6
  json (>= 1.5.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- addressable (2.4.0)
12
- backports (3.11.4)
13
- coveralls (0.8.22)
14
- json (>= 1.8, < 3)
15
- simplecov (~> 0.16.1)
16
- term-ansicolor (~> 1.3)
17
- thor (~> 0.19.4)
18
- tins (~> 1.6)
11
+ activesupport (5.2.4.3)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ addressable (2.7.0)
17
+ public_suffix (>= 2.0.2, < 5.0)
18
+ concurrent-ruby (1.1.6)
19
19
  crack (0.4.3)
20
20
  safe_yaml (~> 1.0.0)
21
21
  diff-lcs (1.3)
22
- docile (1.3.1)
22
+ docile (1.3.2)
23
23
  ethon (0.12.0)
24
24
  ffi (>= 1.3.0)
25
- faraday (0.15.4)
25
+ faraday (1.0.1)
26
26
  multipart-post (>= 1.2, < 3)
27
- faraday_middleware (0.12.2)
28
- faraday (>= 0.7.4, < 1.0)
29
- ffi (1.10.0)
27
+ faraday_middleware (1.0.0)
28
+ faraday (~> 1.0)
29
+ ffi (1.13.0)
30
30
  ffi2-generators (0.1.1)
31
- gh (0.15.1)
32
- addressable (~> 2.4.0)
33
- backports
34
- faraday (~> 0.8)
31
+ gh (0.17.0)
32
+ activesupport (~> 5.0)
33
+ addressable (~> 2.4)
34
+ faraday (~> 1.0)
35
+ faraday_middleware (~> 1.0)
35
36
  multi_json (~> 1.0)
36
37
  net-http-persistent (~> 2.9)
37
38
  net-http-pipeline
38
- hashdiff (0.3.8)
39
- highline (1.7.10)
39
+ hashdiff (1.0.1)
40
+ highline (2.0.3)
40
41
  httpclient (2.8.3)
41
- json (2.1.0)
42
+ i18n (1.8.2)
43
+ concurrent-ruby (~> 1.0)
44
+ json (2.3.0)
42
45
  launchy (2.4.3)
43
46
  addressable (~> 2.3)
44
- multi_json (1.13.1)
45
- multipart-post (2.0.0)
47
+ minitest (5.14.1)
48
+ multi_json (1.14.1)
49
+ multipart-post (2.1.1)
46
50
  net-http-persistent (2.9.4)
47
51
  net-http-pipeline (1.0.1)
52
+ public_suffix (4.0.5)
48
53
  pusher-client (0.6.2)
49
54
  json
50
55
  websocket (~> 1.0)
51
- rake (12.3.2)
52
- rdoc (6.1.1)
53
- rspec (3.8.0)
54
- rspec-core (~> 3.8.0)
55
- rspec-expectations (~> 3.8.0)
56
- rspec-mocks (~> 3.8.0)
57
- rspec-core (3.8.0)
58
- rspec-support (~> 3.8.0)
59
- rspec-expectations (3.8.2)
56
+ rake (13.0.1)
57
+ rdoc (6.2.1)
58
+ rspec (3.9.0)
59
+ rspec-core (~> 3.9.0)
60
+ rspec-expectations (~> 3.9.0)
61
+ rspec-mocks (~> 3.9.0)
62
+ rspec-core (3.9.2)
63
+ rspec-support (~> 3.9.3)
64
+ rspec-expectations (3.9.2)
60
65
  diff-lcs (>= 1.2.0, < 2.0)
61
- rspec-support (~> 3.8.0)
62
- rspec-mocks (3.8.0)
66
+ rspec-support (~> 3.9.0)
67
+ rspec-mocks (3.9.1)
63
68
  diff-lcs (>= 1.2.0, < 2.0)
64
- rspec-support (~> 3.8.0)
65
- rspec-support (3.8.0)
69
+ rspec-support (~> 3.9.0)
70
+ rspec-support (3.9.3)
66
71
  rubysl (2.2.0)
67
72
  rubysl-abbrev (~> 2.0)
68
73
  rubysl-base64 (~> 2.0)
@@ -170,7 +175,7 @@ GEM
170
175
  rubysl-curses (2.0.1)
171
176
  rubysl-date (2.0.9)
172
177
  rubysl-delegate (2.0.1)
173
- rubysl-digest (2.0.8)
178
+ rubysl-digest (2.1)
174
179
  rubysl-drb (2.0.1)
175
180
  rubysl-e2mmap (2.0.0)
176
181
  rubysl-english (2.0.0)
@@ -220,7 +225,7 @@ GEM
220
225
  rubysl-observer (2.0.0)
221
226
  rubysl-open-uri (2.0.0)
222
227
  rubysl-open3 (2.0.0)
223
- rubysl-openssl (2.10)
228
+ rubysl-openssl (2.13)
224
229
  rubysl-optparse (2.0.1)
225
230
  rubysl-shellwords (~> 2.0)
226
231
  rubysl-ostruct (2.1.0)
@@ -265,31 +270,29 @@ GEM
265
270
  rubysl-xmlrpc (2.0.0)
266
271
  rubysl-yaml (2.1.0)
267
272
  rubysl-zlib (2.0.1)
268
- safe_yaml (1.0.4)
269
- simplecov (0.16.1)
273
+ safe_yaml (1.0.5)
274
+ simplecov (0.18.5)
270
275
  docile (~> 1.1)
271
- json (>= 1.8, < 3)
272
- simplecov-html (~> 0.10.0)
273
- simplecov-html (0.10.2)
274
- term-ansicolor (1.7.1)
275
- tins (~> 1.0)
276
- thor (0.19.4)
277
- tins (1.20.2)
278
- travis (1.8.9)
279
- backports
280
- faraday (~> 0.9)
281
- faraday_middleware (~> 0.9, >= 0.9.1)
276
+ simplecov-html (~> 0.11)
277
+ simplecov-html (0.12.2)
278
+ thread_safe (0.3.6)
279
+ travis (1.9.1)
280
+ faraday (~> 1.0)
281
+ faraday_middleware (~> 1.0)
282
282
  gh (~> 0.13)
283
- highline (~> 1.6)
284
- launchy (~> 2.1)
283
+ highline (~> 2.0)
284
+ json (~> 2.3)
285
+ launchy (~> 2.1, < 2.5.0)
285
286
  pusher-client (~> 0.4)
286
287
  typhoeus (~> 0.6, >= 0.6.8)
287
288
  typhoeus (0.8.0)
288
289
  ethon (>= 0.8.0)
289
- webmock (3.5.1)
290
+ tzinfo (1.2.7)
291
+ thread_safe (~> 0.1)
292
+ webmock (3.8.3)
290
293
  addressable (>= 2.3.6)
291
294
  crack (>= 0.3.2)
292
- hashdiff
295
+ hashdiff (>= 0.4.0, < 2.0.0)
293
296
  websocket (1.2.8)
294
297
 
295
298
  PLATFORMS
@@ -297,7 +300,6 @@ PLATFORMS
297
300
 
298
301
  DEPENDENCIES
299
302
  algoliasearch!
300
- coveralls
301
303
  rake
302
304
  rdoc
303
305
  rspec (>= 2.5.0)
@@ -307,4 +309,4 @@ DEPENDENCIES
307
309
  webmock
308
310
 
309
311
  BUNDLED WITH
310
- 1.17.3
312
+ 2.1.4
data/README.md CHANGED
@@ -1,363 +1,56 @@
1
- # Algolia Search API Client for Ruby
1
+ <p align="center">
2
+ <a href="https://www.algolia.com">
3
+ <img alt="Algolia for Ruby" src="https://raw.githubusercontent.com/algolia/algoliasearch-client-common/master/banners/ruby.png" >
4
+ </a>
2
5
 
3
- [Algolia Search](https://www.algolia.com) is a hosted search engine capable of delivering realtime results from the first keystroke.
6
+ <h4 align="center">The perfect starting point to integrate <a href="https://algolia.com" target="_blank">Algolia</a> within your Ruby project</h4>
4
7
 
5
- The **Algolia Search API Client for Ruby** lets
6
- you easily use the [Algolia Search REST API](https://www.algolia.com/doc/rest-api/search) from
7
- your Ruby code.
8
+ <p align="center">
9
+ <a href="https://travis-ci.org/algolia/algoliasearch-client-ruby"><img src="https://img.shields.io/travis/algolia/algoliasearch-client-ruby/master.svg" alt="Build Status"></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>
12
+ </p>
13
+ </p>
8
14
 
9
- [![Build Status](https://travis-ci.org/algolia/algoliasearch-client-ruby.svg?branch=master)](https://travis-ci.org/algolia/algoliasearch-client-ruby) [![Gem Version](https://badge.fury.io/rb/algoliasearch.svg)](http://badge.fury.io/rb/algoliasearch) [![Code Climate](https://codeclimate.com/github/algolia/algoliasearch-client-ruby.svg)](https://codeclimate.com/github/algolia/algoliasearch-client-ruby) [![Coverage Status](https://coveralls.io/repos/algolia/algoliasearch-client-ruby/badge.svg)](https://coveralls.io/r/algolia/algoliasearch-client-ruby)
15
+ <p align="center">
16
+ <a href="https://www.algolia.com/doc/api-client/getting-started/install/ruby/" target="_blank">Documentation</a> •
17
+ <a href="https://github.com/algolia/algoliasearch-rails" target="_blank">Rails</a> •
18
+ <a href="https://discourse.algolia.com" target="_blank">Community Forum</a> •
19
+ <a href="http://stackoverflow.com/questions/tagged/algolia" target="_blank">Stack Overflow</a> •
20
+ <a href="https://github.com/algolia/algoliasearch-client-ruby/issues" target="_blank">Report a bug</a> •
21
+ <a href="https://www.algolia.com/support" target="_blank">Support</a>
22
+ </p>
10
23
 
24
+ ## ✨ Features
11
25
 
12
- If you are a **Ruby on Rails** user, you are probably looking for the [algoliasearch-rails](https://github.com/algolia/algoliasearch-rails) gem.
26
+ - Thin & minimal low-level HTTP client to interact with Algolia's API
27
+ - Supports Ruby `^1.8.7`.
13
28
 
29
+ ## 💡 Getting Started
14
30
 
15
-
16
-
17
- ## API Documentation
18
-
19
- You can find the full reference on [Algolia's website](https://www.algolia.com/doc/api-client/ruby/).
20
-
21
-
22
-
23
- 1. **[Install](#install)**
24
-
25
-
26
- 1. **[Quick Start](#quick-start)**
27
-
28
-
29
- 1. **[Push data](#push-data)**
30
-
31
-
32
- 1. **[Configure](#configure)**
33
-
34
-
35
- 1. **[Search](#search)**
36
-
37
-
38
- 1. **[Search UI](#search-ui)**
39
-
40
-
41
- 1. **[List of available methods](#list-of-available-methods)**
42
-
43
-
44
- # Getting Started
45
-
46
-
47
-
48
- ## Install
49
-
50
- Install the Ruby client using [RubyGems](https://rubygems.org/):
51
-
31
+ First, install Algolia Ruby API Client via the [RubyGems](https://rubygems.org/) package manager:
52
32
  ```bash
53
33
  gem install algoliasearch
54
34
  ```
55
35
 
56
- ### Ruby on Rails
36
+ Then, create objects on your index:
57
37
 
58
- If you're a Ruby on Rails user, you're probably looking for the [algoliasearch-rails](https://github.com/algolia/algoliasearch-rails) gem.
59
-
60
- ## Quick Start
61
-
62
- In 30 seconds, this quick start tutorial will show you how to index and search objects.
63
-
64
- ### Initialize the client
65
-
66
- To start, you need to initialize the client. To do this, you need your **Application ID** and **API Key**.
67
- You can find both on [your Algolia account](https://www.algolia.com/api-keys).
68
38
 
69
39
  ```ruby
70
- require 'rubygems'
71
- require 'algoliasearch'
72
-
73
40
  Algolia.init(application_id: 'YourApplicationID',
74
41
  api_key: 'YourAPIKey')
75
42
  index = Algolia::Index.new('your_index_name')
76
- ```
77
43
 
78
- ## Push data
79
-
80
- Without any prior configuration, you can start indexing [500 contacts](https://github.com/algolia/datasets/blob/master/contacts/contacts.json) in the ```contacts``` index using the following code:
81
- ```ruby
82
- index = Algolia::Index.new('contacts')
83
- batch = JSON.parse(File.read('contacts.json'))
84
- index.add_objects(batch)
44
+ index.save_objects([objectID: 1, name: 'Foo'])
85
45
  ```
86
46
 
87
- ## Configure
88
-
89
- You can customize settings to fine tune the search behavior. For example, you can add a custom ranking by number of followers to further enhance the built-in relevance:
90
-
91
- ```ruby
92
- index.set_settings(customRanking: ['desc(followers)'])
93
- ```
94
-
95
- You can also configure the list of attributes you want to index by order of importance (most important first).
96
-
97
- **Note:** Algolia is designed to suggest results as you type, which means you'll generally search by prefix.
98
- In this case, the order of attributes is crucial to decide which hit is the best.
99
-
100
- ```ruby
101
- index.set_settings({
102
- searchableAttributes: [
103
- 'lastname',
104
- 'firstname',
105
- 'company',
106
- 'email',
107
- 'city',
108
- 'address'
109
- ]}
110
- )
111
- ```
112
-
113
- ## Search
114
-
115
- You can now search for contacts by `firstname`, `lastname`, `company`, etc. (even with typos):
116
-
47
+ Finally, you may begin searching a object using the `search` method:
117
48
  ```ruby
118
- # Search for a first name
119
- puts index.search('jimmie').to_json
120
- # Search for a first name with typo
121
- puts index.search('jimie').to_json
122
- # Search for a company
123
- puts index.search('california paint').to_json
124
- # Search for a first name and a company
125
- puts index.search('jimmie paint').to_json
126
- ```
127
-
128
- ## Search UI
129
-
130
- **Warning:** If you're building a web application, you may be interested in using one of our
131
- [front-end search UI libraries](https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/).
132
-
133
- The following example shows how to quickly build a front-end search using
134
- [InstantSearch.js](https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/)
135
-
136
- ### index.html
137
-
138
- ```html
139
- <!doctype html>
140
- <head>
141
- <meta charset="UTF-8">
142
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/instantsearch.css@7.1.0/themes/algolia.css" />
143
- </head>
144
- <body>
145
- <header>
146
- <div>
147
- <input id="search-input" placeholder="Search for products">
148
- <!-- We use a specific placeholder in the input to guide users in their search. -->
149
-
150
- </header>
151
- <main>
152
-
153
-
154
- </main>
155
-
156
- <script type="text/html" id="hit-template">
157
-
158
- <p class="hit-name">
159
- {}{ "attribute": "firstname" }{{/helpers.highlight}}
160
- {}{ "attribute": "lastname" }{{/helpers.highlight}}
161
- </p>
162
-
163
- </script>
164
-
165
- <script src="https://cdn.jsdelivr.net/npm/instantsearch.js@3.0.0"></script>
166
- <script src="app.js"></script>
167
- </body>
168
- ```
169
-
170
- ### app.js
171
-
172
- ```js
173
- // Replace with your own values
174
- var searchClient = algoliasearch(
175
- 'YourApplicationID',
176
- 'YourAPIKey' // search only API key, no ADMIN key
177
- );
178
-
179
- var search = instantsearch({
180
- indexName: 'instant_search',
181
- searchClient: searchClient,
182
- routing: true,
183
- searchParameters: {
184
- hitsPerPage: 10
185
- }
186
- });
187
-
188
- search.addWidget(
189
- instantsearch.widgets.searchBox({
190
- container: '#search-input'
191
- })
192
- );
193
-
194
- search.addWidget(
195
- instantsearch.widgets.hits({
196
- container: '#hits',
197
- templates: {
198
- item: document.getElementById('hit-template').innerHTML,
199
- empty: "We didn't find any results for the search <em>\"{{query}}\"</em>"
200
- }
201
- })
202
- );
203
-
204
- search.start();
49
+ objects = index.search('Fo')
205
50
  ```
206
51
 
52
+ For full documentation, visit the **[Algolia Ruby API Client](https://www.algolia.com/doc/api-client/getting-started/install/ruby/)**.
207
53
 
54
+ ## 📄 License
208
55
 
209
-
210
- ## List of available methods
211
-
212
-
213
-
214
-
215
-
216
- ### Personalization
217
-
218
- - [Add strategy](https://algolia.com/doc/api-reference/api-methods/add-strategy/?language=ruby)
219
- - [Get strategy](https://algolia.com/doc/api-reference/api-methods/get-strategy/?language=ruby)
220
-
221
-
222
-
223
-
224
- ### Search
225
-
226
- - [Search index](https://algolia.com/doc/api-reference/api-methods/search/?language=ruby)
227
- - [Search for facet values](https://algolia.com/doc/api-reference/api-methods/search-for-facet-values/?language=ruby)
228
- - [Search multiple indices](https://algolia.com/doc/api-reference/api-methods/multiple-queries/?language=ruby)
229
- - [Browse index](https://algolia.com/doc/api-reference/api-methods/browse/?language=ruby)
230
-
231
-
232
-
233
-
234
- ### Indexing
235
-
236
- - [Add objects](https://algolia.com/doc/api-reference/api-methods/add-objects/?language=ruby)
237
- - [Save objects](https://algolia.com/doc/api-reference/api-methods/save-objects/?language=ruby)
238
- - [Partial update objects](https://algolia.com/doc/api-reference/api-methods/partial-update-objects/?language=ruby)
239
- - [Delete objects](https://algolia.com/doc/api-reference/api-methods/delete-objects/?language=ruby)
240
- - [Replace all objects](https://algolia.com/doc/api-reference/api-methods/replace-all-objects/?language=ruby)
241
- - [Delete by](https://algolia.com/doc/api-reference/api-methods/delete-by/?language=ruby)
242
- - [Clear objects](https://algolia.com/doc/api-reference/api-methods/clear-objects/?language=ruby)
243
- - [Get objects](https://algolia.com/doc/api-reference/api-methods/get-objects/?language=ruby)
244
- - [Custom batch](https://algolia.com/doc/api-reference/api-methods/batch/?language=ruby)
245
-
246
-
247
-
248
-
249
- ### Settings
250
-
251
- - [Get settings](https://algolia.com/doc/api-reference/api-methods/get-settings/?language=ruby)
252
- - [Set settings](https://algolia.com/doc/api-reference/api-methods/set-settings/?language=ruby)
253
- - [Copy settings](https://algolia.com/doc/api-reference/api-methods/copy-settings/?language=ruby)
254
-
255
-
256
-
257
-
258
- ### Manage indices
259
-
260
- - [List indices](https://algolia.com/doc/api-reference/api-methods/list-indices/?language=ruby)
261
- - [Delete index](https://algolia.com/doc/api-reference/api-methods/delete-index/?language=ruby)
262
- - [Copy index](https://algolia.com/doc/api-reference/api-methods/copy-index/?language=ruby)
263
- - [Move index](https://algolia.com/doc/api-reference/api-methods/move-index/?language=ruby)
264
-
265
-
266
-
267
-
268
- ### API Keys
269
-
270
- - [Create secured API Key](https://algolia.com/doc/api-reference/api-methods/generate-secured-api-key/?language=ruby)
271
- - [Add API Key](https://algolia.com/doc/api-reference/api-methods/add-api-key/?language=ruby)
272
- - [Update API Key](https://algolia.com/doc/api-reference/api-methods/update-api-key/?language=ruby)
273
- - [Delete API Key](https://algolia.com/doc/api-reference/api-methods/delete-api-key/?language=ruby)
274
- - [Get API Key permissions](https://algolia.com/doc/api-reference/api-methods/get-api-key/?language=ruby)
275
- - [List API Keys](https://algolia.com/doc/api-reference/api-methods/list-api-keys/?language=ruby)
276
-
277
-
278
-
279
-
280
- ### Synonyms
281
-
282
- - [Save synonym](https://algolia.com/doc/api-reference/api-methods/save-synonym/?language=ruby)
283
- - [Batch synonyms](https://algolia.com/doc/api-reference/api-methods/batch-synonyms/?language=ruby)
284
- - [Delete synonym](https://algolia.com/doc/api-reference/api-methods/delete-synonym/?language=ruby)
285
- - [Clear all synonyms](https://algolia.com/doc/api-reference/api-methods/clear-synonyms/?language=ruby)
286
- - [Get synonym](https://algolia.com/doc/api-reference/api-methods/get-synonym/?language=ruby)
287
- - [Search synonyms](https://algolia.com/doc/api-reference/api-methods/search-synonyms/?language=ruby)
288
- - [Replace all synonyms](https://algolia.com/doc/api-reference/api-methods/replace-all-synonyms/?language=ruby)
289
- - [Copy synonyms](https://algolia.com/doc/api-reference/api-methods/copy-synonyms/?language=ruby)
290
- - [Export Synonyms](https://algolia.com/doc/api-reference/api-methods/export-synonyms/?language=ruby)
291
-
292
-
293
-
294
-
295
- ### Query rules
296
-
297
- - [Save rule](https://algolia.com/doc/api-reference/api-methods/save-rule/?language=ruby)
298
- - [Batch rules](https://algolia.com/doc/api-reference/api-methods/batch-rules/?language=ruby)
299
- - [Get rule](https://algolia.com/doc/api-reference/api-methods/get-rule/?language=ruby)
300
- - [Delete rule](https://algolia.com/doc/api-reference/api-methods/delete-rule/?language=ruby)
301
- - [Clear rules](https://algolia.com/doc/api-reference/api-methods/clear-rules/?language=ruby)
302
- - [Search rules](https://algolia.com/doc/api-reference/api-methods/search-rules/?language=ruby)
303
- - [Replace all rules](https://algolia.com/doc/api-reference/api-methods/replace-all-rules/?language=ruby)
304
- - [Copy rules](https://algolia.com/doc/api-reference/api-methods/copy-rules/?language=ruby)
305
- - [Export rules](https://algolia.com/doc/api-reference/api-methods/export-rules/?language=ruby)
306
-
307
-
308
-
309
-
310
- ### A/B Test
311
-
312
- - [Add A/B test](https://algolia.com/doc/api-reference/api-methods/add-ab-test/?language=ruby)
313
- - [Get A/B test](https://algolia.com/doc/api-reference/api-methods/get-ab-test/?language=ruby)
314
- - [List A/B tests](https://algolia.com/doc/api-reference/api-methods/list-ab-tests/?language=ruby)
315
- - [Stop A/B test](https://algolia.com/doc/api-reference/api-methods/stop-ab-test/?language=ruby)
316
- - [Delete A/B test](https://algolia.com/doc/api-reference/api-methods/delete-ab-test/?language=ruby)
317
-
318
-
319
-
320
-
321
- ### Insights
322
-
323
- - [Clicked Object IDs After Search](https://algolia.com/doc/api-reference/api-methods/clicked-object-ids-after-search/?language=ruby)
324
- - [Clicked Object IDs](https://algolia.com/doc/api-reference/api-methods/clicked-object-ids/?language=ruby)
325
- - [Clicked Filters](https://algolia.com/doc/api-reference/api-methods/clicked-filters/?language=ruby)
326
- - [Converted Objects IDs After Search](https://algolia.com/doc/api-reference/api-methods/converted-object-ids-after-search/?language=ruby)
327
- - [Converted Object IDs](https://algolia.com/doc/api-reference/api-methods/converted-object-ids/?language=ruby)
328
- - [Converted Filters](https://algolia.com/doc/api-reference/api-methods/converted-filters/?language=ruby)
329
- - [Viewed Object IDs](https://algolia.com/doc/api-reference/api-methods/viewed-object-ids/?language=ruby)
330
- - [Viewed Filters](https://algolia.com/doc/api-reference/api-methods/viewed-filters/?language=ruby)
331
-
332
-
333
-
334
-
335
- ### MultiClusters
336
-
337
- - [Assign or Move userID](https://algolia.com/doc/api-reference/api-methods/assign-user-id/?language=ruby)
338
- - [Get top userID](https://algolia.com/doc/api-reference/api-methods/get-top-user-id/?language=ruby)
339
- - [Get userID](https://algolia.com/doc/api-reference/api-methods/get-user-id/?language=ruby)
340
- - [List clusters](https://algolia.com/doc/api-reference/api-methods/list-clusters/?language=ruby)
341
- - [List userIDs](https://algolia.com/doc/api-reference/api-methods/list-user-id/?language=ruby)
342
- - [Remove userID](https://algolia.com/doc/api-reference/api-methods/remove-user-id/?language=ruby)
343
- - [Search userID](https://algolia.com/doc/api-reference/api-methods/search-user-id/?language=ruby)
344
-
345
-
346
-
347
-
348
- ### Advanced
349
-
350
- - [Get logs](https://algolia.com/doc/api-reference/api-methods/get-logs/?language=ruby)
351
- - [Configuring timeouts](https://algolia.com/doc/api-reference/api-methods/configuring-timeouts/?language=ruby)
352
- - [Set extra header](https://algolia.com/doc/api-reference/api-methods/set-extra-header/?language=ruby)
353
- - [Wait for operations](https://algolia.com/doc/api-reference/api-methods/wait-task/?language=ruby)
354
-
355
-
356
-
357
-
358
-
359
- ## Getting Help
360
-
361
- - **Need help**? Ask a question to the [Algolia Community](https://discourse.algolia.com/) or on [Stack Overflow](http://stackoverflow.com/questions/tagged/algolia).
362
- - **Found a bug?** You can open a [GitHub issue](https://github.com/algolia/algoliasearch-client-ruby/issues).
363
-
56
+ Algolia Ruby API Client is an open-sourced software licensed under the [MIT license](LICENSE.md).
@@ -64,17 +64,21 @@ Gem::Specification.new do |s|
64
64
  s.specification_version = 4
65
65
 
66
66
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
67
+ if defined?(RUBY_VERSION) && RUBY_VERSION < '2.0'
68
+ s.add_runtime_dependency 'json', '>= 1.5.1', '< 2.3'
69
+ else
70
+ s.add_runtime_dependency 'json', '>= 1.5.1'
71
+ end
67
72
  s.add_runtime_dependency 'httpclient', '~> 2.8', '>= 2.8.3'
68
- s.add_runtime_dependency 'json', '>= 1.5.1'
69
73
  s.add_development_dependency 'travis', '~> 0'
70
74
  s.add_development_dependency 'rake', '~> 0'
71
75
  s.add_development_dependency 'rdoc', '~> 0'
72
76
  else
73
77
  s.add_dependency 'httpclient', '~> 2.8', '>= 2.8.3'
74
- s.add_dependency 'json', '>= 1.5.1'
78
+ s.add_dependency 'json', '>= 1.5.1', '< 2.3'
75
79
  end
76
80
  else
77
81
  s.add_dependency 'httpclient', '~> 2.8', '>= 2.8.3'
78
- s.add_dependency 'json', '>= 1.5.1'
82
+ s.add_dependency 'json', '>= 1.5.1', '< 2.3'
79
83
  end
80
84
  end
@@ -552,7 +552,7 @@ module Algolia
552
552
 
553
553
  def search_user_id(query, cluster_name = nil, page = nil, hits_per_page = nil, request_options = {})
554
554
  body = { :query => query }
555
- body[:clusterName] = cluster_name unless cluster_name.nil?
555
+ body[:cluster] = cluster_name unless cluster_name.nil?
556
556
  body[:page] = page unless page.nil?
557
557
  body[:hitsPerPage] = hits_per_page unless hits_per_page.nil?
558
558
  post(Protocol.search_user_id_uri, body.to_json, :read, request_options)
@@ -774,6 +774,28 @@ module Algolia
774
774
  end
775
775
  end
776
776
 
777
+ #
778
+ # Returns the remaining validity time for the given API key in seconds
779
+ #
780
+ # @param [String] secured_api_key the secured API key to check
781
+ #
782
+ # @return [Integer] remaining validity in seconds
783
+ #
784
+ def Algolia.get_secured_api_key_remaining_validity(secured_api_key)
785
+ now = Time.now.to_i
786
+ decoded_key = Base64.decode64(secured_api_key)
787
+ regex = 'validUntil=(\d+)'
788
+ matches = decoded_key.match(regex)
789
+
790
+ if matches === nil
791
+ raise ValidUntilNotFoundError.new('The SecuredAPIKey doesn\'t have a validUntil parameter.')
792
+ end
793
+
794
+ valid_until = matches[1].to_i
795
+
796
+ valid_until - now
797
+ end
798
+
777
799
  #
778
800
  # This method allows to query multiple indexes with one API call
779
801
  #
@@ -20,4 +20,12 @@ module Algolia
20
20
  end
21
21
  end
22
22
 
23
- end
23
+ # An exception class raised when the given object was not found.
24
+ class AlgoliaObjectNotFoundError < AlgoliaError
25
+ end
26
+
27
+ # An exception class raised when the validUntil parameter is not found
28
+ class ValidUntilNotFoundError < AlgoliaError
29
+ end
30
+
31
+ end
@@ -264,6 +264,75 @@ module Algolia
264
264
  client.post(Protocol.objects_uri, { :requests => requests }.to_json, :read, request_options)['results']
265
265
  end
266
266
 
267
+ #
268
+ # Find object by the given condition.
269
+ #
270
+ # Options can be passed in request_options body:
271
+ # - query (string): pass a query
272
+ # - paginate (bool): choose if you want to iterate through all the
273
+ # documents (true) or only the first page (false). Default is true.
274
+ # The function takes a block to filter the results from search query
275
+ # Usage example:
276
+ # index.find_object({'query' => '', 'paginate' => true}) {|obj| obj.key?('company') and obj['company'] == 'Apple'}
277
+ #
278
+ # @param request_options contains extra parameters to send with your query
279
+ #
280
+ # @return [Hash] the matching object and its position in the result set
281
+ #
282
+ def find_object(request_options = {})
283
+ paginate = true
284
+ page = 0
285
+
286
+ query = request_options[:query] || request_options['query'] || ''
287
+ request_options.delete(:query)
288
+ request_options.delete('query')
289
+
290
+ if request_options.has_key? :paginate
291
+ paginate = request_options[:paginate]
292
+ end
293
+
294
+ if request_options.has_key? 'paginate'
295
+ paginate = request_options['paginate']
296
+ end
297
+
298
+ request_options.delete(:paginate)
299
+ request_options.delete('paginate')
300
+
301
+ while true
302
+ request_options['page'] = page
303
+ res = search(query, request_options)
304
+
305
+ res['hits'].each_with_index do |hit, i|
306
+ if yield(hit)
307
+ return {
308
+ 'object' => hit,
309
+ 'position' => i,
310
+ 'page' => page,
311
+ }
312
+ end
313
+ end if block_given?
314
+
315
+ has_next_page = page + 1 < res['nbPages']
316
+ if !paginate || !has_next_page
317
+ raise AlgoliaObjectNotFoundError.new('Object not found')
318
+ end
319
+
320
+ page += 1
321
+ end
322
+ end
323
+
324
+ #
325
+ # Retrieve the given object position in a set of results.
326
+ #
327
+ # @param [Array] objects the result set to browse
328
+ # @param [String] object_id the object to look for
329
+ #
330
+ # @return [Integer] position of the object, or -1 if it's not in the array
331
+ #
332
+ def self.get_object_position(objects, object_id)
333
+ objects['hits'].find_index { |hit| hit['objectID'] == object_id } || -1
334
+ end
335
+
267
336
  #
268
337
  # Check the status of a task on the server.
269
338
  # All server task are asynchronous and you can check the status of a task with this method.
@@ -1208,6 +1277,29 @@ module Algolia
1208
1277
  res
1209
1278
  end
1210
1279
 
1280
+ #
1281
+ # Check whether an index exists or not
1282
+ #
1283
+ # @return [Boolean]
1284
+ #
1285
+ def exists
1286
+ begin
1287
+ get_settings
1288
+ rescue AlgoliaProtocolError => e
1289
+ if e.code === 404
1290
+ return false
1291
+ end
1292
+
1293
+ raise e
1294
+ end
1295
+ return true
1296
+ end
1297
+
1298
+ #
1299
+ # Aliases the exists method
1300
+ #
1301
+ alias :exists? :exists
1302
+
1211
1303
  # Deprecated
1212
1304
  alias_method :get_user_key, :get_api_key
1213
1305
  alias_method :list_user_keys, :list_api_keys
@@ -1,3 +1,3 @@
1
1
  module Algolia
2
- VERSION = "1.26.0"
2
+ VERSION = "1.27.3"
3
3
  end
@@ -16,6 +16,43 @@
16
16
 
17
17
  # @(#) $RCSfile: certdata.txt,v $ $Revision: 1.87 $ $Date: 2012/12/29 16:32:45 $
18
18
 
19
+ USERTrust RSA root CA
20
+ =====================
21
+ -----BEGIN CERTIFICATE-----
22
+ MIIF3jCCA8agAwIBAgIQAf1tMPyjylGoG7xkDjUDLTANBgkqhkiG9w0BAQwFADCB
23
+ iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl
24
+ cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV
25
+ BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTAw
26
+ MjAxMDAwMDAwWhcNMzgwMTE4MjM1OTU5WjCBiDELMAkGA1UEBhMCVVMxEzARBgNV
27
+ BAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0plcnNleSBDaXR5MR4wHAYDVQQKExVU
28
+ aGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNVBAMTJVVTRVJUcnVzdCBSU0EgQ2Vy
29
+ dGlmaWNhdGlvbiBBdXRob3JpdHkwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIK
30
+ AoICAQCAEmUXNg7D2wiz0KxXDXbtzSfTTK1Qg2HiqiBNCS1kCdzOiZ/MPans9s/B
31
+ 3PHTsdZ7NygRK0faOca8Ohm0X6a9fZ2jY0K2dvKpOyuR+OJv0OwWIJAJPuLodMkY
32
+ tJHUYmTbf6MG8YgYapAiPLz+E/CHFHv25B+O1ORRxhFnRghRy4YUVD+8M/5+bJz/
33
+ Fp0YvVGONaanZshyZ9shZrHUm3gDwFA66Mzw3LyeTP6vBZY1H1dat//O+T23LLb2
34
+ VN3I5xI6Ta5MirdcmrS3ID3KfyI0rn47aGYBROcBTkZTmzNg95S+UzeQc0PzMsNT
35
+ 79uq/nROacdrjGCT3sTHDN/hMq7MkztReJVni+49Vv4M0GkPGw/zJSZrM233bkf6
36
+ c0Plfg6lZrEpfDKEY1WJxA3Bk1QwGROs0303p+tdOmw1XNtB1xLaqUkL39iAigmT
37
+ Yo61Zs8liM2EuLE/pDkP2QKe6xJMlXzzawWpXhaDzLhn4ugTncxbgtNMs+1b/97l
38
+ c6wjOy0AvzVVdAlJ2ElYGn+SNuZRkg7zJn0cTRe8yexDJtC/QV9AqURE9JnnV4ee
39
+ UB9XVKg+/XRjL7FQZQnmWEIuQxpMtPAlR1n6BB6T1CZGSlCBst6+eLf8ZxXhyVeE
40
+ Hg9j1uliutZfVS7qXMYoCAQlObgOK6nyTJccBz8NUvXt7y+CDwIDAQABo0IwQDAd
41
+ BgNVHQ4EFgQUU3m/WqorSs9UgOHYm8Cd8rIDZsswDgYDVR0PAQH/BAQDAgEGMA8G
42
+ A1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEMBQADggIBAFzUfA3P9wF9QZllDHPF
43
+ Up/L+M+ZBn8b2kMVn54CVVeWFPFSPCeHlCjtHzoBN6J2/FNQwISbxmtOuowhT6KO
44
+ VWKR82kV2LyI48SqC/3vqOlLVSoGIG1VeCkZ7l8wXEskEVX/JJpuXior7gtNn3/3
45
+ ATiUFJVDBwn7YKnuHKsSjKCaXqeYalltiz8I+8jRRa8YFWSQEg9zKC7F4iRO/Fjs
46
+ 8PRF/iKz6y+O0tlFYQXBl2+odnKPi4w2r78NBc5xjeambx9spnFixdjQg3IM8WcR
47
+ iQycE0xyNN+81XHfqnHd4blsjDwSXWXavVcStkNr/+XeTWYRUc+ZruwXtuhxkYze
48
+ Sf7dNXGiFSeUHM9h4ya7b6NnJSFd5t0dCy5oGzuCr+yDZ4XUmFF0sbmZgIn/f3gZ
49
+ XHlKYC6SQK5MNyosycdiyA5d9zZbyuAlJQG03RoHnHcAP9Dc1ew91Pq7P8yF1m9/
50
+ qS3fuQL39ZeatTXaw2ewh0qpKJ4jjv9cJ2vhsE/zB+4ALtRZh8tSQZXq9EfX7mRB
51
+ VXyNWQKV3WKdwrnuWih0hKWbt5DHDAff9Yk2dDLWKMGwsAvgnEzDHNb842m1R0aB
52
+ L6KCq9NjRHDEjf8tM7qtj3u1cIiuPhnPQCjY/MiQu12ZIvVS5ljFH4gxQ+6IHdfG
53
+ jjxDah2nGN59PRbxYvnKkKj9
54
+ -----END CERTIFICATE-----
55
+
19
56
  GTE CyberTrust Global Root
20
57
  ==========================
21
58
  -----BEGIN CERTIFICATE-----
@@ -551,30 +588,6 @@ mYbvP33zGDLKe8bjq2RGlfgmadlVg3sslgf/WSxEo8bl6ancoWOAWiFeIc9TVPC6b4nbqKqVz4vj
551
588
  ccweGyBECMB6tkD9xOQ14R0WHNC8K47Wcdk=
552
589
  -----END CERTIFICATE-----
553
590
 
554
- AddTrust External Root
555
- ======================
556
- -----BEGIN CERTIFICATE-----
557
- MIIENjCCAx6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBvMQswCQYDVQQGEwJTRTEUMBIGA1UEChML
558
- QWRkVHJ1c3QgQUIxJjAkBgNVBAsTHUFkZFRydXN0IEV4dGVybmFsIFRUUCBOZXR3b3JrMSIwIAYD
559
- VQQDExlBZGRUcnVzdCBFeHRlcm5hbCBDQSBSb290MB4XDTAwMDUzMDEwNDgzOFoXDTIwMDUzMDEw
560
- NDgzOFowbzELMAkGA1UEBhMCU0UxFDASBgNVBAoTC0FkZFRydXN0IEFCMSYwJAYDVQQLEx1BZGRU
561
- cnVzdCBFeHRlcm5hbCBUVFAgTmV0d29yazEiMCAGA1UEAxMZQWRkVHJ1c3QgRXh0ZXJuYWwgQ0Eg
562
- Um9vdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALf3GjPm8gAELTngTlvtH7xsD821
563
- +iO2zt6bETOXpClMfZOfvUq8k+0DGuOPz+VtUFrWlymUWoCwSXrbLpX9uMq/NzgtHj6RQa1wVsfw
564
- Tz/oMp50ysiQVOnGXw94nZpAPA6sYapeFI+eh6FqUNzXmk6vBbOmcZSccbNQYArHE504B4YCqOmo
565
- aSYYkKtMsE8jqzpPhNjfzp/haW+710LXa0Tkx63ubUFfclpxCDezeWWkWaCUN/cALw3CknLa0Dhy
566
- 2xSoRcRdKn23tNbE7qzNE0S3ySvdQwAl+mG5aWpYIxG3pzOPVnVZ9c0p10a3CitlttNCbxWyuHv7
567
- 7+ldU9U0WicCAwEAAaOB3DCB2TAdBgNVHQ4EFgQUrb2YejS0Jvf6xCZU7wO94CTLVBowCwYDVR0P
568
- BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wgZkGA1UdIwSBkTCBjoAUrb2YejS0Jvf6xCZU7wO94CTL
569
- VBqhc6RxMG8xCzAJBgNVBAYTAlNFMRQwEgYDVQQKEwtBZGRUcnVzdCBBQjEmMCQGA1UECxMdQWRk
570
- VHJ1c3QgRXh0ZXJuYWwgVFRQIE5ldHdvcmsxIjAgBgNVBAMTGUFkZFRydXN0IEV4dGVybmFsIENB
571
- IFJvb3SCAQEwDQYJKoZIhvcNAQEFBQADggEBALCb4IUlwtYj4g+WBpKdQZic2YR5gdkeWxQHIzZl
572
- j7DYd7usQWxHYINRsPkyPef89iYTx4AWpb9a/IfPeHmJIZriTAcKhjW88t5RxNKWt9x+Tu5w/Rw5
573
- 6wwCURQtjr0W4MHfRnXnJK3s9EK0hZNwEGe6nQY1ShjTK3rMUUKhemPR5ruhxSvCNr4TDea9Y355
574
- e6cJDUCrat2PisP29owaQgVR1EX1n6diIWgVIEM8med8vSTYqZEXc4g/VhsxOBi0cQ+azcgOno4u
575
- G+GMmIPLHzHxREzGBHNJdmAPx/i9F4BrLunMTA5amnkPIAou1Z5jJh5VkpTYghdae9C8x49OhgQ=
576
- -----END CERTIFICATE-----
577
-
578
591
  AddTrust Public Services Root
579
592
  =============================
580
593
  -----BEGIN CERTIFICATE-----
@@ -175,6 +175,16 @@ describe 'Client' do
175
175
  @index.delete_index rescue "not fatal"
176
176
  end
177
177
 
178
+ it "should tell if index exists" do
179
+ @index.add_object!({ :name => "John Doe", :email => "john@doe.org" }, "1")
180
+ expect(@index.exists?).to be true
181
+ end
182
+
183
+ it "should tell if index does not exist" do
184
+ index = Algolia::Index.new('nonexistent_index')
185
+ expect(index.exists?).to be false
186
+ end
187
+
178
188
  it "should add a simple object" do
179
189
  @index.add_object!({ :name => "John Doe", :email => "john@doe.org" }, "1")
180
190
  res = @index.search("john")
@@ -436,6 +446,73 @@ describe 'Client' do
436
446
  end
437
447
  end
438
448
 
449
+ it 'should find objects when needed' do
450
+ index = Algolia::Index.new(safe_index_name("àlgol?à"))
451
+
452
+ index.save_objects!([
453
+ {:company => 'Algolia', :name => 'Julien Lemoine', :objectID => 'julien-lemoine'},
454
+ {:company => 'Algolia', :name => 'Nicolas Dessaigne', :objectID => 'nicolas-dessaigne'},
455
+ {:company => 'Amazon', :name =>' "Jeff Bezos', :objectID => '162590850'},
456
+ {:company => 'Apple', :name => 'Steve Jobs', :objectID => '162590860'},
457
+ {:company => 'Apple', :name => 'Steve Wozniak', :objectID => '162590870'},
458
+ {:company => 'Arista Networks', :name => 'Jayshree Ullal', :objectID => '162590880'},
459
+ {:company => 'Google', :name => 'Larry Page', :objectID => '162590890'},
460
+ {:company => 'Google', :name => 'Rob Pike', :objectID => '162590900'},
461
+ {:company => 'Google', :name => 'Sergueï Brin', :objectID => '162590910'},
462
+ {:company => 'Microsoft', :name => 'Bill Gates', :objectID => '162590920'},
463
+ {:company => 'SpaceX', :name => 'Elon Musk', :objectID => '162590930'},
464
+ {:company => 'Tesla', :name => 'Elon Musk', :objectID => '162590940'},
465
+ {:company => 'Yahoo', :name => 'Marissa Mayer', :objectID => '162590950'},
466
+ ])
467
+
468
+ res = index.search('algolia')
469
+ Algolia::Index.get_object_position(res, 'nicolas-dessaigne').should eq(0)
470
+ Algolia::Index.get_object_position(res, 'julien-lemoine').should eq(1)
471
+ Algolia::Index.get_object_position(res, '').should eq(-1)
472
+
473
+ expect {
474
+ index.find_object({'query' => '', 'paginate' => true})
475
+ }.to raise_exception(
476
+ Algolia::AlgoliaObjectNotFoundError,
477
+ 'Object not found'
478
+ )
479
+
480
+ expect {
481
+ index.find_object({'query' => '', 'paginate' => true}) { false }
482
+ }.to raise_exception(
483
+ Algolia::AlgoliaObjectNotFoundError,
484
+ 'Object not found'
485
+ )
486
+
487
+ obj = index.find_object({'query' => '', 'paginate' => true}) { true }
488
+ obj['position'].should eq(0)
489
+ obj['page'].should eq(0)
490
+
491
+ # we use a lambda and convert it to a block with `&`
492
+ # so as not to repeat the condition
493
+ condition = lambda do |obj|
494
+ obj.key?('company') and obj['company'] == 'Apple'
495
+ end
496
+
497
+ expect {
498
+ index.find_object({'query' => 'algolia', 'paginate' => true}, &condition)
499
+ }.to raise_exception(
500
+ Algolia::AlgoliaObjectNotFoundError,
501
+ 'Object not found'
502
+ )
503
+
504
+ expect {
505
+ index.find_object({'query' => '', 'paginate' => false, 'hitsPerPage' => 5}, &condition)
506
+ }.to raise_exception(
507
+ Algolia::AlgoliaObjectNotFoundError,
508
+ 'Object not found'
509
+ )
510
+
511
+ obj = index.find_object({'query' => '', 'paginate' => true, 'hitsPerPage' => 5}, &condition)
512
+ obj['position'].should eq(0)
513
+ obj['page'].should eq(2)
514
+ end
515
+
439
516
  it "should copy the index" do
440
517
  index = Algolia::Index.new(safe_index_name("àlgol?à"))
441
518
  begin
@@ -615,7 +692,7 @@ describe 'Client' do
615
692
  expect { Algolia.multiple_queries([{"query" => ""}]) }.to raise_error(ArgumentError)
616
693
  end
617
694
 
618
- it "shoud accept custom batch" do
695
+ it "should accept custom batch" do
619
696
  @index.clear_index! rescue "Not fatal"
620
697
  request = { "requests" => [
621
698
  {
@@ -1277,6 +1354,19 @@ describe 'Client' do
1277
1354
  expect{Algolia.list_indexes('headers' => { 'X-Algolia-API-Key' => 'NotExistentAPIKey' })}.to raise_error(Algolia::AlgoliaProtocolError)
1278
1355
  end
1279
1356
 
1357
+ it 'should retrieve the remaining validity time in seconds' do
1358
+ now = Time.now.to_i
1359
+
1360
+ key = Algolia.generate_secured_api_key('foo', :validUntil => now - (10 * 60))
1361
+ expect(Algolia.get_secured_api_key_remaining_validity(key)).to be < 0
1362
+
1363
+ key = Algolia.generate_secured_api_key('foo', :validUntil => now + (10 * 60))
1364
+ expect(Algolia.get_secured_api_key_remaining_validity(key)).to be > 0
1365
+
1366
+ key = Algolia.generate_secured_api_key('foo', [])
1367
+ expect { Algolia.get_secured_api_key_remaining_validity(key) }.to raise_error(Algolia::ValidUntilNotFoundError)
1368
+ end
1369
+
1280
1370
  context 'DNS timeout' do
1281
1371
  before(:each) do
1282
1372
  @client = Algolia::Client.new :application_id => ENV['ALGOLIA_APPLICATION_ID'], :api_key => ENV['ALGOLIA_API_KEY'],
@@ -4,11 +4,6 @@ if ENV['COVERAGE']
4
4
  SimpleCov.start
5
5
  end
6
6
 
7
- if ENV['TRAVIS'] && Object.const_defined?(:RUBY_ENGINE) && RUBY_ENGINE == 'ruby'
8
- require 'coveralls'
9
- Coveralls.wear!
10
- end
11
-
12
7
  require 'bundler/setup'
13
8
 
14
9
  Bundler.setup :test
metadata CHANGED
@@ -1,49 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algoliasearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.26.0
4
+ version: 1.27.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-12 00:00:00.000000000 Z
11
+ date: 2020-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: httpclient
14
+ name: json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2.8'
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
- version: 2.8.3
19
+ version: 1.5.1
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '2.8'
30
24
  - - ">="
31
25
  - !ruby/object:Gem::Version
32
- version: 2.8.3
26
+ version: 1.5.1
33
27
  - !ruby/object:Gem::Dependency
34
- name: json
28
+ name: httpclient
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.8'
37
34
  - - ">="
38
35
  - !ruby/object:Gem::Version
39
- version: 1.5.1
36
+ version: 2.8.3
40
37
  type: :runtime
41
38
  prerelease: false
42
39
  version_requirements: !ruby/object:Gem::Requirement
43
40
  requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '2.8'
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 1.5.1
46
+ version: 2.8.3
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: travis
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  requirements: []
148
- rubygems_version: 3.0.2
148
+ rubygems_version: 3.0.6
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: A simple Ruby client for the algolia.com REST API