public class APIClient extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
APIClient.IndexQuery |
static class |
APIClient.LogType |
| Constructor and Description |
|---|
APIClient(String applicationID,
String apiKey)
Algolia Search initialization
|
APIClient(String applicationID,
String apiKey,
List<String> hostsArray)
Algolia Search initialization
|
APIClient(String applicationID,
String apiKey,
List<String> buildHostsArray,
List<String> queryHostArray)
Algolia Search initialization
|
| Modifier and Type | Method and Description |
|---|---|
org.json.JSONObject |
addUserKey(org.json.JSONObject params)
Create a new user key
|
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 |
batch(org.json.JSONArray actions)
Custom batch
|
org.json.JSONObject |
batch(List<org.json.JSONObject> actions)
Custom batch
|
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,
boolean build) |
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,
Query query)
Generate a secured and public API Key from a query and an
optional user token identifying the current user
|
String |
generateSecuredApiKey(String privateApiKey,
Query query,
String userToken)
Generate a secured and public API Key from a query and an
optional user token identifying the current user
|
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,
boolean search) |
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
|
org.json.JSONObject |
multipleQueries(List<APIClient.IndexQuery> queries,
String strategy) |
protected org.json.JSONObject |
postRequest(String url,
String obj,
boolean build,
boolean search) |
protected org.json.JSONObject |
putRequest(String url,
String obj,
boolean build) |
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,
org.json.JSONObject params)
Update a user key
|
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
|
public APIClient(String applicationID, String apiKey)
applicationID - the application ID you have in your admin interfaceapiKey - a valid API key for the servicepublic APIClient(String applicationID, String apiKey, List<String> hostsArray)
applicationID - the application ID you have in your admin interfaceapiKey - a valid API key for the servicehostsArray - the list of hosts that you have received for the servicepublic APIClient(String applicationID, String apiKey, List<String> buildHostsArray, List<String> queryHostArray)
applicationID - the application ID you have in your admin interfaceapiKey - a valid API key for the servicebuildHostsArray - the list of hosts that you have received for the servicequeryHostsArray - the list of hosts that you have received for the servicepublic void enableRateLimitForward(String adminAPIKey, String endUserIP, String rateLimitAPIKey)
adminAPIKey - the admin API Key you can find in your dashboardendUserIP - the end user IP (you can use both IPV4 or IPV6 syntax)rateLimitAPIKey - the API key on which you have a rate limitpublic void disableRateLimitForward()
public void setTimeout(int connectTimeout,
int readTimeout)
connectTimeout - connection timeout in MSreadTimeout - socket timeout in MSpublic org.json.JSONObject listIndexes()
throws AlgoliaException
AlgoliaExceptionpublic org.json.JSONObject deleteIndex(String indexName) throws AlgoliaException
indexName - the name of index to delete
return an object containing a "deletedAt" attributeAlgoliaExceptionpublic org.json.JSONObject moveIndex(String srcIndexName, String dstIndexName) throws AlgoliaException
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).AlgoliaExceptionpublic org.json.JSONObject copyIndex(String srcIndexName, String dstIndexName) throws AlgoliaException
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).AlgoliaExceptionpublic org.json.JSONObject getLogs()
throws AlgoliaException
AlgoliaExceptionpublic org.json.JSONObject getLogs(int offset,
int length)
throws AlgoliaException
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.AlgoliaExceptionpublic org.json.JSONObject getLogs(int offset,
int length,
boolean onlyErrors)
throws AlgoliaException
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 201AlgoliaExceptionpublic org.json.JSONObject getLogs(int offset,
int length,
APIClient.LogType logType)
throws AlgoliaException
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 retrieveAlgoliaExceptionpublic Index initIndex(String indexName)
indexName - the name of indexpublic org.json.JSONObject listUserKeys()
throws AlgoliaException
AlgoliaExceptionpublic org.json.JSONObject getUserKeyACL(String key) throws AlgoliaException
AlgoliaExceptionpublic org.json.JSONObject deleteUserKey(String key) throws AlgoliaException
AlgoliaExceptionpublic org.json.JSONObject addUserKey(org.json.JSONObject params)
throws AlgoliaException
params - the list of parameters for this key. Defined by a JSONObject that
can contains the following values:
- acl: array of string
- indices: array of string
- validity: int
- referers: array of string
- description: string
- maxHitsPerQuery: integer
- queryParameters: string
- maxQueriesPerIPPerHour: integerAlgoliaExceptionpublic org.json.JSONObject addUserKey(List<String> acls) throws AlgoliaException
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)AlgoliaExceptionpublic org.json.JSONObject updateUserKey(String key, org.json.JSONObject params) throws AlgoliaException
params - the list of parameters for this key. Defined by a JSONObject that
can contains the following values:
- acl: array of string
- indices: array of string
- validity: int
- referers: array of string
- description: string
- maxHitsPerQuery: integer
- queryParameters: string
- maxQueriesPerIPPerHour: integerAlgoliaExceptionpublic org.json.JSONObject updateUserKey(String key, List<String> acls) throws AlgoliaException
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)AlgoliaExceptionpublic org.json.JSONObject addUserKey(List<String> acls, int validity, int maxQueriesPerIPPerHour, int maxHitsPerQuery) throws AlgoliaException
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)AlgoliaExceptionpublic org.json.JSONObject updateUserKey(String key, List<String> acls, int validity, int maxQueriesPerIPPerHour, int maxHitsPerQuery) throws AlgoliaException
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)AlgoliaExceptionpublic org.json.JSONObject addUserKey(List<String> acls, int validity, int maxQueriesPerIPPerHour, int maxHitsPerQuery, List<String> indexes) throws AlgoliaException
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 indexesAlgoliaExceptionpublic org.json.JSONObject updateUserKey(String key, List<String> acls, int validity, int maxQueriesPerIPPerHour, int maxHitsPerQuery, List<String> indexes) throws AlgoliaException
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 indexesAlgoliaExceptionpublic String generateSecuredApiKey(String privateApiKey, String tagFilters) throws NoSuchAlgorithmException, InvalidKeyException
privateApiKey - your private API KeytagFilters - the list of tags applied to the query (used as security)NoSuchAlgorithmExceptionInvalidKeyExceptionpublic String generateSecuredApiKey(String privateApiKey, Query query) throws NoSuchAlgorithmException, InvalidKeyException
privateApiKey - your private API Keyquery - contains the parameter applied to the query (used as security)NoSuchAlgorithmExceptionInvalidKeyExceptionpublic String generateSecuredApiKey(String privateApiKey, String tagFilters, String userToken) throws NoSuchAlgorithmException, InvalidKeyException
privateApiKey - your private API KeytagFilters - the list of tags applied to the query (used as security)userToken - an optional token identifying the current userNoSuchAlgorithmExceptionInvalidKeyExceptionpublic String generateSecuredApiKey(String privateApiKey, Query query, String userToken) throws NoSuchAlgorithmException, InvalidKeyException
privateApiKey - your private API Keyquery - contains the parameter applied to the query (used as security)userToken - an optional token identifying the current userNoSuchAlgorithmExceptionInvalidKeyExceptionprotected org.json.JSONObject getRequest(String url, boolean search) throws AlgoliaException
AlgoliaExceptionprotected org.json.JSONObject deleteRequest(String url, boolean build) throws AlgoliaException
AlgoliaExceptionprotected org.json.JSONObject postRequest(String url, String obj, boolean build, boolean search) throws AlgoliaException
AlgoliaExceptionprotected org.json.JSONObject putRequest(String url, String obj, boolean build) throws AlgoliaException
AlgoliaExceptionpublic org.json.JSONObject multipleQueries(List<APIClient.IndexQuery> queries) throws AlgoliaException
AlgoliaExceptionpublic org.json.JSONObject multipleQueries(List<APIClient.IndexQuery> queries, String strategy) throws AlgoliaException
AlgoliaExceptionpublic org.json.JSONObject batch(org.json.JSONArray actions)
throws AlgoliaException
actions - the array of actionsAlgoliaExceptionpublic org.json.JSONObject batch(List<org.json.JSONObject> actions) throws AlgoliaException
actions - the array of actionsAlgoliaExceptionCopyright © 2015. All rights reserved.