|
15 | 15 | import io.codebottle.api.model.Snippet; |
16 | 16 | import io.codebottle.api.rest.CodeBottleRequest; |
17 | 17 | import io.codebottle.api.rest.Endpoint; |
18 | | -import lombok.Builder; |
19 | | -import lombok.Getter; |
20 | 18 | import okhttp3.OkHttpClient; |
21 | 19 | import org.jetbrains.annotations.Nullable; |
22 | 20 |
|
23 | 21 | /** |
24 | 22 | * API Class. Create an instance of this using {@code #builder()} to use the API. |
25 | 23 | */ |
26 | | -@Builder |
27 | 24 | public final class CodeBottle { |
28 | 25 | private final Map<String, Language> languageCache = new ConcurrentHashMap<>(); |
29 | 26 | private final Map<String, Category> categoryCache = new ConcurrentHashMap<>(); |
30 | 27 | private final Map<String, Snippet> snippetCache = new ConcurrentHashMap<>(); |
31 | | - @Builder.Default |
32 | | - private final @Nullable String token = null; |
33 | | - @Builder.Default |
34 | | - private @Getter final OkHttpClient httpClient = new OkHttpClient.Builder().build(); |
| 28 | + private final @Nullable String token; |
| 29 | + private final OkHttpClient httpClient; |
35 | 30 | /** |
36 | 31 | * A {@link CompletableFuture} that completes once lazy loading was finished. |
37 | 32 | * <p> |
38 | 33 | * Lazy loading is calling {@link #requestLanguages()} and {@link #requestCategories()} on API construction. |
39 | 34 | */ |
40 | 35 | public final CompletableFuture<Void> lazyLoading = CompletableFuture.allOf(requestLanguages(), requestCategories()); |
41 | 36 |
|
| 37 | + private CodeBottle(@Nullable String token, OkHttpClient httpClient) { |
| 38 | + this.token = token; |
| 39 | + this.httpClient = httpClient; |
| 40 | + } |
| 41 | + |
42 | 42 | /** |
43 | 43 | * Waits for {@linkplain #lazyLoading lazy loading} to finish using {@link CompletableFuture#join()}. |
44 | 44 | * This method is intended to be used for API chaining, otherwise it is recommended to wait for {@link #lazyLoading} yourself. |
@@ -331,4 +331,37 @@ public CompletableFuture<Collection<Snippet.Revision>> requestAllRevisions() { |
331 | 331 | return yields; |
332 | 332 | }); |
333 | 333 | } |
| 334 | + |
| 335 | + public OkHttpClient getHttpClient() { |
| 336 | + return httpClient; |
| 337 | + } |
| 338 | + |
| 339 | + public final static class Builder { |
| 340 | + private @Nullable String token = null; |
| 341 | + private OkHttpClient httpClient = new OkHttpClient.Builder().build(); |
| 342 | + |
| 343 | + public Optional<String> getToken() { |
| 344 | + return Optional.ofNullable(token); |
| 345 | + } |
| 346 | + |
| 347 | + public void setToken(@Nullable String token) { |
| 348 | + this.token = token; |
| 349 | + } |
| 350 | + |
| 351 | + public void removeToken() { |
| 352 | + setToken(null); |
| 353 | + } |
| 354 | + |
| 355 | + public Optional<OkHttpClient> getHttpClient() { |
| 356 | + return Optional.ofNullable(httpClient); |
| 357 | + } |
| 358 | + |
| 359 | + public void setHttpClient(OkHttpClient httpClient) { |
| 360 | + this.httpClient = httpClient; |
| 361 | + } |
| 362 | + |
| 363 | + public CodeBottle build() { |
| 364 | + return new CodeBottle(token, httpClient); |
| 365 | + } |
| 366 | + } |
334 | 367 | } |
0 commit comments