Inprove contruction system
This commit is contained in:
parent
dade689e22
commit
e15aed47c6
|
@ -10,36 +10,54 @@ import java.util.Map;
|
|||
|
||||
public class UntisClient {
|
||||
|
||||
//Fields
|
||||
JsonRpcHttpClient client;
|
||||
public AuthResponse auth;
|
||||
Map<String , String> header;
|
||||
|
||||
//Static Methods
|
||||
public static String getURLBySchoolname(String schoolname) throws APIRequestException {
|
||||
try {
|
||||
JsonRpcHttpClient client = new JsonRpcHttpClient(new URL("https://mobile.webuntis.com/ms/schoolquery2"));
|
||||
SchoolParams[] params = new SchoolParams[1];
|
||||
params[0] = new SchoolParams(schoolname);
|
||||
SchoolResponse res = client.invoke("searchSchool", params, SchoolResponse.class);
|
||||
|
||||
String url = "https://" + res.schools[0].server + "/WebUntis/jsonrpc.do";
|
||||
|
||||
return url;
|
||||
return "https://" + res.schools[0].server + "/WebUntis/jsonrpc.do?school=" + res.schools[0].loginName;
|
||||
} catch (Throwable e) {
|
||||
throw new APIRequestException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an UntisClient and starts a session.
|
||||
* Creates an UntisClient and starts a session
|
||||
* @param username The username of the user
|
||||
* @param password The password of the user
|
||||
* @param school The name of the school
|
||||
* @param appname The name of your app
|
||||
* @return An UntisClient object
|
||||
* @throws APIRequestException
|
||||
*/
|
||||
public UntisClient(String username, String password, String school, String appname) throws APIRequestException{
|
||||
public static UntisClient constructBySchool(String username, String password, String school, String appname) throws APIRequestException {
|
||||
return new UntisClient(username, password, getURLBySchoolname(school), appname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an UntisClient and starts a session
|
||||
* @param username The username of the user
|
||||
* @param password The password of the user
|
||||
* @param url The url of the school
|
||||
* @param appname The name of your app
|
||||
* @return An UntisClient object
|
||||
* @throws APIRequestException
|
||||
*/
|
||||
public static UntisClient constructByURL(String username, String password, String url, String appname) throws APIRequestException {
|
||||
return new UntisClient(username, password, url, appname);
|
||||
}
|
||||
|
||||
//Constructors
|
||||
UntisClient(String username, String password, String url, String appname) throws APIRequestException{
|
||||
try {
|
||||
client = new JsonRpcHttpClient(new URL(getURLBySchoolname(school) + "?school=" + school));
|
||||
client = new JsonRpcHttpClient(new URL(url));
|
||||
|
||||
auth = client.invoke("authenticate", new AuthParams(username, password, appname), AuthResponse.class);
|
||||
header = new HashMap<>();
|
||||
|
@ -51,17 +69,7 @@ public class UntisClient {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an UntisClient and starts a session.
|
||||
* @param username The username of the user
|
||||
* @param password The password of the user
|
||||
* @param school The name of the school
|
||||
* @throws APIRequestException
|
||||
*/
|
||||
public UntisClient(String username, String password, String school) throws APIRequestException{
|
||||
this(username, password, school, "JavaUntis");
|
||||
}
|
||||
|
||||
//Methods
|
||||
/**
|
||||
* End the session.
|
||||
* Use to logout from the server. Only do this, if you don't longer need this Object!
|
||||
|
|
Loading…
Reference in a new issue