Skip to content

Commit

Permalink
feat: add default utility classes for Java.net client (#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
aallam committed Feb 4, 2022
1 parent 0e58180 commit 48aeae3
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 0 deletions.
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));
}
}
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));
}
}
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));
}
}
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));
}
}
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));
}
}

0 comments on commit 48aeae3

Please sign in to comment.