Skip to content

Commit 653af60

Browse files
committed
feat: add webhooks and callbacks support
1 parent 6b543e6 commit 653af60

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

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

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: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 DefaultImpl.SUCCESS;
34+
}
35+
36+
/**
37+
* Creates a failed result with the given error messages.
38+
*
39+
* @param errors list of error messages
40+
* @return a failure result
41+
*/
42+
static VerificationResult failure(String... errors) {
43+
return new DefaultImpl(errors);
44+
}
45+
46+
/**
47+
* Default hidden implementation inside the interface.
48+
*/
49+
class DefaultImpl implements VerificationResult {
50+
private static final VerificationResult SUCCESS = new DefaultImpl();
51+
52+
private final List<String> errors;
53+
54+
private DefaultImpl(String... errors) {
55+
this.errors = Collections.unmodifiableList(errors != null ?
56+
Arrays.asList(errors) : Collections.emptyList());
57+
}
58+
59+
@Override
60+
public boolean isSuccess() {
61+
return errors.isEmpty();
62+
}
63+
64+
@Override
65+
public List<String> getErrors() {
66+
return errors;
67+
}
68+
69+
@Override
70+
public String toString() {
71+
return isSuccess()
72+
? "VerificationResult{success}"
73+
: "VerificationResult{errors=" + errors + "}";
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)