Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert release #84

Merged
merged 3 commits into from
Dec 8, 2023
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
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,13 @@ Core lib's Maven group ID is `io.apimatic`, and its artifact ID is `core`.
|-------------------------------------------------------------------------|--------------------------------------------------------------------|
| [`ApiCall`](./src/main/java/io/apimatic/core/ApiCall.java) | An API call, or API request, is a message sent to a server asking an API to provide a service or information |
| [`Parameter`](./src/main/java/io/apimatic/core/Parameter.java) | HTTP parameters consist of a type, a name, and a value. These parameters appear in the header and body of an HTTP request. |
| [`ErrorCase`](./src/main/java/io/apimatic/core/ErrorCase.java) | A class which is responsible to generate the SDK Exception |
| [`ErrorCase`](./src/main/java/io/apimatic/core/ErrorCase.java) | A class is responsible to generate the SDK Exception |
| [`GlobalConfiguration`](./src/main/java/io/apimatic/core/GlobalConfiguration.java) | A class which hold the global configuration properties to make a successful Api Call |
| [`HttpRequest`](./src/main/java/io/apimatic/core/HttpRequest.java) | An HTTP request is made by a client, to a named host, which is located on a server |
| [`ResponseHandler`](./src/main/java/io/apimatic/core/ResponseHandler.java) | Handler that encapsulates the process of generating a response object from a Response |
| [`HttpLogger`](./src/main/java/io/apimatic/core/logger/HttpLogger.java) | A class to log the Http events. |
| [`AuthBuilder`](./src/main/java/io/apimatic/core/authentication/AuthBuilder.java) | A class to build and validate provided combination of auth schemes. |
| [`AuthCredential`](./src/main/java/io/apimatic/core/authentication/AuthCredential.java) | A parent class of [`HeaderAuth`](./src/main/java/io/apimatic/core/authentication/HeaderAuth.java) and [`QueryAuth`](./src/main/java/io/apimatic/core/authentication/QueryAuth.java) to hold the common implementation for header and query parameters |
| [`HeaderAuth`](./src/main/java/io/apimatic/core/authentication/HeaderAuth.java) | A class supports HTTP authentication through HTTP Headers |
| [`QueryAuth`](./src/main/java/io/apimatic/core/authentication/QueryAuth.java) | A class supports HTTP authentication through query parameters |
| [`AuthGroup`](./src/main/java/io/apimatic/core/authentication/multiple/AuthGroup.java) | A parent class of [`And`](./src/main/java/io/apimatic/core/authentication/multiple/And.java) and [`Or`](./src/main/java/io/apimatic/core/authentication/multiple/Or.java) to hold the common functionality of multiple auth |
| [`And`](./src/main/java/io/apimatic/core/authentication/multiple/And.java) | A class to hold the algorithm for `And` combination of auth schemes|
| [`Or`](./src/main/java/io/apimatic/core/authentication/multiple/Or.java) | A class to hold the algorithm for `Or` combination of auth schemes |
| [`Single`](./src/main/java/io/apimatic/core/authentication/multiple/Single.java) | A class to hold the logic for single auth scheme, it is used as leaf node for auth combination or it could be used directly to apply one auth only to the http request |
| [`CoreHttpClientConfiguration`](./src/main/java/io/apimatic/core/configurations/http/client/CoreHttpClientConfiguration.java) | To hold HTTP Client Configuration |
| [`ApiLoggingConfiguration`](./src/main/java/io/apimatic/core/configurations/http/client/ApiLoggingConfiguration.java) | To hold logging configuration |
| [`EndpointConfiguration`](./src/main/java/io/apimatic/core/configurations/http/request/EndpointConfiguration.java) | The configuration for an endpoint |
Expand Down
74 changes: 25 additions & 49 deletions src/main/java/io/apimatic/core/HttpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import io.apimatic.core.authentication.AuthBuilder;
import io.apimatic.core.exceptions.AuthValidationException;
import io.apimatic.core.types.http.request.MultipartFileWrapper;
import io.apimatic.core.types.http.request.MultipartWrapper;
import io.apimatic.core.utilities.CoreHelper;
Expand Down Expand Up @@ -57,7 +55,7 @@ public final class HttpRequest {
* @param server
* @param path
* @param httpMethod
* @param authentication
* @param authenticationKey
* @param queryParams
* @param templateParams
* @param headerParams
Expand All @@ -67,18 +65,16 @@ public final class HttpRequest {
* @param bodySerializer
* @param bodyParameters
* @param arraySerializationFormat
* @param isSingleAuth
* @throws IOException
*/
private HttpRequest(final GlobalConfiguration coreConfig, final String server,
final String path, final Method httpMethod, final Authentication authentication,
final String path, final Method httpMethod, final String authenticationKey,
final Map<String, Object> queryParams,
final Map<String, SimpleEntry<Object, Boolean>> templateParams,
final Map<String, List<String>> headerParams, final Set<Parameter> formParams,
final Map<String, Object> formParameters, final Object body,
final Serializer bodySerializer, final Map<String, Object> bodyParameters,
final ArraySerializationFormat arraySerializationFormat,
final boolean isSingleAuth) throws IOException {
final ArraySerializationFormat arraySerializationFormat) throws IOException {
this.coreConfig = coreConfig;
this.compatibilityFactory = coreConfig.getCompatibilityFactory();
urlBuilder = getStringBuilder(server, path);
Expand All @@ -90,7 +86,7 @@ private HttpRequest(final GlobalConfiguration coreConfig, final String server,
coreHttpRequest =
buildRequest(httpMethod, bodyValue, addHeaders(headerParams), queryParams,
formFields, arraySerializationFormat);
applyAuthentication(authentication, isSingleAuth);
applyAuthentication(authenticationKey);
}

/**
Expand All @@ -100,6 +96,21 @@ public Request getCoreHttpRequest() {
return coreHttpRequest;
}

private void applyAuthentication(String authenticationKey) {
if (authenticationKey == null) {
return;
}

Map<String, Authentication> authentications = coreConfig.getAuthentications();
if (authentications != null) {
Authentication authManager = authentications.get(authenticationKey);
if (authManager != null) {
authManager.validate();
authManager.apply(coreHttpRequest);
}
}
}

private Request buildRequest(
Method httpMethod, Object body, HttpHeaders headerParams,
Map<String, Object> queryParams, List<SimpleEntry<String, Object>> formFields,
Expand All @@ -113,22 +124,6 @@ private Request buildRequest(
queryParams, formFields);
}

private void applyAuthentication(Authentication authentication, boolean isSingleAuth) {
if (authentication != null) {
authentication.validate();
if (!authentication.isValid() && !isSingleAuth) {
throw new AuthValidationException(authentication.getErrorMessage());
}

// The following block should be removed with the next major version release.
if (isSingleAuth && authentication.getErrorMessage() != null) {
throw new AuthValidationException(authentication.getErrorMessage());
}

authentication.apply(coreHttpRequest);
}
}

/**
* @param formParams
* @param optionalFormParamaters
Expand Down Expand Up @@ -244,15 +239,9 @@ public static class Builder {
private Method httpMethod;

/**
* An auth builder for the request.
*/
private AuthBuilder authBuilder = new AuthBuilder();

/**
* Flag to use for backward compatibility.
* It should be removed with the next major version release.
* A authentication key string.
*/
private boolean isSingleAuth = false;
private String authenticationKey;

/**
* A map of query parameters.
Expand Down Expand Up @@ -336,23 +325,12 @@ public Builder httpMethod(Method httpMethod) {
}

/**
* Setter for authentication key.
* Setter for requiresAuth.
* @param authenticationKey string value for authenticationKey.
* @return Builder.
*/
public Builder authenticationKey(String authenticationKey) {
authBuilder = authBuilder.add(authenticationKey);
isSingleAuth = true;
return this;
}

/**
* Setter for Authentication Builder, used for authenticating the request.
* @param consumer the builder consumer for authentication.
* @return Builder.
*/
public Builder withAuth(Consumer<AuthBuilder> consumer) {
consumer.accept(authBuilder);
this.authenticationKey = authenticationKey;
return this;
}

Expand Down Expand Up @@ -494,12 +472,10 @@ public Builder arraySerializationFormat(ArraySerializationFormat arraySerializat
* @throws IOException Signals that an I/O exception of some sort has occurred.
*/
public Request build(GlobalConfiguration coreConfig) throws IOException {
Authentication authentication = authBuilder.build(coreConfig.getAuthentications());
HttpRequest coreRequest =
new HttpRequest(coreConfig, server, path, httpMethod, authentication,
new HttpRequest(coreConfig, server, path, httpMethod, authenticationKey,
queryParams, templateParams, headerParams, formParams, formParamaters,
body, bodySerializer, bodyParameters, arraySerializationFormat,
isSingleAuth);
body, bodySerializer, bodyParameters, arraySerializationFormat);
Request coreHttpRequest = coreRequest.getCoreHttpRequest();

if (coreConfig.getHttpCallback() != null) {
Expand Down
139 changes: 0 additions & 139 deletions src/main/java/io/apimatic/core/authentication/AuthBuilder.java

This file was deleted.

52 changes: 0 additions & 52 deletions src/main/java/io/apimatic/core/authentication/AuthCredential.java

This file was deleted.

Loading
Loading