Skip to content

Commit

Permalink
Offline token partner client support added (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
divyanshusinghh authored Jan 3, 2025
1 parent fa7c616 commit 3fdb77a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,40 @@ public class ExampleOfflineAccessMode {
}
```

#### How to get partnerClient for offline access_mode?

To obtain the `PartnerClient` for offline access mode in your Java extension, use the provided `ExtensionService` class.
This example demonstrates how to retrieve response time using the obtained `PartnerClient`

```java
@RestController
@RequestMapping("/api/v1")
public class ExampleOfflineAccessMode {

@Autowired
ExtensionService extensionService;

@GetMapping(value = "/response-time", produces = "application/json")
public WebhookPartnerModels.ResponseTimeTs getResponseTime() {
try {
String organizationId = "64b0e718f56860951c34d735";
PartnerClient partnerClient = extensionService.getPartnerClient("64b0e718f56860951c34d735");
WebhookPartnerModels.ResponseTimeTs responseTime = partnerClient.webhook.responseTimeSummary(
"66c5b90b2d58ee212f3891f8",
"2024-11-18T11:38:44+05:30",
"2024-11-18T14:38:44+05:30"
);

return responseTime;

} catch (Exception e) {
System.out.println(e.getMessage());
throw new RuntimeException(e);
}
}
}
```

#### How to call partner apis?

To call partner api you need to have instance of `PartnerClient`. Instance holds methods for SDK classes.
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/fynd/extension/service/ExtensionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.sdk.application.ApplicationClient;
import com.sdk.application.ApplicationConfig;
import com.sdk.common.model.AccessTokenDto;
import com.sdk.partner.PartnerClient;
import com.sdk.platform.PlatformClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -49,6 +50,30 @@ public PlatformClient getPlatformClient(String companyId) {
return client;
}

public PartnerClient getPartnerClient(String organizationId) {
log.debug("Fetching PartnerClient for organizationId : {}", organizationId);
PartnerClient client = null;
try {
if (!this.ext.isOnlineAccessMode()) {
String sid = Session.generateSessionId(false, new Option(organizationId, this.ext.getExtensionProperties()
.getCluster()));
Session session = sessionStorage.getSession(sid);
if (Objects.nonNull(session)) {
AccessTokenDto rawToken = new AccessTokenDto();
rawToken.setExpiresIn((session.getExpiresIn()));
rawToken.setAccessToken(session.getAccessToken());
rawToken.setRefreshToken(session.getRefreshToken());
client = this.ext.getPartnerClient(organizationId, session);
}
log.info("Partner Client for Organization Id : {} and Session Id :{}", organizationId, sid);
}
} catch (Exception e) {
log.error("Exception in getting Partner Client : ", e);
}

return client;
}


public ApplicationClient getApplicationClient(String applicationId, String applicationToken) {
log.debug("Fetching ApplicationClient for applicationId : {}", applicationId);
Expand Down

0 comments on commit 3fdb77a

Please sign in to comment.