Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Velib Gateway Web Service

An IWS exposing the JCDecaux API to access the Velib Web Service.

Project Structure

This project consists of four parts :

  • An Intermediate Web Server (IWS) (contained in the Server directory) exposing a WS-SOAP API to access the Velib Web Service provided by JCDecaux.
  • A console application (contained in the ServerApp directory) launching the IWS.
  • A console client (contained in the ConsoleClient directory) connecting to the IWS to fetch information coming from the JCDecaux API
  • A GUI client (contained in the Client directory), being the GUI version of the console client.

Building the project

  • Include your API key in the project (see the next section for detailed procedure).
  • Run Visual Studio in Administrator Mode. Otherwise, you won't have access to the port where the service is hosted.
  • Open the VelibGateway.sln solution file contained in the Client directory.
  • Add the Newtonsoft.Json NuGet package to the Server project.
  • Set the Client project as StartUp project.
  • Run ServerApp\bin\Debug\ServerApp.exe in Administrator Mode. To exit the program, simply type exit and the server will close.
  • Run the solution.

Using your own API key

Become a JCDecaux developer

In order to use the JCDecaux API, you need to have an API key delivered after subscription on their website.

Include the key in the project

You then need to create an api_key.txt file in the Server directory containing only your key. The server will fetch the content of the file as a resource :

private static string API_KEY = Server.Properties.Resources.api_key;

Extensions

Available extensions

Development

  • GUI client
  • Asynchronous accesses to WS
  • Added cache to IWS

Deployment

  • Deployment on Docker

Monitoring

  • Second WS to monitor fetch and compute information from the WS

Extensions descriptions

  • Concerning the asynchronous calls

Instead of directly calling the synchronous methods we implemented, we call the corresponding asynchronous methods generated by Visual Studio. This allows to make asynchronous calls to the IWS in a simple manner. However, this implies some changes in the code.

Example of synchronous to asynchronous transformation for the getContracts() method.
// IVelibInfos.cs
[OperationContract]
List<string> GetContracts();

// VelibInfos.cs
public List<string> GetContracts()
{
    var contracts = GetArray("https://api.jcdecaux.com/vls/v1/contracts?apiKey=" + API_KEY)
        .Children()
        .Select(child => (string)child["name"])
        .ToList();
    contracts.Sort();
    return contracts;
}

// MainWindow.xaml.cs
listBoxContracts.ItemsSource = velibInfos.GetContracts();

becomes :

// IVelibInfos.cs
[OperationContract]
Task<List<string>> GetContracts();

// VelibInfos.cs
public async Task<List<string>> GetContracts()
{
    var contracts = (await GetArray("https://api.jcdecaux.com/vls/v1/contracts?apiKey=" + API_KEY))
        .Children()
        .Select(child => (string)child["name"])
        .ToList();
    contracts.Sort();
    return contracts;
}

// MainWindow.xaml.cs
listBoxContracts.ItemsSource = await velibInfos.GetContractsAsync();

The impact of asynchronous calls can be seen using the console client. Using synchnous calls, the client waits for the server's answer before allowing you to type another command. However, using asynchrounous calls, you can type another command before having an answer from the server. This results in a difference of output in the console.

Example :
  • Synchonous call
> get-station Nancy 00029
Nb of available bikes : 18
> █
  • Asynchonous call
> get-station-async Nancy 00029
> Nb of available bikes : 18
█
  • Concerning the caching extension :

In both clients, you can set the cache duration you want.

  • In the GUI client, a box lets you input the number of seconds
  • In the console client, you can use the print-cache-duration command to print the actual value, and set-cache-duration to set it.

For debugging purpose, the default value is set to 5 seconds.

At runtime, when a station is selected, a message is logged in the console to show the cache behaviour :

  • Station never queried, adding to cache. : This is the first time we query information about this station. A new Station object is added to the cache.
  • Outdated information, updating information. : Information about this station is already present in the cache, but it needs to be updated. A new Station object replacing the old one is added to the cache.
  • Getting value from cache. : Information about this station is already present in the cache and is considered as up-to-date. We directly get the value from the cache.

About

An IWS exposing the JCDecaux API to access the Velib web service.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages