Fetching Data
As you learned in the previous chapter, the Friedolyn
is the central class in the
Friedolyn project, and it provides easy access to the core functionality via high-level methods.
The Friedolyn
object you create will be your gateway to the Friedolin system, and it will remain open until you
explicitly close it.
Instantiating Friedolyn
First, you need to create a new instance of the
Friedolyn
class.
Since the constructor requires a Configuration
, you need to create
one first.
import page.codeberg.friedolyn.Friedolyn;
Configuration configuration =
new Configuration(
"es13nsa", // Friedolin username
"correct horse battery staple".toCharArray() // Friedolin password
);
Friedolyn friedolyn = new Friedolyn(configuration);
Logging in
It’s not necessary to log in manually, because the underlying
FriedolinClient
does that automatically when invoking any method
that requires a login.
Fetching personal data
try {
String clearname = friedolyn.fetchStudentClearname();
InternetAddress emailAddress = friedolyn.fetchEmailAddress();
} catch (NotFoundException e) {
// Handle the case if something went wrong
}
Fetching the grades table
try {
friedolyn.fetchGrades();
} catch (NotFoundException e) {
// Handle the case if something went wrong
}
Periodic grades fetching
It is possible to have Friedolyn check for newly released grades of the student at regular intervals, by default every 5 minutes.
Note
Make sure to instantiate Friedolyn properly before starting the periodic fetching.
try {
friedolyn.startPeriodicGradesFetch();
} catch (IllegalStateException e) {
// Handle the case if periodic fetching has already been started
}
// Don't want Friedolyn to make any more requests for a while?
// Just temporarily suspend the periodic fetching until you're ready to resume it.
friedolyn.pausePeriodicGradesFetch();
System.out.println("Taking a break...");
System.out.println("/* Do whatever you want to do in the meantime */");
System.out.println("Done with the break!");
// Continue where you left off fetching grades.
friedolyn.resumePeriodicGradesFetch();
// Sick of having Friedolyn do the same thing over and over again?
// Terminate the periodic fetching altogether, once and for all.
friedolyn.stopPeriodicGradesFetch();
You can change the interval from the default value to a custom one in the configuration. Make sure not to surpass the maximum interval of 7 days or undershoot the minimum interval of 5 minutes.
If you don’t want the periodic fetching to start immediately, specify a delay that should be waited before the first fetching task is executed:
try {
Duration delay = Duration.ofMinutes(10);
friedolyn.startPeriodicGradesFetch(delay);
} catch (IllegalStateException e) {
// Handle the case if periodic fetching has already been started
}
Friedolyn Javadocs
Learn everything about the Friedolyn class and its members.