algoliasearch 1.12.6 → 1.12.7
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 +4 -4
- data/ChangeLog +3 -0
- data/README.md +33 -2770
- data/lib/algolia/client.rb +41 -10
- data/lib/algolia/index.rb +12 -5
- data/lib/algolia/version.rb +1 -1
- data/spec/client_spec.rb +24 -24
- data/spec/mock_spec.rb +1 -1
- metadata +3 -3
data/lib/algolia/client.rb
CHANGED
|
@@ -198,12 +198,12 @@ module Algolia
|
|
|
198
198
|
end
|
|
199
199
|
|
|
200
200
|
# List all existing user keys with their associated ACLs
|
|
201
|
-
def
|
|
201
|
+
def list_api_keys
|
|
202
202
|
get(Protocol.keys_uri, :read)
|
|
203
203
|
end
|
|
204
204
|
|
|
205
205
|
# Get ACL of a user key
|
|
206
|
-
def
|
|
206
|
+
def get_api_key(key)
|
|
207
207
|
get(Protocol.key_uri(key), :read)
|
|
208
208
|
end
|
|
209
209
|
|
|
@@ -234,7 +234,7 @@ module Algolia
|
|
|
234
234
|
# @param maxHitsPerQuery the maximum number of hits this API key can retrieve in one call (0 means unlimited)
|
|
235
235
|
# @param indexes the optional list of targeted indexes
|
|
236
236
|
#
|
|
237
|
-
def
|
|
237
|
+
def add_api_key(obj, validity = 0, maxQueriesPerIPPerHour = 0, maxHitsPerQuery = 0, indexes = nil)
|
|
238
238
|
if obj.instance_of? Array
|
|
239
239
|
params = {
|
|
240
240
|
:acl => obj
|
|
@@ -282,7 +282,7 @@ module Algolia
|
|
|
282
282
|
# @param maxHitsPerQuery the maximum number of hits this API key can retrieve in one call (0 means unlimited)
|
|
283
283
|
# @param indexes the optional list of targeted indexes
|
|
284
284
|
#
|
|
285
|
-
def
|
|
285
|
+
def update_api_key(key, obj, validity = 0, maxQueriesPerIPPerHour = 0, maxHitsPerQuery = 0, indexes = nil)
|
|
286
286
|
if obj.instance_of? Array
|
|
287
287
|
params = {
|
|
288
288
|
:acl => obj
|
|
@@ -303,9 +303,9 @@ module Algolia
|
|
|
303
303
|
put(Protocol.key_uri(key), params.to_json)
|
|
304
304
|
end
|
|
305
305
|
|
|
306
|
-
|
|
306
|
+
|
|
307
307
|
# Delete an existing user key
|
|
308
|
-
def
|
|
308
|
+
def delete_api_key(key)
|
|
309
309
|
delete(Protocol.key_uri(key))
|
|
310
310
|
end
|
|
311
311
|
|
|
@@ -430,6 +430,12 @@ module Algolia
|
|
|
430
430
|
return JSON.parse(response.content)
|
|
431
431
|
end
|
|
432
432
|
|
|
433
|
+
# Deprecated
|
|
434
|
+
alias_method :list_user_keys, :list_api_keys
|
|
435
|
+
alias_method :get_user_key, :get_api_key
|
|
436
|
+
alias_method :add_user_key, :add_api_key
|
|
437
|
+
alias_method :update_user_key, :update_api_key
|
|
438
|
+
alias_method :delete_user_key, :delete_api_key
|
|
433
439
|
end
|
|
434
440
|
|
|
435
441
|
# Module methods
|
|
@@ -588,11 +594,21 @@ module Algolia
|
|
|
588
594
|
end
|
|
589
595
|
|
|
590
596
|
# List all existing user keys with their associated ACLs
|
|
597
|
+
def Algolia.list_api_keys
|
|
598
|
+
Algolia.client.list_api_keys
|
|
599
|
+
end
|
|
600
|
+
|
|
601
|
+
# Deprecated
|
|
591
602
|
def Algolia.list_user_keys
|
|
592
|
-
Algolia.client.
|
|
603
|
+
Algolia.client.list_api_keys
|
|
593
604
|
end
|
|
594
605
|
|
|
595
606
|
# Get ACL of a user key
|
|
607
|
+
def Algolia.get_api_key(key)
|
|
608
|
+
Algolia.client.get_api_key(key)
|
|
609
|
+
end
|
|
610
|
+
|
|
611
|
+
# Deprecated
|
|
596
612
|
def Algolia.get_user_key(key)
|
|
597
613
|
Algolia.client.get_user_key(key)
|
|
598
614
|
end
|
|
@@ -624,8 +640,13 @@ module Algolia
|
|
|
624
640
|
# @param maxHitsPerQuery the maximum number of hits this API key can retrieve in one call (0 means unlimited)
|
|
625
641
|
# @param indexes the optional list of targeted indexes
|
|
626
642
|
#
|
|
643
|
+
def Algolia.add_api_key(obj, validity = 0, maxQueriesPerIPPerHour = 0, maxHitsPerQuery = 0, indexes = nil)
|
|
644
|
+
Algolia.client.add_api_key(obj, validity, maxQueriesPerIPPerHour, maxHitsPerQuery, indexes)
|
|
645
|
+
end
|
|
646
|
+
|
|
647
|
+
# Deprecated
|
|
627
648
|
def Algolia.add_user_key(obj, validity = 0, maxQueriesPerIPPerHour = 0, maxHitsPerQuery = 0, indexes = nil)
|
|
628
|
-
Algolia.client.
|
|
649
|
+
Algolia.client.add_api_key(obj, validity, maxQueriesPerIPPerHour, maxHitsPerQuery, indexes)
|
|
629
650
|
end
|
|
630
651
|
|
|
631
652
|
#
|
|
@@ -655,13 +676,23 @@ module Algolia
|
|
|
655
676
|
# @param maxHitsPerQuery the maximum number of hits this API key can retrieve in one call (0 means unlimited)
|
|
656
677
|
# @param indexes the optional list of targeted indexes
|
|
657
678
|
#
|
|
679
|
+
def Algolia.update_api_key(key, obj, validity = 0, maxQueriesPerIPPerHour = 0, maxHitsPerQuery = 0, indexes = nil)
|
|
680
|
+
Algolia.client.update_api_key(key, obj, validity, maxQueriesPerIPPerHour, maxHitsPerQuery, indexes)
|
|
681
|
+
end
|
|
682
|
+
|
|
683
|
+
# Deprecated
|
|
658
684
|
def Algolia.update_user_key(key, obj, validity = 0, maxQueriesPerIPPerHour = 0, maxHitsPerQuery = 0, indexes = nil)
|
|
659
|
-
Algolia.client.
|
|
685
|
+
Algolia.client.update_api_key(key, obj, validity, maxQueriesPerIPPerHour, maxHitsPerQuery, indexes)
|
|
660
686
|
end
|
|
661
687
|
|
|
662
688
|
# Delete an existing user key
|
|
689
|
+
def Algolia.delete_api_key(key)
|
|
690
|
+
Algolia.client.delete_api_key(key)
|
|
691
|
+
end
|
|
692
|
+
|
|
693
|
+
# Deprecated
|
|
663
694
|
def Algolia.delete_user_key(key)
|
|
664
|
-
|
|
695
|
+
Algolia.client.delete_api_key(key)
|
|
665
696
|
end
|
|
666
697
|
|
|
667
698
|
# Send a batch request targeting multiple indices
|
data/lib/algolia/index.rb
CHANGED
|
@@ -446,12 +446,12 @@ module Algolia
|
|
|
446
446
|
end
|
|
447
447
|
|
|
448
448
|
# List all existing user keys with their associated ACLs
|
|
449
|
-
def
|
|
449
|
+
def list_api_keys
|
|
450
450
|
client.get(Protocol.index_keys_uri(name), :read)
|
|
451
451
|
end
|
|
452
452
|
|
|
453
453
|
# Get ACL of a user key
|
|
454
|
-
def
|
|
454
|
+
def get_api_key(key)
|
|
455
455
|
client.get(Protocol.index_key_uri(name, key), :read)
|
|
456
456
|
end
|
|
457
457
|
|
|
@@ -480,7 +480,7 @@ module Algolia
|
|
|
480
480
|
# @param maxQueriesPerIPPerHour the maximum number of API calls allowed from an IP address per hour (0 means unlimited)
|
|
481
481
|
# @param maxHitsPerQuery the maximum number of hits this API key can retrieve in one call (0 means unlimited)
|
|
482
482
|
#
|
|
483
|
-
def
|
|
483
|
+
def add_api_key(obj, validity = 0, maxQueriesPerIPPerHour = 0, maxHitsPerQuery = 0)
|
|
484
484
|
if obj.instance_of? Array
|
|
485
485
|
params = {
|
|
486
486
|
:acl => obj
|
|
@@ -525,7 +525,7 @@ module Algolia
|
|
|
525
525
|
# @param maxQueriesPerIPPerHour the maximum number of API calls allowed from an IP address per hour (0 means unlimited)
|
|
526
526
|
# @param maxHitsPerQuery the maximum number of hits this API key can retrieve in one call (0 means unlimited)
|
|
527
527
|
#
|
|
528
|
-
def
|
|
528
|
+
def update_api_key(key, obj, validity = 0, maxQueriesPerIPPerHour = 0, maxHitsPerQuery = 0)
|
|
529
529
|
if obj.instance_of? Array
|
|
530
530
|
params = {
|
|
531
531
|
:acl => obj
|
|
@@ -547,7 +547,7 @@ module Algolia
|
|
|
547
547
|
|
|
548
548
|
|
|
549
549
|
# Delete an existing user key
|
|
550
|
-
def
|
|
550
|
+
def delete_api_key(key)
|
|
551
551
|
client.delete(Protocol.index_key_uri(name, key))
|
|
552
552
|
end
|
|
553
553
|
|
|
@@ -771,6 +771,13 @@ module Algolia
|
|
|
771
771
|
return res
|
|
772
772
|
end
|
|
773
773
|
|
|
774
|
+
# Deprecated
|
|
775
|
+
alias_method :get_user_key, :get_api_key
|
|
776
|
+
alias_method :list_user_keys, :list_api_keys
|
|
777
|
+
alias_method :add_user_key, :add_api_key
|
|
778
|
+
alias_method :update_user_key, :update_api_key
|
|
779
|
+
alias_method :delete_user_key, :delete_api_key
|
|
780
|
+
|
|
774
781
|
private
|
|
775
782
|
def check_array(objs)
|
|
776
783
|
raise ArgumentError.new("argument must be an array of objects") if !objs.is_a?(Array)
|
data/lib/algolia/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
|
@@ -400,7 +400,7 @@ describe 'Client' do
|
|
|
400
400
|
def wait_key(index, key, &block)
|
|
401
401
|
1.upto(60) do # do not wait too long
|
|
402
402
|
begin
|
|
403
|
-
k = index.
|
|
403
|
+
k = index.get_api_key(key)
|
|
404
404
|
if block_given?
|
|
405
405
|
return if yield k
|
|
406
406
|
# not found
|
|
@@ -418,7 +418,7 @@ describe 'Client' do
|
|
|
418
418
|
def wait_key_missing(index, key)
|
|
419
419
|
1.upto(60) do # do not wait too long
|
|
420
420
|
begin
|
|
421
|
-
k = index.
|
|
421
|
+
k = index.get_api_key(key)
|
|
422
422
|
sleep 1
|
|
423
423
|
rescue
|
|
424
424
|
# not found
|
|
@@ -430,7 +430,7 @@ describe 'Client' do
|
|
|
430
430
|
def wait_global_key(key, &block)
|
|
431
431
|
1.upto(60) do # do not wait too long
|
|
432
432
|
begin
|
|
433
|
-
k = Algolia.
|
|
433
|
+
k = Algolia.get_api_key(key)
|
|
434
434
|
if block_given?
|
|
435
435
|
return if yield k
|
|
436
436
|
# not found
|
|
@@ -448,7 +448,7 @@ describe 'Client' do
|
|
|
448
448
|
def wait_global_key_missing(key)
|
|
449
449
|
1.upto(60) do # do not wait too long
|
|
450
450
|
begin
|
|
451
|
-
k = Algolia.
|
|
451
|
+
k = Algolia.get_api_key(key)
|
|
452
452
|
sleep 1
|
|
453
453
|
rescue
|
|
454
454
|
# not found
|
|
@@ -459,46 +459,46 @@ describe 'Client' do
|
|
|
459
459
|
|
|
460
460
|
it "should test index keys" do
|
|
461
461
|
@index.set_settings!({}) # ensure the index exists
|
|
462
|
-
resIndex = @index.
|
|
463
|
-
newIndexKey = @index.
|
|
462
|
+
resIndex = @index.list_api_keys
|
|
463
|
+
newIndexKey = @index.add_api_key(['search'])
|
|
464
464
|
newIndexKey['key'].should_not eq("")
|
|
465
465
|
wait_key(@index, newIndexKey['key'])
|
|
466
|
-
resIndexAfter = @index.
|
|
466
|
+
resIndexAfter = @index.list_api_keys
|
|
467
467
|
is_include(resIndex['keys'], 'value', newIndexKey['key']).should eq(false)
|
|
468
468
|
is_include(resIndexAfter['keys'], 'value', newIndexKey['key']).should eq(true)
|
|
469
|
-
indexKey = @index.
|
|
469
|
+
indexKey = @index.get_api_key(newIndexKey['key'])
|
|
470
470
|
indexKey['acl'][0].should eq('search')
|
|
471
|
-
@index.
|
|
471
|
+
@index.update_api_key(newIndexKey['key'], ['addObject'])
|
|
472
472
|
wait_key(@index, newIndexKey['key']) do |key|
|
|
473
473
|
key['acl'] == ['addObject']
|
|
474
474
|
end
|
|
475
|
-
indexKey = @index.
|
|
475
|
+
indexKey = @index.get_api_key(newIndexKey['key'])
|
|
476
476
|
indexKey['acl'][0].should eq('addObject')
|
|
477
|
-
@index.
|
|
477
|
+
@index.delete_api_key(newIndexKey['key'])
|
|
478
478
|
wait_key_missing(@index, newIndexKey['key'])
|
|
479
|
-
resIndexEnd = @index.
|
|
479
|
+
resIndexEnd = @index.list_api_keys
|
|
480
480
|
is_include(resIndexEnd['keys'], 'value', newIndexKey['key']).should eq(false)
|
|
481
481
|
end
|
|
482
482
|
|
|
483
483
|
it "should test global keys" do
|
|
484
|
-
res = Algolia.
|
|
485
|
-
newKey = Algolia.
|
|
484
|
+
res = Algolia.list_api_keys
|
|
485
|
+
newKey = Algolia.add_api_key(['search'])
|
|
486
486
|
newKey['key'].should_not eq("")
|
|
487
487
|
wait_global_key(newKey['key'])
|
|
488
|
-
resAfter = Algolia.
|
|
488
|
+
resAfter = Algolia.list_api_keys
|
|
489
489
|
is_include(res['keys'], 'value', newKey['key']).should eq(false)
|
|
490
490
|
is_include(resAfter['keys'], 'value', newKey['key']).should eq(true)
|
|
491
|
-
key = Algolia.
|
|
491
|
+
key = Algolia.get_api_key(newKey['key'])
|
|
492
492
|
key['acl'][0].should eq('search')
|
|
493
|
-
Algolia.
|
|
493
|
+
Algolia.update_api_key(newKey['key'], ['addObject'])
|
|
494
494
|
wait_global_key(newKey['key']) do |key|
|
|
495
495
|
key['acl'] == ['addObject']
|
|
496
496
|
end
|
|
497
|
-
key = Algolia.
|
|
497
|
+
key = Algolia.get_api_key(newKey['key'])
|
|
498
498
|
key['acl'][0].should eq('addObject')
|
|
499
|
-
Algolia.
|
|
499
|
+
Algolia.delete_api_key(newKey['key'])
|
|
500
500
|
wait_global_key_missing(newKey['key'])
|
|
501
|
-
resEnd = Algolia.
|
|
501
|
+
resEnd = Algolia.list_api_keys
|
|
502
502
|
is_include(resEnd['keys'], 'value', newKey['key']).should eq(false)
|
|
503
503
|
end
|
|
504
504
|
|
|
@@ -692,13 +692,13 @@ describe 'Client' do
|
|
|
692
692
|
end
|
|
693
693
|
|
|
694
694
|
it "Check add keys" do
|
|
695
|
-
newIndexKey = @index.
|
|
695
|
+
newIndexKey = @index.add_api_key(['search'])
|
|
696
696
|
newIndexKey.should have_key('key')
|
|
697
697
|
newIndexKey['key'].should be_a(String)
|
|
698
698
|
newIndexKey.should have_key('createdAt')
|
|
699
699
|
newIndexKey['createdAt'].should be_a(String)
|
|
700
700
|
sleep 5 # no task ID here
|
|
701
|
-
resIndex = @index.
|
|
701
|
+
resIndex = @index.list_api_keys
|
|
702
702
|
resIndex.should have_key('keys')
|
|
703
703
|
resIndex['keys'].should be_a(Array)
|
|
704
704
|
resIndex['keys'][0].should have_key('value')
|
|
@@ -707,14 +707,14 @@ describe 'Client' do
|
|
|
707
707
|
resIndex['keys'][0]['acl'].should be_a(Array)
|
|
708
708
|
resIndex['keys'][0].should have_key('validity')
|
|
709
709
|
resIndex['keys'][0]['validity'].should be_a(Integer)
|
|
710
|
-
indexKey = @index.
|
|
710
|
+
indexKey = @index.get_api_key(newIndexKey['key'])
|
|
711
711
|
indexKey.should have_key('value')
|
|
712
712
|
indexKey['value'].should be_a(String)
|
|
713
713
|
indexKey.should have_key('acl')
|
|
714
714
|
indexKey['acl'].should be_a(Array)
|
|
715
715
|
indexKey.should have_key('validity')
|
|
716
716
|
indexKey['validity'].should be_a(Integer)
|
|
717
|
-
task = @index.
|
|
717
|
+
task = @index.delete_api_key(newIndexKey['key'])
|
|
718
718
|
task.should have_key('deletedAt')
|
|
719
719
|
task['deletedAt'].should be_a(String)
|
|
720
720
|
end
|
data/spec/mock_spec.rb
CHANGED
|
@@ -19,7 +19,7 @@ describe 'With a mocked client' do
|
|
|
19
19
|
index = Algolia::Index.new("friends")
|
|
20
20
|
index.add_object!({ :name => "John Doe", :email => "john@doe.org" })
|
|
21
21
|
index.search('').should == { "hits" => [ { "objectID" => 42 } ], "page" => 1, "hitsPerPage" => 1 } # mocked
|
|
22
|
-
index.
|
|
22
|
+
index.list_api_keys
|
|
23
23
|
index.browse
|
|
24
24
|
index.clear
|
|
25
25
|
index.delete
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: algoliasearch
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.12.
|
|
4
|
+
version: 1.12.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Algolia
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-01
|
|
11
|
+
date: 2017-03-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httpclient
|
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
131
131
|
version: '0'
|
|
132
132
|
requirements: []
|
|
133
133
|
rubyforge_project:
|
|
134
|
-
rubygems_version: 2.
|
|
134
|
+
rubygems_version: 2.5.1
|
|
135
135
|
signing_key:
|
|
136
136
|
specification_version: 4
|
|
137
137
|
summary: A simple Ruby client for the algolia.com REST API
|