-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds Request and Response Hooks
- Loading branch information
Showing
12 changed files
with
381 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.easypost.hooks; | ||
|
||
import java.util.function.Function; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
public class EventHook { | ||
private List<Function<HashMap<String, Object>, Object>> eventHandlers = new ArrayList<>(); | ||
|
||
/** | ||
* Add a function to the list of event handlers. | ||
* @param handler The event handler function to be added. | ||
*/ | ||
public void addEventHandler(Function<HashMap<String, Object>, Object> handler) { | ||
eventHandlers.add(handler); | ||
} | ||
|
||
/** | ||
* Remove a function to the list of event handlers. | ||
* @param handler The event handler function to be removed. | ||
*/ | ||
public void removeEventHandler(Function<HashMap<String, Object>, Object> handler) { | ||
eventHandlers.remove(handler); | ||
} | ||
|
||
/** | ||
* Execute all the functions from the event handlers. | ||
* @param datas The datas from the hooks. | ||
*/ | ||
public void executeEventHandler(HashMap<String, Object> datas) { | ||
for (Function<HashMap<String, Object>, Object> eventHandler : eventHandlers) { | ||
Object result = eventHandler.apply(datas); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.easypost.hooks; | ||
|
||
public class RequestHook extends EventHook { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.easypost.hooks; | ||
|
||
public class ResponseHook extends EventHook { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Custom hook classes for the EasyPost API. | ||
* | ||
* @author EasyPost developers | ||
* @version 1.0 | ||
* @see <a href="https://www.easypost.com/docs">EasyPost API documentation</a> | ||
* @since 1.0 | ||
*/ | ||
package com.easypost.hooks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.