3232public class Session {
3333
3434 private Infos infos ;
35- private boolean useCache = true ;
3635 private RequestManager requestManager ;
3736
3837 /**
@@ -68,6 +67,26 @@ public static Session login(String username, String password, String server, Str
6867 return login (username , password , server , schoolName , "" );
6968 }
7069
70+ /**
71+ * Logs in to the server.
72+ *
73+ * <p>Send an login request to the server and returns {@link Session} if the login was successful.
74+ * Throws {@link IOException} if an IO Exception occurs or {@link LoginException} (which inherits from IOException) if login fails</p>
75+ *
76+ * @param username the username used for the api
77+ * @param password the password used for the api
78+ * @param server the server used for the api
79+ * @param schoolName the school name used for the api
80+ * @param useCache sets if every request response should be saved in cache
81+ * @return a session
82+ * @throws IOException if an IO Exception occurs
83+ * @see Session#login(String, String, String, String, String)
84+ * @since 1.0
85+ */
86+ public static Session login (String username , String password , String server , String schoolName , boolean useCache ) throws IOException {
87+ return login (username , password , server , schoolName , "" , useCache );
88+ }
89+
7190 /**
7291 * Logs in to the server.
7392 *
@@ -84,12 +103,32 @@ public static Session login(String username, String password, String server, Str
84103 * @since 1.0
85104 */
86105 public static Session login (String username , String password , String server , String schoolName , String userAgent ) throws IOException {
106+ return login (username , password , server , schoolName , userAgent , true );
107+ }
108+
109+ /**
110+ * Logs in to the server.
111+ *
112+ * <p>Send an login request to the server and returns {@link Session} if the login was successful.
113+ * Throws {@link IOException} if an IO Exception occurs or {@link LoginException} (which inherits from IOException) if login fails</p>
114+ *
115+ * @param server the server from your school as URL
116+ * @param schoolName school name of the school you want to connect to
117+ * @param username the username used for the API
118+ * @param password the password used for the API
119+ * @param userAgent the user agent you want to send with
120+ * @param useCache sets if every request response should be saved in cache
121+ * @return a {@link Session} session
122+ * @throws IOException if an IO Exception occurs
123+ * @since 1.0
124+ */
125+ public static Session login (String username , String password , String server , String schoolName , String userAgent , boolean useCache ) throws IOException {
87126 if (!server .startsWith ("http://" ) && !server .startsWith ("https://" )) {
88127 server = "https://" + server ;
89128 }
90129 Infos infos = RequestManager .generateUserInfosAndLogin (username , password , server , schoolName , userAgent );
91130
92- RequestManager requestManager = new RequestManager (infos );
131+ RequestManager requestManager = new RequestManager (infos , useCache );
93132
94133 return new Session (infos , requestManager );
95134 }
@@ -116,13 +155,14 @@ public void logout() throws IOException {
116155 * @since 1.0
117156 */
118157 public void reconnect () throws IOException {
158+ boolean useCache = requestManager .isCacheUsed ();
119159 try {
120160 logout ();
121161 } catch (IOException ignore ) {
122162 }
123163
124164 infos = RequestManager .generateUserInfosAndLogin (infos .getUsername (), infos .getPassword (), infos .getServer (), infos .getSchoolName (), infos .getUserAgent ());
125- requestManager = new RequestManager (infos );
165+ requestManager = new RequestManager (infos , useCache );
126166 }
127167
128168 /**
@@ -147,11 +187,7 @@ private <T extends BaseResponse> T requestSender(UntisUtils.Method method, Respo
147187 * @since 1.1
148188 */
149189 private <T extends BaseResponse > T requestSender (UntisUtils .Method method , Map <String , ?> params , ResponseConsumer <? extends T > action ) throws IOException {
150- if (useCache ) {
151- return action .getResponse (requestManager .CachedPOST (method .getMethod (), params ));
152- } else {
153- return action .getResponse (requestManager .POST (method .getMethod (), params ));
154- }
190+ return action .getResponse (requestManager .CachedPOST (method .getMethod (), params ));
155191 }
156192
157193 /**
@@ -1148,24 +1184,4 @@ public Infos getInfos() {
11481184 return infos ;
11491185 }
11501186
1151- /**
1152- * Gets if every request response should be saved in cache
1153- *
1154- * @return gets if every request response should be saved in cache
1155- * @since 1.1
1156- */
1157- public boolean isCacheUsed () {
1158- return useCache ;
1159- }
1160-
1161- /**
1162- * Sets if every request response should be saved in cache what returns in better performance
1163- *
1164- * @param useCache sets if every request response should be saved in cache
1165- * @since 1.1
1166- */
1167- public void useCache (boolean useCache ) {
1168- this .useCache = useCache ;
1169- }
1170-
11711187}
0 commit comments