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
3 changes: 3 additions & 0 deletions .fernignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# Specify files that shouldn't be modified by Fern
src/main/java/com/schematic/api/Schematic.java
src/main/java/com/schematic/api/BaseSchematic.java
src/main/java/com/schematic/api/Schematic.java
2 changes: 1 addition & 1 deletion sample-app/src/main/java/sample/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

public final class App {
public static void main(String[] args) {
// import com.schematic.api.SchematicApiClient
// import com.schematic.api.BaseSchematic
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
*/
package com.schematic.api;

import com.schematic.api.core.BaseSchematicApiException;
import com.schematic.api.core.BaseSchematicException;
import com.schematic.api.core.ClientOptions;
import com.schematic.api.core.ObjectMappers;
import com.schematic.api.core.RequestOptions;
import com.schematic.api.core.SchematicApiApiException;
import com.schematic.api.core.SchematicApiException;
import com.schematic.api.core.Suppliers;
import com.schematic.api.resources.accesstokens.AccesstokensClient;
import com.schematic.api.resources.accounts.AccountsClient;
Expand All @@ -30,7 +30,7 @@
import okhttp3.Response;
import okhttp3.ResponseBody;

public class SchematicApiClient {
public class BaseSchematic {
protected final ClientOptions clientOptions;

protected final Supplier<AccountsClient> accountsClient;
Expand All @@ -57,7 +57,7 @@ public class SchematicApiClient {

protected final Supplier<WebhooksClient> webhooksClient;

public SchematicApiClient(ClientOptions clientOptions) {
public BaseSchematic(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
this.accountsClient = Suppliers.memoize(() -> new AccountsClient(clientOptions));
this.featuresClient = Suppliers.memoize(() -> new FeaturesClient(clientOptions));
Expand Down Expand Up @@ -97,12 +97,12 @@ public void getCompanyPlans(RequestOptions requestOptions) {
return;
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
throw new SchematicApiApiException(
throw new BaseSchematicApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
} catch (IOException e) {
throw new SchematicApiException("Network error executing HTTP request", e);
throw new BaseSchematicException("Network error executing HTTP request", e);
}
}

Expand Down Expand Up @@ -153,8 +153,4 @@ public AccesstokensClient accesstokens() {
public WebhooksClient webhooks() {
return this.webhooksClient.get();
}

public static SchematicApiClientBuilder builder() {
return new SchematicApiClientBuilder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.schematic.api.core.ClientOptions;
import com.schematic.api.core.Environment;

public final class SchematicApiClientBuilder {
public final class BaseSchematicBuilder {
private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder();

private String apiKey = null;
Expand All @@ -16,27 +16,27 @@ public final class SchematicApiClientBuilder {
/**
* Sets apiKey
*/
public SchematicApiClientBuilder apiKey(String apiKey) {
public BaseSchematicBuilder apiKey(String apiKey) {
this.apiKey = apiKey;
return this;
}

public SchematicApiClientBuilder environment(Environment environment) {
public BaseSchematicBuilder environment(Environment environment) {
this.environment = environment;
return this;
}

public SchematicApiClientBuilder url(String url) {
public BaseSchematicBuilder url(String url) {
this.environment = Environment.custom(url);
return this;
}

public SchematicApiClient build() {
public BaseSchematic build() {
if (apiKey == null) {
throw new RuntimeException("Please provide apiKey");
}
this.clientOptionsBuilder.addHeader("X-Schematic-Api-Key", this.apiKey);
clientOptionsBuilder.environment(this.environment);
return new SchematicApiClient(clientOptionsBuilder.build());
return new BaseSchematic(clientOptionsBuilder.build());
}
}
53 changes: 53 additions & 0 deletions src/main/java/com/schematic/api/Schematic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.schematic.api;

import com.schematic.api.core.ClientOptions;
import com.schematic.api.core.Environment;

public final class Schematic extends BaseSchematic {

public Schematic(ClientOptions clientOptions) {
super(clientOptions);
}

// TODO: add custom methods here

public static Schematic.Builder builder() {
return new Builder();
}

public static final class Builder {
private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder();

private String apiKey = null;

private Environment environment = Environment.DEFAULT;

/**
* Sets apiKey
*/
public Builder apiKey(String apiKey) {
this.apiKey = apiKey;
return this;
}

public Builder environment(Environment environment) {
this.environment = environment;
return this;
}

public Builder url(String url) {
this.environment = Environment.custom(url);
return this;
}

public BaseSchematic build() {
if (apiKey == null) {
throw new RuntimeException("Please provide apiKey");
}
this.clientOptionsBuilder.addHeader("X-Schematic-Api-Key", this.apiKey);
clientOptionsBuilder.environment(this.environment);
return new BaseSchematic(clientOptionsBuilder.build());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* This exception type will be thrown for any non-2XX API responses.
*/
public class SchematicApiApiException extends SchematicApiException {
public class BaseSchematicApiException extends BaseSchematicException {
/**
* The error code of the response that triggered the exception.
*/
Expand All @@ -17,7 +17,7 @@ public class SchematicApiApiException extends SchematicApiException {
*/
private final Object body;

public SchematicApiApiException(String message, int statusCode, Object body) {
public BaseSchematicApiException(String message, int statusCode, Object body) {
super(message);
this.statusCode = statusCode;
this.body = body;
Expand All @@ -39,7 +39,7 @@ public Object body() {

@java.lang.Override
public String toString() {
return "SchematicApiApiException{" + "message: " + getMessage() + ", statusCode: " + statusCode + ", body: "
return "BaseSchematicApiException{" + "message: " + getMessage() + ", statusCode: " + statusCode + ", body: "
+ body + "}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
/**
* This class serves as the base exception for all errors in the SDK.
*/
public class SchematicApiException extends RuntimeException {
public SchematicApiException(String message) {
public class BaseSchematicException extends RuntimeException {
public BaseSchematicException(String message) {
super(message);
}

public SchematicApiException(String message, Exception e) {
public BaseSchematicException(String message, Exception e) {
super(message, e);
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/schematic/api/errors/BadRequestError.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
*/
package com.schematic.api.errors;

import com.schematic.api.core.SchematicApiApiException;
import com.schematic.api.core.BaseSchematicApiException;
import com.schematic.api.types.ApiError;

public final class BadRequestError extends SchematicApiApiException {
public final class BadRequestError extends BaseSchematicApiException {
/**
* The body of the response that triggered the exception.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/schematic/api/errors/ForbiddenError.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
*/
package com.schematic.api.errors;

import com.schematic.api.core.SchematicApiApiException;
import com.schematic.api.core.BaseSchematicApiException;
import com.schematic.api.types.ApiError;

public final class ForbiddenError extends SchematicApiApiException {
public final class ForbiddenError extends BaseSchematicApiException {
/**
* The body of the response that triggered the exception.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
*/
package com.schematic.api.errors;

import com.schematic.api.core.SchematicApiApiException;
import com.schematic.api.core.BaseSchematicApiException;
import com.schematic.api.types.ApiError;

public final class InternalServerError extends SchematicApiApiException {
public final class InternalServerError extends BaseSchematicApiException {
/**
* The body of the response that triggered the exception.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/schematic/api/errors/NotFoundError.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
*/
package com.schematic.api.errors;

import com.schematic.api.core.SchematicApiApiException;
import com.schematic.api.core.BaseSchematicApiException;
import com.schematic.api.types.ApiError;

public final class NotFoundError extends SchematicApiApiException {
public final class NotFoundError extends BaseSchematicApiException {
/**
* The body of the response that triggered the exception.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
*/
package com.schematic.api.errors;

import com.schematic.api.core.SchematicApiApiException;
import com.schematic.api.core.BaseSchematicApiException;
import com.schematic.api.types.ApiError;

public final class UnauthorizedError extends SchematicApiApiException {
public final class UnauthorizedError extends BaseSchematicApiException {
/**
* The body of the response that triggered the exception.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
package com.schematic.api.resources.accesstokens;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.schematic.api.core.BaseSchematicApiException;
import com.schematic.api.core.BaseSchematicException;
import com.schematic.api.core.ClientOptions;
import com.schematic.api.core.MediaTypes;
import com.schematic.api.core.ObjectMappers;
import com.schematic.api.core.RequestOptions;
import com.schematic.api.core.SchematicApiApiException;
import com.schematic.api.core.SchematicApiException;
import com.schematic.api.errors.BadRequestError;
import com.schematic.api.errors.ForbiddenError;
import com.schematic.api.errors.InternalServerError;
Expand Down Expand Up @@ -48,7 +48,7 @@ public IssueTemporaryAccessTokenResponse issueTemporaryAccessToken(
body = RequestBody.create(
ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON);
} catch (JsonProcessingException e) {
throw new SchematicApiException("Failed to serialize request", e);
throw new BaseSchematicException("Failed to serialize request", e);
}
Request okhttpRequest = new Request.Builder()
.url(httpUrl)
Expand Down Expand Up @@ -85,12 +85,12 @@ public IssueTemporaryAccessTokenResponse issueTemporaryAccessToken(
} catch (JsonProcessingException ignored) {
// unable to map error response, throwing generic error
}
throw new SchematicApiApiException(
throw new BaseSchematicApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
} catch (IOException e) {
throw new SchematicApiException("Network error executing HTTP request", e);
throw new BaseSchematicException("Network error executing HTTP request", e);
}
}
}
Loading