com.algolia.search.saas
Class APIClient

java.lang.Object
  extended by com.algolia.search.saas.APIClient

public class APIClient
extends Object

Entry point in the Java API. You should instantiate a Client object with your ApplicationID, ApiKey and Hosts to start using Algolia Search API


Nested Class Summary
static class APIClient.IndexQuery
           
static class APIClient.LogType
           
 
Constructor Summary
APIClient(String applicationID, String apiKey)
          Algolia Search initialization
APIClient(String applicationID, String apiKey, List<String> hostsArray)
          Algolia Search initialization
 
Method Summary
 org.json.JSONObject addUserKey(List<String> acls)
          Create a new user key
 org.json.JSONObject addUserKey(List<String> acls, int validity, int maxQueriesPerIPPerHour, int maxHitsPerQuery)
          Create a new user key
 org.json.JSONObject addUserKey(List<String> acls, int validity, int maxQueriesPerIPPerHour, int maxHitsPerQuery, List<String> indexes)
          Create a new user key
 org.json.JSONObject copyIndex(String srcIndexName, String dstIndexName)
          Copy an existing index.
 org.json.JSONObject deleteIndex(String indexName)
          Delete an index
protected  org.json.JSONObject deleteRequest(String url)
           
 org.json.JSONObject deleteUserKey(String key)
          Delete an existing user key
 void disableRateLimitForward()
          Disable IP rate limit enabled with enableRateLimitForward() function
 void enableRateLimitForward(String adminAPIKey, String endUserIP, String rateLimitAPIKey)
          Allow to use IP rate limit when you have a proxy between end-user and Algolia.
 String generateSecuredApiKey(String privateApiKey, String tagFilters)
          Generate a secured and public API Key from a list of tagFilters and an optional user token identifying the current user
 String generateSecuredApiKey(String privateApiKey, String tagFilters, String userToken)
          Generate a secured and public API Key from a list of tagFilters and an optional user token identifying the current user
 org.json.JSONObject getLogs()
          Return 10 last log entries.
 org.json.JSONObject getLogs(int offset, int length)
          Return last logs entries.
 org.json.JSONObject getLogs(int offset, int length, APIClient.LogType logType)
          Return last logs entries.
 org.json.JSONObject getLogs(int offset, int length, boolean onlyErrors)
          Return last logs entries.
protected  org.json.JSONObject getRequest(String url)
           
 org.json.JSONObject getUserKeyACL(String key)
          Get ACL of a user key
 Index initIndex(String indexName)
          Get the index object initialized (no server call needed for initialization)
 org.json.JSONObject listIndexes()
          List all existing indexes return an JSON Object in the form: { "items": [ {"name": "contacts", "createdAt": "2013-01-18T15:33:13.556Z"}, {"name": "notes", "createdAt": "2013-01-18T15:33:13.556Z"}]}
 org.json.JSONObject listUserKeys()
          List all existing user keys with their associated ACLs
 org.json.JSONObject moveIndex(String srcIndexName, String dstIndexName)
          Move an existing index.
 org.json.JSONObject multipleQueries(List<APIClient.IndexQuery> queries)
          This method allows to query multiple indexes with one API call
protected  org.json.JSONObject postRequest(String url, String obj)
           
protected  org.json.JSONObject putRequest(String url, String obj)
           
 void setExtraHeader(String key, String value)
          Allow to set custom headers
 void setTimeout(int connectTimeout, int readTimeout)
          Allow to set the timeout
 org.json.JSONObject updateUserKey(String key, List<String> acls)
          Update a user key
 org.json.JSONObject updateUserKey(String key, List<String> acls, int validity, int maxQueriesPerIPPerHour, int maxHitsPerQuery)
          Update a user key
 org.json.JSONObject updateUserKey(String key, List<String> acls, int validity, int maxQueriesPerIPPerHour, int maxHitsPerQuery, List<String> indexes)
          Update a user key
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

APIClient

public APIClient(String applicationID,
                 String apiKey)
Algolia Search initialization

Parameters:
applicationID - the application ID you have in your admin interface
apiKey - a valid API key for the service

APIClient

public APIClient(String applicationID,
                 String apiKey,
                 List<String> hostsArray)
Algolia Search initialization

Parameters:
applicationID - the application ID you have in your admin interface
apiKey - a valid API key for the service
hostsArray - the list of hosts that you have received for the service
Method Detail

enableRateLimitForward

public void enableRateLimitForward(String adminAPIKey,
                                   String endUserIP,
                                   String rateLimitAPIKey)
Allow to use IP rate limit when you have a proxy between end-user and Algolia. This option will set the X-Forwarded-For HTTP header with the client IP and the X-Forwarded-API-Key with the API Key having rate limits.

Parameters:
adminAPIKey - the admin API Key you can find in your dashboard
endUserIP - the end user IP (you can use both IPV4 or IPV6 syntax)
rateLimitAPIKey - the API key on which you have a rate limit

disableRateLimitForward

public void disableRateLimitForward()
Disable IP rate limit enabled with enableRateLimitForward() function


setExtraHeader

public void setExtraHeader(String key,
                           String value)
Allow to set custom headers


setTimeout

public void setTimeout(int connectTimeout,
                       int readTimeout)
Allow to set the timeout

Parameters:
connectTimeout - connection timeout in MS
readTimeout - socket timeout in MS

listIndexes

public org.json.JSONObject listIndexes()
                                throws AlgoliaException
List all existing indexes return an JSON Object in the form: { "items": [ {"name": "contacts", "createdAt": "2013-01-18T15:33:13.556Z"}, {"name": "notes", "createdAt": "2013-01-18T15:33:13.556Z"}]}

Throws:
AlgoliaException

deleteIndex

public org.json.JSONObject deleteIndex(String indexName)
                                throws AlgoliaException
Delete an index

Parameters:
indexName - the name of index to delete return an object containing a "deletedAt" attribute
Throws:
AlgoliaException

moveIndex

public org.json.JSONObject moveIndex(String srcIndexName,
                                     String dstIndexName)
                              throws AlgoliaException
Move an existing index.

Parameters:
srcIndexName - the name of index to copy.
dstIndexName - the new index name that will contains a copy of srcIndexName (destination will be overriten if it already exist).
Throws:
AlgoliaException

copyIndex

public org.json.JSONObject copyIndex(String srcIndexName,
                                     String dstIndexName)
                              throws AlgoliaException
Copy an existing index.

Parameters:
srcIndexName - the name of index to copy.
dstIndexName - the new index name that will contains a copy of srcIndexName (destination will be overriten if it already exist).
Throws:
AlgoliaException

getLogs

public org.json.JSONObject getLogs()
                            throws AlgoliaException
Return 10 last log entries.

Throws:
AlgoliaException

getLogs

public org.json.JSONObject getLogs(int offset,
                                   int length)
                            throws AlgoliaException
Return last logs entries.

Parameters:
offset - Specify the first entry to retrieve (0-based, 0 is the most recent log entry).
length - Specify the maximum number of entries to retrieve starting at offset. Maximum allowed value: 1000.
Throws:
AlgoliaException

getLogs

public org.json.JSONObject getLogs(int offset,
                                   int length,
                                   boolean onlyErrors)
                            throws AlgoliaException
Return last logs entries.

Parameters:
offset - Specify the first entry to retrieve (0-based, 0 is the most recent log entry).
length - Specify the maximum number of entries to retrieve starting at offset. Maximum allowed value: 1000.
onlyErrors - Retrieve only logs with an httpCode different than 200 and 201
Throws:
AlgoliaException

getLogs

public org.json.JSONObject getLogs(int offset,
                                   int length,
                                   APIClient.LogType logType)
                            throws AlgoliaException
Return last logs entries.

Parameters:
offset - Specify the first entry to retrieve (0-based, 0 is the most recent log entry).
length - Specify the maximum number of entries to retrieve starting at offset. Maximum allowed value: 1000.
logType - Specify the type of log to retrieve
Throws:
AlgoliaException

initIndex

public Index initIndex(String indexName)
Get the index object initialized (no server call needed for initialization)

Parameters:
indexName - the name of index

listUserKeys

public org.json.JSONObject listUserKeys()
                                 throws AlgoliaException
List all existing user keys with their associated ACLs

Throws:
AlgoliaException

getUserKeyACL

public org.json.JSONObject getUserKeyACL(String key)
                                  throws AlgoliaException
Get ACL of a user key

Throws:
AlgoliaException

deleteUserKey

public org.json.JSONObject deleteUserKey(String key)
                                  throws AlgoliaException
Delete an existing user key

Throws:
AlgoliaException

addUserKey

public org.json.JSONObject addUserKey(List<String> acls)
                               throws AlgoliaException
Create a new user key

Parameters:
acls - the list of ACL for this key. Defined by an array of strings that can contains the following values: - search: allow to search (https and http) - addObject: allows to add/update an object in the index (https only) - deleteObject : allows to delete an existing object (https only) - deleteIndex : allows to delete index content (https only) - settings : allows to get index settings (https only) - editSettings : allows to change index settings (https only)
Throws:
AlgoliaException

updateUserKey

public org.json.JSONObject updateUserKey(String key,
                                         List<String> acls)
                                  throws AlgoliaException
Update a user key

Parameters:
acls - the list of ACL for this key. Defined by an array of strings that can contains the following values: - search: allow to search (https and http) - addObject: allows to add/update an object in the index (https only) - deleteObject : allows to delete an existing object (https only) - deleteIndex : allows to delete index content (https only) - settings : allows to get index settings (https only) - editSettings : allows to change index settings (https only)
Throws:
AlgoliaException

addUserKey

public org.json.JSONObject addUserKey(List<String> acls,
                                      int validity,
                                      int maxQueriesPerIPPerHour,
                                      int maxHitsPerQuery)
                               throws AlgoliaException
Create a new user key

Parameters:
acls - the list of ACL for this key. Defined by an array of strings that can contains the following values: - search: allow to search (https and http) - addObject: allows to add/update an object in the index (https only) - deleteObject : allows to delete an existing object (https only) - deleteIndex : allows to delete index content (https only) - settings : allows to get index settings (https only) - editSettings : allows to change index settings (https only)
validity - the number of seconds after which the key will be automatically removed (0 means no time limit for this key)
maxQueriesPerIPPerHour - Specify the maximum number of API calls allowed from an IP address per hour. Defaults to 0 (no rate limit).
maxHitsPerQuery - Specify the maximum number of hits this API key can retrieve in one call. Defaults to 0 (unlimited)
Throws:
AlgoliaException

updateUserKey

public org.json.JSONObject updateUserKey(String key,
                                         List<String> acls,
                                         int validity,
                                         int maxQueriesPerIPPerHour,
                                         int maxHitsPerQuery)
                                  throws AlgoliaException
Update a user key

Parameters:
acls - the list of ACL for this key. Defined by an array of strings that can contains the following values: - search: allow to search (https and http) - addObject: allows to add/update an object in the index (https only) - deleteObject : allows to delete an existing object (https only) - deleteIndex : allows to delete index content (https only) - settings : allows to get index settings (https only) - editSettings : allows to change index settings (https only)
validity - the number of seconds after which the key will be automatically removed (0 means no time limit for this key)
maxQueriesPerIPPerHour - Specify the maximum number of API calls allowed from an IP address per hour. Defaults to 0 (no rate limit).
maxHitsPerQuery - Specify the maximum number of hits this API key can retrieve in one call. Defaults to 0 (unlimited)
Throws:
AlgoliaException

addUserKey

public org.json.JSONObject addUserKey(List<String> acls,
                                      int validity,
                                      int maxQueriesPerIPPerHour,
                                      int maxHitsPerQuery,
                                      List<String> indexes)
                               throws AlgoliaException
Create a new user key

Parameters:
acls - the list of ACL for this key. Defined by an array of strings that can contains the following values: - search: allow to search (https and http) - addObject: allows to add/update an object in the index (https only) - deleteObject : allows to delete an existing object (https only) - deleteIndex : allows to delete index content (https only) - settings : allows to get index settings (https only) - editSettings : allows to change index settings (https only)
validity - the number of seconds after which the key will be automatically removed (0 means no time limit for this key)
maxQueriesPerIPPerHour - Specify the maximum number of API calls allowed from an IP address per hour. Defaults to 0 (no rate limit).
maxHitsPerQuery - Specify the maximum number of hits this API key can retrieve in one call. Defaults to 0 (unlimited)
indexes - the list of targeted indexes
Throws:
AlgoliaException

updateUserKey

public org.json.JSONObject updateUserKey(String key,
                                         List<String> acls,
                                         int validity,
                                         int maxQueriesPerIPPerHour,
                                         int maxHitsPerQuery,
                                         List<String> indexes)
                                  throws AlgoliaException
Update a user key

Parameters:
acls - the list of ACL for this key. Defined by an array of strings that can contains the following values: - search: allow to search (https and http) - addObject: allows to add/update an object in the index (https only) - deleteObject : allows to delete an existing object (https only) - deleteIndex : allows to delete index content (https only) - settings : allows to get index settings (https only) - editSettings : allows to change index settings (https only)
validity - the number of seconds after which the key will be automatically removed (0 means no time limit for this key)
maxQueriesPerIPPerHour - Specify the maximum number of API calls allowed from an IP address per hour. Defaults to 0 (no rate limit).
maxHitsPerQuery - Specify the maximum number of hits this API key can retrieve in one call. Defaults to 0 (unlimited)
indexes - the list of targeted indexes
Throws:
AlgoliaException

generateSecuredApiKey

public String generateSecuredApiKey(String privateApiKey,
                                    String tagFilters)
                             throws NoSuchAlgorithmException,
                                    InvalidKeyException
Generate a secured and public API Key from a list of tagFilters and an optional user token identifying the current user

Parameters:
privateApiKey - your private API Key
tagFilters - the list of tags applied to the query (used as security)
Throws:
NoSuchAlgorithmException
InvalidKeyException

generateSecuredApiKey

public String generateSecuredApiKey(String privateApiKey,
                                    String tagFilters,
                                    String userToken)
                             throws NoSuchAlgorithmException,
                                    InvalidKeyException
Generate a secured and public API Key from a list of tagFilters and an optional user token identifying the current user

Parameters:
privateApiKey - your private API Key
tagFilters - the list of tags applied to the query (used as security)
userToken - an optional token identifying the current user
Throws:
NoSuchAlgorithmException
InvalidKeyException

getRequest

protected org.json.JSONObject getRequest(String url)
                                  throws AlgoliaException
Throws:
AlgoliaException

deleteRequest

protected org.json.JSONObject deleteRequest(String url)
                                     throws AlgoliaException
Throws:
AlgoliaException

postRequest

protected org.json.JSONObject postRequest(String url,
                                          String obj)
                                   throws AlgoliaException
Throws:
AlgoliaException

putRequest

protected org.json.JSONObject putRequest(String url,
                                         String obj)
                                  throws AlgoliaException
Throws:
AlgoliaException

multipleQueries

public org.json.JSONObject multipleQueries(List<APIClient.IndexQuery> queries)
                                    throws AlgoliaException
This method allows to query multiple indexes with one API call

Throws:
AlgoliaException


Copyright © 2015. All rights reserved.