Skip to content

Commit 58d7299

Browse files
authored
feat: add webhooks and callbacks support (#75)
Adds webhooks and callbacks support to the Java SDK by introducing security verification interfaces for HTTP request signatures. This enables event-driven integration with external systems through standardized verification mechanisms. - Introduces `VerificationResult` interface for representing success/failure states with error messages - Adds `SignatureVerifier` interface for asynchronous HTTP request signature verification - Updates documentation to include the new security interfaces
1 parent 6b543e6 commit 58d7299

4 files changed

Lines changed: 91 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Core Interfaces's Maven group ID is `io.apimatic`, and its artifact ID is `core-
5050
| [`ExceptionCreator`](./src/main/java/io/apimatic/coreinterfaces/type/functional/ExceptionCreator.java) | Functional interface to create the SDK exception |
5151
| [`Serializer`](./src/main/java/io/apimatic/coreinterfaces/type/functional/Serializer.java) | Functional interface to apply the serialization function |
5252
| [`ContextInitializer`](./src/main/java/io/apimatic/coreinterfaces/type/functional/ContextInitializer.java) | Functional Interface to apply the context initialization function for the response models |
53+
| [`SignatureVerifier`](./src/main/java/io/apimatic/coreinterfaces/security/SignatureVerifier.java) | Defines a contract for verifying the signature of an HTTP request |
54+
| [`VerificationResult`](./src/main/java/io/apimatic/coreinterfaces/security/VerificationResult.java) | Represents the result of an operation that can either succeed or fail with an error message |
5355

5456
## Enumerations
5557

sonar-project.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ sonar.sourceEncoding=UTF-8
66

77
sonar.sources=src/main/java
88

9-
sonar.java.binaries=target/classes
9+
sonar.java.binaries=target/classes
10+
11+
# Skip coverage
12+
sonar.coverage.exclusions=**
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.apimatic.coreinterfaces.security;
2+
3+
import io.apimatic.coreinterfaces.http.request.Request;
4+
5+
import java.util.concurrent.CompletableFuture;
6+
7+
/**
8+
* Defines a contract for verifying the signature of an HTTP request.
9+
*/
10+
public interface SignatureVerifier {
11+
12+
/**
13+
* Verifies the signature of the specified HTTP request.
14+
*
15+
* @param request The HTTP request data to verify.
16+
* @return A {@link CompletableFuture} containing the outcome of the verification process.
17+
*/
18+
CompletableFuture<VerificationResult> verifyAsync(Request request);
19+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package io.apimatic.coreinterfaces.security;
2+
import java.util.Arrays;
3+
import java.util.Collections;
4+
import java.util.List;
5+
6+
/**
7+
* Represents the result of an operation that can either succeed
8+
* or fail with an error message.
9+
*/
10+
public interface VerificationResult {
11+
12+
/**
13+
* Indicates whether the verification succeeded.
14+
*
15+
* @return true if successful; false otherwise.
16+
*/
17+
boolean isSuccess();
18+
19+
/**
20+
* Gets the collection of error messages, if any.
21+
* Always returns a read-only list (never null).
22+
*
23+
* @return unmodifiable list of errors, empty if success.
24+
*/
25+
List<String> getErrors();
26+
27+
/**
28+
* Creates a successful result.
29+
*
30+
* @return a success result
31+
*/
32+
static VerificationResult success() {
33+
return new VerificationResult() {
34+
@Override
35+
public boolean isSuccess() {
36+
return true;
37+
}
38+
39+
@Override
40+
public List<String> getErrors() {
41+
return Collections.emptyList();
42+
}
43+
};
44+
}
45+
46+
/**
47+
* Creates a failed result with the given error messages.
48+
*
49+
* @param errors list of error messages
50+
* @return a failure result
51+
*/
52+
static VerificationResult failure(String... errors) {
53+
return new VerificationResult() {
54+
@Override
55+
public boolean isSuccess() {
56+
return false;
57+
}
58+
59+
@Override
60+
public List<String> getErrors() {
61+
return Collections.unmodifiableList(errors != null
62+
? Arrays.asList(errors) : Collections.emptyList());
63+
}
64+
};
65+
}
66+
}

0 commit comments

Comments
 (0)