-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add default utility classes for Java.net client (#772)
- Loading branch information
Showing
5 changed files
with
239 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
algoliasearch-java-net/src/main/java/com/algolia/search/DefaultAnalyticsClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.algolia.search; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Algolia's REST analytics client that wraps an instance of the transporter. which wraps the HTTP | ||
* Client This client allows to build typed requests and read typed responses. Requests are made | ||
* under the Algolia's retry-strategy. This client is intended to be reused and it's thread-safe. | ||
* | ||
* @see <a href="https://www.algolia.com/doc/rest-api/analytics/">Algolia.com</a> | ||
*/ | ||
public class DefaultAnalyticsClient { | ||
|
||
// Suppress default constructor for noninstantiability | ||
private DefaultAnalyticsClient() { | ||
throw new AssertionError(); | ||
} | ||
|
||
/** | ||
* Creates a default {@link AnalyticsClient} with the given credentials. The default HttpClient | ||
* implementation is {@link ApacheHttpRequester} | ||
* | ||
* @param applicationID The Algolia Application ID | ||
* @param apiKey The Algolia API Key | ||
* @throws NullPointerException If one of the following ApplicationID/ApiKey is null | ||
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty | ||
*/ | ||
public static AnalyticsClient create(@Nonnull String applicationID, @Nonnull String apiKey) { | ||
return create(applicationID, apiKey, "us"); | ||
} | ||
|
||
/** | ||
* Creates a default {@link AnalyticsClient} with the given credentials. The default HttpClient | ||
* implementation is {@link ApacheHttpRequester} | ||
* | ||
* @param applicationID The Algolia Application ID | ||
* @param apiKey The Algolia API Key | ||
* @param region The region of the Analytics cluster | ||
* @throws NullPointerException If one of the following ApplicationID/ApiKey is null | ||
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty | ||
*/ | ||
public static AnalyticsClient create( | ||
@Nonnull String applicationID, @Nonnull String apiKey, @Nonnull String region) { | ||
return create(new AnalyticsConfig.Builder(applicationID, apiKey, region).build()); | ||
} | ||
|
||
/** | ||
* Creates a default {@link AnalyticsClient} with the given {@link AnalyticsConfig}. The default | ||
* HttpClient implementation is {@link ApacheHttpRequester} | ||
* | ||
* @param config The configuration allows you to advanced configuration of the clients such as | ||
* batch size or custom hosts and timeout. | ||
* @throws NullPointerException If one of the following ApplicationID/ApiKey/Config is null | ||
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty | ||
*/ | ||
public static AnalyticsClient create(@Nonnull AnalyticsConfig config) { | ||
return new AnalyticsClient(config, new JavaNetHttpRequester(config)); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
algoliasearch-java-net/src/main/java/com/algolia/search/DefaultInsightsClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.algolia.search; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Algolia's REST insights client that wraps an instance of the transporter. which wraps the HTTP | ||
* Client This client allows to build typed requests and read typed responses. Requests are made | ||
* under the Algolia's retry-strategy. This client is intended to be reused and it's thread-safe. | ||
* | ||
* @see <a href="https://www.algolia.com/doc/rest-api/insights/">Algolia.com</a> | ||
*/ | ||
public class DefaultInsightsClient { | ||
|
||
// Suppress default constructor for noninstantiability | ||
private DefaultInsightsClient() { | ||
throw new AssertionError(); | ||
} | ||
|
||
/** | ||
* Creates a default {@link InsightsClient} with the given credentials. The default HttpClient | ||
* implementation is {@link ApacheHttpRequester} | ||
* | ||
* @param applicationID The Algolia Application ID | ||
* @param apiKey The Algolia API Key | ||
* @throws NullPointerException If one of the following ApplicationID/ApiKey is null | ||
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty | ||
*/ | ||
public static InsightsClient create(@Nonnull String applicationID, @Nonnull String apiKey) { | ||
return create(new InsightsConfig.Builder(applicationID, apiKey).build()); | ||
} | ||
|
||
/** | ||
* Creates a default {@link InsightsClient} with the given {@link InsightsConfig}. The default | ||
* HttpClient implementation is {@link ApacheHttpRequester} | ||
* | ||
* @param config The configuration allows you to advanced configuration of the clients such as | ||
* batch size or custom hosts and timeout. | ||
* @throws NullPointerException If one of the following ApplicationID/ApiKey/Config is null | ||
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty | ||
*/ | ||
public static InsightsClient create(@Nonnull InsightsConfig config) { | ||
return new InsightsClient(config, new JavaNetHttpRequester(config)); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
algoliasearch-java-net/src/main/java/com/algolia/search/DefaultPersonalizationClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.algolia.search; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Algolia's REST recommendation client that wraps an instance of the transporter {@link | ||
* HttpTransport} which wraps the HTTP Client This client allows to build typed requests and read | ||
* typed responses. Requests are made under the Algolia's retry-strategy. This client is intended to | ||
* be reused and it's thread-safe. | ||
* | ||
* @see <a href="https://www.algolia.com/doc/rest-api/personalization/">Algolia.com</a> | ||
*/ | ||
public class DefaultPersonalizationClient { | ||
|
||
// Suppress default constructor for noninstantiability | ||
private DefaultPersonalizationClient() { | ||
throw new AssertionError(); | ||
} | ||
|
||
/** | ||
* Creates a {@link PersonalizationClient} with the given credentials The default HttpClient | ||
* implementation is {@link ApacheHttpRequester} | ||
* | ||
* @param applicationID The Algolia Application ID | ||
* @param apiKey The Algolia API Key | ||
* @param region Region where your personalization data is stored and processed. | ||
* @throws NullPointerException If one of the following ApplicationID/ApiKey is null | ||
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty | ||
*/ | ||
public static PersonalizationClient create( | ||
@Nonnull String applicationID, @Nonnull String apiKey, @Nonnull String region) { | ||
return create(new PersonalizationConfig.Builder(applicationID, apiKey, region).build()); | ||
} | ||
|
||
/** | ||
* Creates a default {@link PersonalizationClient} with the given {@link SearchConfig}. The | ||
* default HttpClient implementation is {@link ApacheHttpRequester} | ||
* | ||
* @param config The configuration allows you to advanced configuration of the clients such as | ||
* batch size or custom hosts and timeout. | ||
* @throws NullPointerException If one of the following ApplicationID/ApiKey/Config is null | ||
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty | ||
*/ | ||
public static PersonalizationClient create(@Nonnull PersonalizationConfig config) { | ||
return new PersonalizationClient(config, new JavaNetHttpRequester(config)); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
algoliasearch-java-net/src/main/java/com/algolia/search/DefaultRecommendClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.algolia.search; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Algolia's REST recommend client that wraps an instance of the transporter {@link HttpTransport} | ||
* which wraps the HTTP Client This client allows to build typed requests and read typed responses. | ||
* Requests are made under the Algolia's retry-strategy. This client is intended to be reused, and | ||
* it's thread-safe. | ||
* | ||
* @see <a href="https://www.algolia.com/doc/rest-api/recommend">Algolia.com</a> | ||
*/ | ||
public class DefaultRecommendClient { | ||
|
||
// Suppress default constructor for noninstantiability | ||
private DefaultRecommendClient() { | ||
throw new AssertionError(); | ||
} | ||
|
||
/** | ||
* Creates a {@link RecommendClient} with the given credentials The default HttpClient | ||
* implementation is {@link ApacheHttpRequester} | ||
* | ||
* @param applicationID The Algolia Application ID | ||
* @param apiKey The Algolia API Key | ||
* @throws NullPointerException If one of the following ApplicationID/ApiKey is null | ||
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty | ||
*/ | ||
public static RecommendClient create(@Nonnull String applicationID, @Nonnull String apiKey) { | ||
return create(new SearchConfig.Builder(applicationID, apiKey).build()); | ||
} | ||
|
||
/** | ||
* Creates a default {@link RecommendClient} with the given {@link SearchConfig}. The default | ||
* HttpClient implementation is {@link ApacheHttpRequester} | ||
* | ||
* @param config The configuration allows you to advanced configuration of the clients such as | ||
* batch size or custom hosts and timeout. | ||
* @throws NullPointerException If one of the following ApplicationID/ApiKey/Config is null | ||
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty | ||
*/ | ||
public static RecommendClient create(@Nonnull SearchConfig config) { | ||
return new RecommendClient(config, new JavaNetHttpRequester(config)); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
algoliasearch-java-net/src/main/java/com/algolia/search/DefaultSearchClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.algolia.search; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Algolia's REST search client that wraps an instance of the transporter which wraps the HttpClient | ||
* This client allows to build typed requests and read typed responses. Requests are made under the | ||
* Algolia's retry-strategy. This client is intended to be reused and it's thread-safe. | ||
* | ||
* @see <a href="https://www.algolia.com/doc/rest-api/search/">Algolia.com</a> | ||
*/ | ||
public class DefaultSearchClient { | ||
|
||
// Suppress default constructor for noninstantiability | ||
private DefaultSearchClient() { | ||
throw new AssertionError(); | ||
} | ||
|
||
/** | ||
* Creates a {@link DefaultSearchClient} with the given credentials The default HttpClient | ||
* implementation is {@link JavaNetHttpRequester} | ||
* | ||
* @param applicationID The Algolia Application ID | ||
* @param apiKey The Algolia API Key | ||
* @throws NullPointerException If one of the following ApplicationID/ApiKey is null | ||
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty | ||
*/ | ||
public static SearchClient create(@Nonnull String applicationID, @Nonnull String apiKey) { | ||
return create(new SearchConfig.Builder(applicationID, apiKey).build()); | ||
} | ||
|
||
/** | ||
* Creates a default {@link DefaultSearchClient} with the given {@link SearchConfig}. The default | ||
* HttpClient implementation is {@link ApacheHttpRequester} | ||
* | ||
* @param config The configuration allows you to advanced configuration of the clients such as | ||
* batch size or custom hosts and timeout. | ||
* @throws NullPointerException If one of the following ApplicationID/ApiKey/Config is null | ||
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty | ||
*/ | ||
public static SearchClient create(@Nonnull SearchConfig config) { | ||
return new SearchClient(config, new JavaNetHttpRequester(config)); | ||
} | ||
} |