Befehle des Menübands überspringen
Zum Hauptinhalt wechseln

​​

The L²P API Reference Client

 

About

This is the official L²P API Reference Client. The client is written in C# and can be used for multiple platform projects (e.g. Windows, Android, iOS, ASP.Net, Linux/Unix). The client contains mechanisms for obtaining and managing the tokens as well as calling the L²P API.

 

Step 1: Configuring the Client

The client contains the file L2PAPIClientPortable/ConfigSample.cs in which you have to add your client ID you got from ITC/CiL.

Rename file to Config.cs and save. The client is now working.

Optional: For now, the Application will store the tokens in static internal variables. By quitting the Application, the tokens are not available anymore. If you want to use a persistent storage (e.g. files or property dictionary of the smartphone), change the getters and setters in this file too. It will be the only file that needs to be changed to enable persistent device-oriented storage.

Step 2: Authorization process

To start the Authorization process, you get the URL for the user by:​

​​

​​            string url = await L2PAPIClientPortable.AuthenticationManager.StartAuthenticationProcessAsync(); // Start Authorization Process - open this url in browser!

Open the URL in a browser according to the platform. The user can now login and authorize your app. You can wait some seconds and check the status for the process by:


​​ ​​​​​​​​​​​​

                bool done = false;

                Thread.Sleep(5000); // you may use different methods for waiting like Task.Delay

                L2PAPIClientPortable.AuthenticationManager.CheckAuthenticationProgressAsync(); // Update State of client

                done = (L2PAPIClientPortable.AuthenticationManager.getState() == L2PAPIClientPortable.AuthenticationManager.AuthenticationState.ACTIVE);


You may want to iterate this step several times (depending on network and user speed, this may take way more time). The CheckAuthenticationProgressAsync() method will force the client to update the current state on authorization of the app. The state can be checked via the getState() every time during the application lifecycle and provides information whether the client can use API Calls.

 

Step 3: Call the API

If the app is authorized, you can simply use the calls from api.Calls namespace inside the project, like

​​​var courses = await L2PAPIClientPortable.api.Calls.L2PviewAllCourseInfoByCurrentSemester();// Get All Information about courses of the current semester

The tokens, http-methods and parameter-ordering will be done automatically in the background.

 

Remarks

After the user authorized the app, the AuthenticationManager will automatically refresh the accessToken when it gets invalidated by timeout in the OAuth. If also the refreshToken gets invalidated (e.g. user unauthorizes the app) the state of the client is reset and API calls throw well-defined Exceptions.

In the L2PAPITestApplication program you can find more examples how to use the client.​

Every mathod that uses network connections is provided asynchronously. All frameworks and NuGet-packages referenced are completely portable and free. The client itself is free to use and Open Source.

This client has been tested with Windows, UWP, Windows Phone, Android (Xamarin), iOS (Xamarin), Linux/Unix (Mono), OS X

The Reference client can be founf in the RWTH Gitlab​