Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
11
17
distribution: 'temurin'
- name: Run tests
run: mvn --batch-mode test
- name: Cache SonarQube packages
uses: actions/cache@v4
with:
Expand All @@ -26,10 +28,11 @@ jobs:
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
if: ${{ github.ref == 'refs/heads/main' }}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: >-
mvn -B verify sonar:sonar
mvn --batch-mode verify sonar:sonar
-Dsonar.java.jdkHome=$JAVA_HOME_11_X64
-Dsonar.projectKey=pgmarc_space-java-client
-Pcoverage
7 changes: 0 additions & 7 deletions src/main/java/io/github/pgmarc/space/App.java

This file was deleted.

98 changes: 0 additions & 98 deletions src/main/java/io/github/pgmarc/space/Config.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package io.github.pgmarc.space.contracts;
package io.github.pgmarc.space;

import java.io.IOException;
import java.util.Objects;

import org.json.JSONObject;

import io.github.pgmarc.space.contracts.Subscription;
import io.github.pgmarc.space.contracts.SubscriptionRequest;
import io.github.pgmarc.space.contracts.SubscriptionUpdateRequest;
import io.github.pgmarc.space.deserializers.ErrorDeserializer;
import io.github.pgmarc.space.deserializers.SubscriptionDeserializer;
import io.github.pgmarc.space.exceptions.SpaceApiException;
Expand Down Expand Up @@ -33,7 +36,7 @@ public final class ContractsEndpoint {
private final ErrorDeserializer errorDeserializer = new ErrorDeserializer();
private final Headers requiredHeaders;

public ContractsEndpoint(OkHttpClient client, HttpUrl baseUrl, String apiKey) {
ContractsEndpoint(OkHttpClient client, HttpUrl baseUrl, String apiKey) {
this.client = client;
this.baseUrl = baseUrl;
this.requiredHeaders = new Headers.Builder().add("Accept", JSON.toString())
Expand Down
107 changes: 107 additions & 0 deletions src/main/java/io/github/pgmarc/space/SpaceClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package io.github.pgmarc.space;

import java.time.Duration;
import java.util.Objects;

import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;

public final class SpaceClient {

private final OkHttpClient httpClient;
private final HttpUrl baseUrl;
private final String apiKey;

private ContractsEndpoint contracts;

private SpaceClient(OkHttpClient httpClient, HttpUrl baseUrl, String apiKey) {
this.httpClient = httpClient;
this.baseUrl = baseUrl;
this.apiKey = apiKey;
}

public ContractsEndpoint contracts() {
if (contracts == null) {
this.contracts = new ContractsEndpoint(httpClient, baseUrl, apiKey);
}
return contracts;
}

public static Builder builder(String host, String apiKey) {
return new Builder(host, apiKey);
}

public static final class Builder {

private static final String DEFAULT_SCHEME = "http";
private static final int DEFAULT_PORT = 5403;
private static final String DEFAULT_API_VERSION = "api/v1";

private final String apiKey;
private final String host;
private int port = DEFAULT_PORT;
private String prefixPath = DEFAULT_API_VERSION;
private Duration readTimeout;
private Duration writeTimeout;

private Builder(String host, String apiKey) {
this.apiKey = apiKey;
this.host = host;
}

public Builder withPort(int port) {
this.port = port;
return this;
}

public Builder withPath(String prefixPath) {
if (prefixPath != null) {
this.prefixPath = prefixPath;
}
return this;
}

public Builder withReadTimeout(Duration duration) {
if (duration != null) {
this.readTimeout = duration;
}
return this;
}

public Builder withWriteTimeout(Duration duration) {
if (duration != null) {
this.writeTimeout = duration;
}
return this;
}

public SpaceClient build() {
Objects.requireNonNull(this.host, "host must not be null");
Objects.requireNonNull(this.apiKey, "api key must not be null");
if (apiKey.isBlank()) {
throw new IllegalArgumentException("api key must not be blank");
}
if (host.isBlank()) {
throw new IllegalArgumentException("host must not be blank");
}
OkHttpClient.Builder httpClientBuilder = new OkHttpClient().newBuilder();

if (readTimeout != null) {
httpClientBuilder.readTimeout(readTimeout);
}

if (writeTimeout != null) {
httpClientBuilder.writeTimeout(writeTimeout);
}

HttpUrl baseUrl = new HttpUrl.Builder()
.scheme(DEFAULT_SCHEME)
.host(host)
.port(port)
.addPathSegments(prefixPath).build();
return new SpaceClient(httpClientBuilder.build(), baseUrl, this.apiKey);
}

}

}
13 changes: 0 additions & 13 deletions src/test/java/io/github/pgmarc/space/AppTest.java

This file was deleted.

72 changes: 0 additions & 72 deletions src/test/java/io/github/pgmarc/space/ConfigTest.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.pgmarc.space.contracts;
package io.github.pgmarc.space;

import java.io.IOException;
import java.time.Duration;
Expand All @@ -9,6 +9,10 @@

import com.github.tomakehurst.wiremock.junit5.WireMockExtension;

import io.github.pgmarc.space.contracts.Subscription;
import io.github.pgmarc.space.contracts.SubscriptionRequest;
import io.github.pgmarc.space.contracts.SubscriptionUpdateRequest;
import io.github.pgmarc.space.contracts.UserContact;
import io.github.pgmarc.space.exceptions.SpaceApiException;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
Expand Down
Loading