Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:adding API key script #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ruby/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ALGOLIA_APP_ID=
ALGOLIA_API_KEY=
ALGOLIA_INDEX_NAME=
ALGOLIA_INDEX_NAME=
ALGOLIA_SEARCH_API_KEY=
21 changes: 21 additions & 0 deletions ruby/API_key_rate_limit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'dotenv/load'
require 'algolia'

# Algolia client credentials
ALGOLIA_APP_ID = ENV['ALGOLIA_APP_ID']
ALGOLIA_API_KEY = ENV['ALGOLIA_API_KEY']
ALGOLIA_INDEX_NAME = ENV['ALGOLIA_INDEX_NAME']
ALGOLIA_SEARCH_API_KEY = ENV['ALGOLIA_SEARCH_API_KEY']


# Create API rate limit key TODO: generate key
# generate a public API key that is restricted to 'index1' and 'index2':
created_Algolia_API_key = Algolia::Search::Client.generate_secured_api_key(ALGOLIA_SEARCH_API_KEY, { restrictIndices: ALGOLIA_INDEX_NAME })
# generated API key
p 'generated API key'
p created_Algolia_API_key
client2= Algolia::Search::Client.create(ALGOLIA_APP_ID, created_Algolia_API_key)
# Initialize an index
# https://www.algolia.com/doc/api-client/getting-started/instantiate-client-index/#initialize-an-index
index = client2.init_index(ALGOLIA_INDEX_NAME)
# use that key to run a search TODO: run a search