Skip to content

Commit

Permalink
Add restore_api_key method
Browse files Browse the repository at this point in the history
  • Loading branch information
julienbourdeau committed Feb 11, 2019
1 parent ccb5aef commit c4ce211
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/algolia/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,13 @@ def delete_api_key(key, request_options = {})
delete(Protocol.key_uri(key), :write, request_options)
end

#
# Restore a deleted api key
#
def restore_api_key(key, request_options = {})
post(Protocol.restore_key_uri(key), :write, request_options)
end

#
# Send a batch request targeting multiple indices
#
Expand Down Expand Up @@ -1045,6 +1052,13 @@ def Algolia.delete_api_key(key, request_options = {})
Algolia.client.delete_api_key(key, request_options)
end

#
# Restore an existing api key
#
def Algolia.restore_api_key(key, request_options = {})
Algolia.client.restore_api_key(key, request_options)
end

#
# Deprecated
#
Expand Down
4 changes: 4 additions & 0 deletions lib/algolia/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ def Protocol.key_uri(key)
"/#{VERSION}/keys/#{key}"
end

def Protocol.restore_key_uri(key)
"/#{VERSION}/keys/#{key}/restore"
end

def Protocol.index_key_uri(index, key)
"#{index_uri(index)}/keys/#{key}"
end
Expand Down
10 changes: 10 additions & 0 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def wait_global_key_missing(key)

it "should test index keys" do
@index.set_settings!({}) # ensure the index exists

resIndex = @index.list_api_keys
newIndexKey = @index.add_api_key(['search'])
newIndexKey['key'].should_not eq("")
Expand Down Expand Up @@ -124,6 +125,15 @@ def wait_global_key_missing(key)
wait_global_key_missing(newKey['key'])
resEnd = Algolia.list_api_keys
is_include(resEnd['keys'], 'value', newKey['key']).should eq(false)

# Restore the deleted key
Algolia.restore_api_key(newKey['key'])
wait_global_key(newKey['key'])
key_end = Algolia.list_api_keys
is_include(key_end['keys'], 'value', newKey['key']).should eq(true)

# Re-delete the key
Algolia.delete_api_key(newKey['key'])
end

it "Check add keys" do
Expand Down

0 comments on commit c4ce211

Please sign in to comment.