SDK tools

Various methods that are provided by our SDK that can be used as you see fit.

Debug Logging

When the debug logging feature is enabled, each step of the process in Harbor SDK is recorded in a log callback. This log callback provides a detailed record that can be utilized for analyzing and addressing any failures that may occur during the connection and drop-off/pick-up process. By reviewing the log, you can gain insights into the specific actions and events that took place, allowing you to troubleshoot and resolve any issues effectively.

After you initialize the SDK, set the Logging capabilities up using the log level you need:

To set the log level in the Harbor Android SDK, use the following code:

HarborLockersSDK.setLogLevel('debug'); // can be: debug, verbose, info, warning, error

Replace ‘debug’ with the desired log level (‘debug’, ‘verbose’, ‘info’, ‘warning’, ‘error’) based on your requirements.

Adding Event Emitter Listener

To listen for the HarborLogged event using an Event Emitter, utilize the code snippet below:

func harborDidLog(message: String, logType: HarborLogLevel, context: [String : Any]?) {
  print("Harbor log [\(logType.name())]: \(message)")
  if let context = context {
      print("Context: \(context)")
  }
}

This code sets up an event listener for HarborLogged events. When such an event occurs, it logs the result using console.log in JavaScript.

Remember to remove the debug level when you are no longer going to use it as it clutters up the log.

Reopen Locker Door

Another thing you might want to do is to reopen the lastly opened locker. This might be useful if your user forgot to add something inside, or if the door was accidentally closed before the user completed the drop off.

Call the sendReopenLocker function to reopen the same locker that was lastly opened in your session. If no door was opened during your session, the completion handler will return an error.

Check Locker Door

After a locker was opened, you can check the state of the door using the sendCheckLockerDoor function.

The completion handler will notify you if the door you just tried to open is open or close. If no door was opened during your session, the completion handler will return an error.

You can use this method for 2 things:

  1. To confirm the door was opened (as it might fail to pop open).

  2. To get notified when your user closed the locker door, and move the app to the next screen/state.

Disconnecting from a tower

You can only connect to one tower a time. So if you ever need to end your connection with a tower, you can call sendTerminateSession in your code and send a value of ‘0’ and then a string explaining the reason.

HarborLockersSDK.sendTerminateSession(0, 'Session terminated by user');

Refreshing the token

If at any point your token has expired you can use the following code to refresh it. The accounts_url can be found on the Access Token page

 curl -X 'POST' \
'{accounts_url}/realms/harbor/protocol/openid-connect/token' \
-H 'accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=refresh_token&client_id=your client id&client_secret={your client secret}&refresh_token={your very long token here}'