-
Notifications
You must be signed in to change notification settings - Fork 2
Integrate with other apps
There are some interfaces that need to be implemented in order to integrate Schedulizer with other external apps. The external app must have an authentication endpoint and a way to autocomplete the name of other users. Optionally it may have a way to post messages in groups (which allows the Remind Users
feature to work).
Follow these steps to integrate with your app:
(1) Add your app name to the ExtAppType enum at src/main/java/com/yammer/schedulizer/auth/ExtAppType.java
.
public enum ExtAppType {
yammer, facebook, myApp
}
(2) Create inside /src/main/java/com/yammer/schedulizer/auth
an Authenticator for your app. For example: MyAppAuthenticator.java
. It should extend ExtAppAuthenticator
and implement the method getTokenOwner
that receives an access token from your external app, makes a request to get the users information and returns an Employee
instance.
package com.yammer.schedulizer.auth;
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.api.client.Client;
import com.yammer.schedulizer.entities.Employee;
import javax.ws.rs.core.MediaType;
public class MyAppAuthenticator extends ExtAppAuthenticator {
private static final String MY_APP_CURRENT_USER_ENDPOINT = "https://my_app.com/me";
private static final String ACCESS_TOKEN_PARAM = "access_token";
public MyAppAuthenticator(Client client) {
super(client);
}
@Override
public Employee getTokenOwner(String accessToken) {
JsonNode response = client.resource(MY_APP_CURRENT_USER_ENDPOINT)
.queryParam(ACCESS_TOKEN_PARAM, accessToken)
.accept(MediaType.APPLICATION_JSON_TYPE)
.get(JsonNode.class);
String myAppId = response.get("id").asText();
String name = response.get("name").asText();
String imageUrlTemplate = response.get("image_url").asText();
Employee employee = new Employee(name, myAppId, ExtAppType.myApp);
employee.setImageUrlTemplate(imageUrlTemplate);
return employee;
}
}