Skip to content

Commit 48aeae3

Browse files
authored
feat: add default utility classes for Java.net client (#772)
1 parent 0e58180 commit 48aeae3

File tree

5 files changed

+239
-0
lines changed

5 files changed

+239
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.algolia.search;
2+
3+
import javax.annotation.Nonnull;
4+
5+
/**
6+
* Algolia's REST analytics client that wraps an instance of the transporter. which wraps the HTTP
7+
* Client This client allows to build typed requests and read typed responses. Requests are made
8+
* under the Algolia's retry-strategy. This client is intended to be reused and it's thread-safe.
9+
*
10+
* @see <a href="https://www.algolia.com/doc/rest-api/analytics/">Algolia.com</a>
11+
*/
12+
public class DefaultAnalyticsClient {
13+
14+
// Suppress default constructor for noninstantiability
15+
private DefaultAnalyticsClient() {
16+
throw new AssertionError();
17+
}
18+
19+
/**
20+
* Creates a default {@link AnalyticsClient} with the given credentials. The default HttpClient
21+
* implementation is {@link ApacheHttpRequester}
22+
*
23+
* @param applicationID The Algolia Application ID
24+
* @param apiKey The Algolia API Key
25+
* @throws NullPointerException If one of the following ApplicationID/ApiKey is null
26+
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty
27+
*/
28+
public static AnalyticsClient create(@Nonnull String applicationID, @Nonnull String apiKey) {
29+
return create(applicationID, apiKey, "us");
30+
}
31+
32+
/**
33+
* Creates a default {@link AnalyticsClient} with the given credentials. The default HttpClient
34+
* implementation is {@link ApacheHttpRequester}
35+
*
36+
* @param applicationID The Algolia Application ID
37+
* @param apiKey The Algolia API Key
38+
* @param region The region of the Analytics cluster
39+
* @throws NullPointerException If one of the following ApplicationID/ApiKey is null
40+
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty
41+
*/
42+
public static AnalyticsClient create(
43+
@Nonnull String applicationID, @Nonnull String apiKey, @Nonnull String region) {
44+
return create(new AnalyticsConfig.Builder(applicationID, apiKey, region).build());
45+
}
46+
47+
/**
48+
* Creates a default {@link AnalyticsClient} with the given {@link AnalyticsConfig}. The default
49+
* HttpClient implementation is {@link ApacheHttpRequester}
50+
*
51+
* @param config The configuration allows you to advanced configuration of the clients such as
52+
* batch size or custom hosts and timeout.
53+
* @throws NullPointerException If one of the following ApplicationID/ApiKey/Config is null
54+
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty
55+
*/
56+
public static AnalyticsClient create(@Nonnull AnalyticsConfig config) {
57+
return new AnalyticsClient(config, new JavaNetHttpRequester(config));
58+
}
59+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.algolia.search;
2+
3+
import javax.annotation.Nonnull;
4+
5+
/**
6+
* Algolia's REST insights client that wraps an instance of the transporter. which wraps the HTTP
7+
* Client This client allows to build typed requests and read typed responses. Requests are made
8+
* under the Algolia's retry-strategy. This client is intended to be reused and it's thread-safe.
9+
*
10+
* @see <a href="https://www.algolia.com/doc/rest-api/insights/">Algolia.com</a>
11+
*/
12+
public class DefaultInsightsClient {
13+
14+
// Suppress default constructor for noninstantiability
15+
private DefaultInsightsClient() {
16+
throw new AssertionError();
17+
}
18+
19+
/**
20+
* Creates a default {@link InsightsClient} with the given credentials. The default HttpClient
21+
* implementation is {@link ApacheHttpRequester}
22+
*
23+
* @param applicationID The Algolia Application ID
24+
* @param apiKey The Algolia API Key
25+
* @throws NullPointerException If one of the following ApplicationID/ApiKey is null
26+
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty
27+
*/
28+
public static InsightsClient create(@Nonnull String applicationID, @Nonnull String apiKey) {
29+
return create(new InsightsConfig.Builder(applicationID, apiKey).build());
30+
}
31+
32+
/**
33+
* Creates a default {@link InsightsClient} with the given {@link InsightsConfig}. The default
34+
* HttpClient implementation is {@link ApacheHttpRequester}
35+
*
36+
* @param config The configuration allows you to advanced configuration of the clients such as
37+
* batch size or custom hosts and timeout.
38+
* @throws NullPointerException If one of the following ApplicationID/ApiKey/Config is null
39+
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty
40+
*/
41+
public static InsightsClient create(@Nonnull InsightsConfig config) {
42+
return new InsightsClient(config, new JavaNetHttpRequester(config));
43+
}
44+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.algolia.search;
2+
3+
import javax.annotation.Nonnull;
4+
5+
/**
6+
* Algolia's REST recommendation client that wraps an instance of the transporter {@link
7+
* HttpTransport} which wraps the HTTP Client This client allows to build typed requests and read
8+
* typed responses. Requests are made under the Algolia's retry-strategy. This client is intended to
9+
* be reused and it's thread-safe.
10+
*
11+
* @see <a href="https://www.algolia.com/doc/rest-api/personalization/">Algolia.com</a>
12+
*/
13+
public class DefaultPersonalizationClient {
14+
15+
// Suppress default constructor for noninstantiability
16+
private DefaultPersonalizationClient() {
17+
throw new AssertionError();
18+
}
19+
20+
/**
21+
* Creates a {@link PersonalizationClient} with the given credentials The default HttpClient
22+
* implementation is {@link ApacheHttpRequester}
23+
*
24+
* @param applicationID The Algolia Application ID
25+
* @param apiKey The Algolia API Key
26+
* @param region Region where your personalization data is stored and processed.
27+
* @throws NullPointerException If one of the following ApplicationID/ApiKey is null
28+
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty
29+
*/
30+
public static PersonalizationClient create(
31+
@Nonnull String applicationID, @Nonnull String apiKey, @Nonnull String region) {
32+
return create(new PersonalizationConfig.Builder(applicationID, apiKey, region).build());
33+
}
34+
35+
/**
36+
* Creates a default {@link PersonalizationClient} with the given {@link SearchConfig}. The
37+
* default HttpClient implementation is {@link ApacheHttpRequester}
38+
*
39+
* @param config The configuration allows you to advanced configuration of the clients such as
40+
* batch size or custom hosts and timeout.
41+
* @throws NullPointerException If one of the following ApplicationID/ApiKey/Config is null
42+
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty
43+
*/
44+
public static PersonalizationClient create(@Nonnull PersonalizationConfig config) {
45+
return new PersonalizationClient(config, new JavaNetHttpRequester(config));
46+
}
47+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.algolia.search;
2+
3+
import javax.annotation.Nonnull;
4+
5+
/**
6+
* Algolia's REST recommend client that wraps an instance of the transporter {@link HttpTransport}
7+
* which wraps the HTTP Client This client allows to build typed requests and read typed responses.
8+
* Requests are made under the Algolia's retry-strategy. This client is intended to be reused, and
9+
* it's thread-safe.
10+
*
11+
* @see <a href="https://www.algolia.com/doc/rest-api/recommend">Algolia.com</a>
12+
*/
13+
public class DefaultRecommendClient {
14+
15+
// Suppress default constructor for noninstantiability
16+
private DefaultRecommendClient() {
17+
throw new AssertionError();
18+
}
19+
20+
/**
21+
* Creates a {@link RecommendClient} with the given credentials The default HttpClient
22+
* implementation is {@link ApacheHttpRequester}
23+
*
24+
* @param applicationID The Algolia Application ID
25+
* @param apiKey The Algolia API Key
26+
* @throws NullPointerException If one of the following ApplicationID/ApiKey is null
27+
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty
28+
*/
29+
public static RecommendClient create(@Nonnull String applicationID, @Nonnull String apiKey) {
30+
return create(new SearchConfig.Builder(applicationID, apiKey).build());
31+
}
32+
33+
/**
34+
* Creates a default {@link RecommendClient} with the given {@link SearchConfig}. The default
35+
* HttpClient implementation is {@link ApacheHttpRequester}
36+
*
37+
* @param config The configuration allows you to advanced configuration of the clients such as
38+
* batch size or custom hosts and timeout.
39+
* @throws NullPointerException If one of the following ApplicationID/ApiKey/Config is null
40+
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty
41+
*/
42+
public static RecommendClient create(@Nonnull SearchConfig config) {
43+
return new RecommendClient(config, new JavaNetHttpRequester(config));
44+
}
45+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.algolia.search;
2+
3+
import javax.annotation.Nonnull;
4+
5+
/**
6+
* Algolia's REST search client that wraps an instance of the transporter which wraps the HttpClient
7+
* This client allows to build typed requests and read typed responses. Requests are made under the
8+
* Algolia's retry-strategy. This client is intended to be reused and it's thread-safe.
9+
*
10+
* @see <a href="https://www.algolia.com/doc/rest-api/search/">Algolia.com</a>
11+
*/
12+
public class DefaultSearchClient {
13+
14+
// Suppress default constructor for noninstantiability
15+
private DefaultSearchClient() {
16+
throw new AssertionError();
17+
}
18+
19+
/**
20+
* Creates a {@link DefaultSearchClient} with the given credentials The default HttpClient
21+
* implementation is {@link JavaNetHttpRequester}
22+
*
23+
* @param applicationID The Algolia Application ID
24+
* @param apiKey The Algolia API Key
25+
* @throws NullPointerException If one of the following ApplicationID/ApiKey is null
26+
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty
27+
*/
28+
public static SearchClient create(@Nonnull String applicationID, @Nonnull String apiKey) {
29+
return create(new SearchConfig.Builder(applicationID, apiKey).build());
30+
}
31+
32+
/**
33+
* Creates a default {@link DefaultSearchClient} with the given {@link SearchConfig}. The default
34+
* HttpClient implementation is {@link ApacheHttpRequester}
35+
*
36+
* @param config The configuration allows you to advanced configuration of the clients such as
37+
* batch size or custom hosts and timeout.
38+
* @throws NullPointerException If one of the following ApplicationID/ApiKey/Config is null
39+
* @throws IllegalArgumentException If the ApplicationID or the APIKey are empty
40+
*/
41+
public static SearchClient create(@Nonnull SearchConfig config) {
42+
return new SearchClient(config, new JavaNetHttpRequester(config));
43+
}
44+
}

0 commit comments

Comments
 (0)